Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,7 +2,6 @@ import google.generativeai as palm
|
|
| 2 |
import gradio as gr
|
| 3 |
import os
|
| 4 |
import json
|
| 5 |
-
from transformers import pipeline
|
| 6 |
|
| 7 |
# Set your API key
|
| 8 |
palm.configure(api_key=os.environ['PALM_KEY'])
|
|
@@ -10,13 +9,13 @@ palm.configure(api_key=os.environ['PALM_KEY'])
|
|
| 10 |
# Select the PaLM 2 model
|
| 11 |
# model = 'models/text-bison-001'
|
| 12 |
|
| 13 |
-
# candlab= ["recharge coins or get subscription", "show list of my friends"]
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
def responsenew(data):
|
| 18 |
print(data)
|
| 19 |
-
response = palm.chat(
|
|
|
|
| 20 |
1. purchasing coins\n
|
| 21 |
2. viewing friends list\n
|
| 22 |
3. viewing groups been joined by the user\n
|
|
@@ -32,30 +31,48 @@ def responsenew(data):
|
|
| 32 |
5. sharedrem\n\n
|
| 33 |
Your answer must be of one word only out of these above given 5 words.""")
|
| 34 |
|
| 35 |
-
respo = {
|
| 36 |
-
"message": response.last,
|
| 37 |
-
"action": "nothing",
|
| 38 |
-
"function": "nothing"
|
| 39 |
-
}
|
| 40 |
-
# user_intent = pipeline("zero-shot-classification", model="facebook/bart-large-mnli")
|
| 41 |
-
# if "payment" in response.last:
|
| 42 |
-
# respo = {
|
| 43 |
-
# "message": "Click the button below to view Premium Services and Coin Recharge options: ",
|
| 44 |
-
# "action": "payment",
|
| 45 |
-
# "function": "nothing"
|
| 46 |
-
# }
|
| 47 |
-
# elif "friends" in response.last:
|
| 48 |
-
# respo = {
|
| 49 |
-
# "message": "Slide left or right profiles or tap on 'My Friends' to view list of your friends: ",
|
| 50 |
-
# "action": "show_friends",
|
| 51 |
-
# "function": "nothing"
|
| 52 |
-
# }
|
| 53 |
-
# else:
|
| 54 |
-
# respo = {
|
| 55 |
# "message": response.last,
|
| 56 |
# "action": "nothing",
|
| 57 |
# "function": "nothing"
|
| 58 |
# }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
return json.dumps(respo)
|
| 60 |
|
| 61 |
gradio_interface = gr.Interface(
|
|
|
|
| 2 |
import gradio as gr
|
| 3 |
import os
|
| 4 |
import json
|
|
|
|
| 5 |
|
| 6 |
# Set your API key
|
| 7 |
palm.configure(api_key=os.environ['PALM_KEY'])
|
|
|
|
| 9 |
# Select the PaLM 2 model
|
| 10 |
# model = 'models/text-bison-001'
|
| 11 |
|
|
|
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
def responsenew(data):
|
| 16 |
print(data)
|
| 17 |
+
response = palm.chat(message=data)
|
| 18 |
+
intent = palm.chat(messages=f"""From the text given as data below by the user, find out what intention or category does the data fall under out of given 5 intents i.e:\n
|
| 19 |
1. purchasing coins\n
|
| 20 |
2. viewing friends list\n
|
| 21 |
3. viewing groups been joined by the user\n
|
|
|
|
| 31 |
5. sharedrem\n\n
|
| 32 |
Your answer must be of one word only out of these above given 5 words.""")
|
| 33 |
|
| 34 |
+
# respo = {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
# "message": response.last,
|
| 36 |
# "action": "nothing",
|
| 37 |
# "function": "nothing"
|
| 38 |
# }
|
| 39 |
+
|
| 40 |
+
if "recoin" in intent.last:
|
| 41 |
+
respo = {
|
| 42 |
+
"message": "Click the button below to view Premium Services and Coin Recharge options: ",
|
| 43 |
+
"action": "payment",
|
| 44 |
+
"function": "nothing"
|
| 45 |
+
}
|
| 46 |
+
elif "view_friends" in intent.last:
|
| 47 |
+
respo = {
|
| 48 |
+
"message": "Here's the list of your friends: ",
|
| 49 |
+
"action": "show_friends",
|
| 50 |
+
"function": "nothing"
|
| 51 |
+
}
|
| 52 |
+
elif "view_groups" in intent.last:
|
| 53 |
+
respo = {
|
| 54 |
+
"message": "You are member of following groups: ",
|
| 55 |
+
"action": "show_mygroups",
|
| 56 |
+
"function": "nothing"
|
| 57 |
+
}
|
| 58 |
+
elif "view_pages" in intent.last:
|
| 59 |
+
respo = {
|
| 60 |
+
"message": "You are part of following communities🫶: ",
|
| 61 |
+
"action": "show_mycommunities",
|
| 62 |
+
"function": "nothing"
|
| 63 |
+
}
|
| 64 |
+
elif "sharedrem" in intent.last:
|
| 65 |
+
respo = {
|
| 66 |
+
"message": "Here's the list of your shared reminders: ",
|
| 67 |
+
"action": "shared_reminders",
|
| 68 |
+
"function": "nothing"
|
| 69 |
+
}
|
| 70 |
+
else:
|
| 71 |
+
respo = {
|
| 72 |
+
"message": response.last,
|
| 73 |
+
"action": "nothing",
|
| 74 |
+
"function": "nothing"
|
| 75 |
+
}
|
| 76 |
return json.dumps(respo)
|
| 77 |
|
| 78 |
gradio_interface = gr.Interface(
|