Spaces:
Running
Running
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"""Identifies the user's intent from the given text data. | |
Args: | |
text_data: {data}.\n\n | |
Returns: | |
A one-word string representing the user's intent, one of: | |
* purchase_coins | |
* view_friends | |
* view_groups | |
* view_communities | |
* shared_reminders | |
* my_routines | |
""") | |
print(intent) | |
respo = { | |
"message": intent.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() | |