GoalsAI / app.py
CosmoAI's picture
Update app.py
47c93b4
raw
history blame
2.81 kB
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'
def responsenew(data):
print(data)
response = palm.chat(messages=data)
intent = palm.chat(messages=f"""Identify the user's intent from the given text_data, which can be one of the following:s i.e:\n
1. purchasing coins\n
2. viewing friends list\n
3. viewing groups been joined by the user\n
4. viewing pages been joined by the user\n
5. user is saying to view the reminders been shared to the user or by the user\n
6. viewing list of my routines or my reminders\n
data = {data}\n\n
After you are done find out the intent, answer in one word only the intent. Use the following word for your answer, as given below in sequence to the intent:\n
1. recoin\n
2. view_friends\n
3. view_groups\n
4. view_pages\n
5. sharedrem\n
6. myroutines\n\n
Your answer must be of one word only out of these above given words.""")
print(intent)
# respo = {
# "message": response.last,
# "action": "nothing",
# "function": "nothing"
# }
if "recoin" 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_pages" in intent.last:
respo = {
"message": "You are part of following communities🫶: ",
"action": "show_mycommunities",
"function": "nothing"
}
elif "sharedrem" in intent.last:
respo = {
"message": "Here's the list of your shared reminders: ",
"action": "shared_reminders",
"function": "nothing"
}
elif "myroutines" in intent.last:
respo = {
"message": "Here's the list of your routines: ",
"action": "myroutines",
"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()