import google.generativeai as palm import gradio as gr import os import json # Set your API key palm.configure(api_key=os.environ["PALM_KEY"]) # Select the PaLM 2 model # model = 'models/text-bison-001' # contx = """Act as a friendly personal assistant. # You help users manage their daily tasks by providing them with a variety of features. # Below are the list of features you have: \n # - You can create goals\n # - You can share goals with friends\n # - You can create reminders\n # - You can create routines\n # - You can share reminders with users friends\n # - You can share routines with users friends\n # - You can create todo lists\n # - You can share todo lists with users friends\n # - You can create groups\n # - You can share groups with users friends\n # - You can create communities\n # - You can create notes for user\n # - You can share notes with users friends\n # - You can publish posts on timeline\n # - You can invite friends to this(CosmoAI) app\n # - You can help users purchase coins\n # - You can view your friends\n # - You can view your groups\n # - You can view your communities\n # - You can view your shared reminders\n # - You can view your shared routines\n # - You can view your todo lists\n # - You can view your shared todo lists\n # - You can view your shared notes\n # - You can start a timer or a stopwatch\n\n""" def responsenew(data): print(data) data = data.lower() response = palm.chat( messages=data) print(response) if data is not None: # if "remind me" or "remind me to" in data: if "add coins" in data: respo = { "message": "Click the button below to view Premium Services and Coin Recharge options: ", "action": "payment", "function": "nothing", } elif "show my friends" in data: respo = { "message": "Here's the list of your friends: ", "action": "show_friends", "function": "nothing", } elif "show my groups" in data: respo = { "message": "You are member of following groups: ", "action": "show_mygroups", "function": "nothing", } elif "show my communities" in data: respo = { "message": "You are part of following communities🫶: ", "action": "show_mycommunities", "function": "nothing", } elif " show shared reminders" in data: respo = { "message": "Here's the list of your shared reminders: ", "action": "shared_reminders", "function": "nothing", } elif "show my routines" in data: respo = { "message": "Here's the list of your routines: ", "action": "myroutines", "function": "nothing", } # elif "cosmo_name" in intent.last: # respo = { # "message": "My name is Cosmo. I am your friendly personal assistant.", # "action": "nothing", # "function": "nothing", # } elif "notify" in data: respo = { "message": "Select your friends to notify", "action": "send_notify", "function": "nothing", } elif "show actions" in data: respo = { "message": "Here is list of actions you can use:", "action": "show_actions", "function": "nothing", } else: respo = { "message": response.last, "action": "nothing", "function": "nothing", } else: respo = { "message": "I am currently experiencing server overload, sorry for inconvenience. Please try again with your query.", "action": "nothing", "function": "nothing", } return json.dumps(respo) # intent = palm.chat( # messages=f""" # Identify the user's intent from text_data below:\n # Arguments: text_data = {data}\n\n # Return the intent as one-word string representing the user's intent, as mentioned below: # * if intent = viewing user's routine return = "my_routines" # * if intent = viewing user's notes return = "view_notes" # * if intent = viewing user's posts return = "view_posts" # * if intent = viewing user's shared notes return = "view_shared_notes" # * if intent = viewing user's todo lists return = "view_todo_lists" # * if intent = viewing user's shared todo lists return = "view_shared_todo_lists" # * if intent = viewing user's shared routines return = "view_shared_routines" # * if intent = creating a goal return = "create_goal" # * if intent = creating a reminder return = "create_reminder" # * if intent = creating a routine return = "create_routine" # * if intent = creating a group return = "create_group" # * if intent = creating a community return = "create_community" # * if intent = creating a note return = "create_note" # * if intent = creating a post return = "create_post" # * if intent = creating a todo list return = "create_todo_list" # * if intent = sharing a reminder return = "share_reminder" # * if intent = sharing a routine return = "share_routine" # * if intent = sharing a group return = "share_group" # * if intent = sharing a todo list return = "share_todo_list" # * if intent = sharing a note return = "share_note" # * if intent = notify then return = "send_notify" # * if intent = show actions then return = "show_actions" # """, # ) # respo = {"message": intent.last, "action": "nothing", "function": "nothing"} # if intent.last is not None: # if "purchase_coins" in intent.last: # respo = { # "message": "Click the button below to view Premium Services and Coin Recharge options: ", # "action": "payment", # "function": "nothing", # } # elif "view_friends" in intent.last: # respo = { # "message": "Here's the list of your friends: ", # "action": "show_friends", # "function": "nothing", # } # elif "view_groups" in intent.last: # respo = { # "message": "You are member of following groups: ", # "action": "show_mygroups", # "function": "nothing", # } # elif "view_communities" in intent.last: # respo = { # "message": "You are part of following communities🫶: ", # "action": "show_mycommunities", # "function": "nothing", # } # elif "shared_reminders" in intent.last: # respo = { # "message": "Here's the list of your shared reminders: ", # "action": "shared_reminders", # "function": "nothing", # } # elif "my_routines" in intent.last: # respo = { # "message": "Here's the list of your routines: ", # "action": "myroutines", # "function": "nothing", # } # # elif "cosmo_name" in intent.last: # # respo = { # # "message": "My name is Cosmo. I am your friendly personal assistant.", # # "action": "nothing", # # "function": "nothing", # # } # elif "send_notify" in intent.last: # respo = { # "message": "Select your friends to notify", # "action": "send_notify", # "function": "nothing", # } # elif "show_actions" in intent.last: # respo = { # "message": "Here is list of actions you can use:", # "action": "show_actions", # "function": "nothing", # } # else: # respo = { # "message": response.last, # "action": "nothing", # "function": "nothing", # } # else: # respo = { # "message": response.last, # "action": "nothing", # "function": "nothing", # } # return json.dumps(respo) gradio_interface = gr.Interface(fn=responsenew, inputs="text", outputs="text") gradio_interface.launch()