Spaces:
Runtime error
Runtime error
this
Browse files
app.py
CHANGED
|
@@ -1,149 +1,143 @@
|
|
| 1 |
import google.generativeai as palm
|
| 2 |
import gradio as gr
|
| 3 |
-
import os
|
| 4 |
import json
|
| 5 |
|
| 6 |
# Set your API key
|
| 7 |
-
palm.configure(api_key=os.environ[
|
| 8 |
|
| 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(messages=data)
|
| 18 |
-
intent = palm.chat(
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
|
|
|
| 49 |
|
| 50 |
-
|
| 51 |
-
|
| 52 |
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
|
|
|
| 86 |
print(intent)
|
| 87 |
# respo = {
|
| 88 |
# "message": intent.last,
|
| 89 |
# "action": "nothing",
|
| 90 |
# "function": "nothing"
|
| 91 |
# }
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
|
|
|
|
|
|
| 135 |
else:
|
| 136 |
-
respo = {
|
| 137 |
-
"message": response.last,
|
| 138 |
-
"action": "nothing",
|
| 139 |
-
"function": "nothing"
|
| 140 |
-
}
|
| 141 |
return json.dumps(respo)
|
| 142 |
|
| 143 |
-
gradio_interface = gr.Interface(
|
| 144 |
-
fn = responsenew,
|
| 145 |
-
inputs = "text",
|
| 146 |
-
outputs = "text"
|
| 147 |
-
)
|
| 148 |
-
gradio_interface.launch()
|
| 149 |
|
|
|
|
|
|
|
|
|
| 1 |
import google.generativeai as palm
|
| 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"])
|
| 8 |
|
| 9 |
# Select the PaLM 2 model
|
| 10 |
# model = 'models/text-bison-001'
|
| 11 |
|
| 12 |
|
|
|
|
|
|
|
| 13 |
def responsenew(data):
|
| 14 |
print(data)
|
| 15 |
response = palm.chat(messages=data)
|
| 16 |
+
intent = palm.chat(
|
| 17 |
+
messages=f"""Act as a friendly personal assistant who's name is Cosmo. ".
|
| 18 |
+
You help users manage their daily tasks by providing them with a variety of features.
|
| 19 |
+
Below are the list of features you have: \n
|
| 20 |
+
- You can create goals\n
|
| 21 |
+
- You can share goals with friends\n
|
| 22 |
+
- You can create reminders\n
|
| 23 |
+
- You can create routines\n
|
| 24 |
+
- You can share reminders with users friends\n
|
| 25 |
+
- You can share routines with users friends\n
|
| 26 |
+
- You can create todo lists\n
|
| 27 |
+
- You can share todo lists with users friends\n
|
| 28 |
+
- You can create groups\n
|
| 29 |
+
- You can share groups with users friends\n
|
| 30 |
+
- You can create communities\n
|
| 31 |
+
- You can create notes for user\n
|
| 32 |
+
- You can share notes with users friends\n
|
| 33 |
+
- You can publish posts on timeline\n
|
| 34 |
+
- You can invite friends to this(CosmoAI) app\n
|
| 35 |
+
- You can help users purchase coins\n
|
| 36 |
+
- You can view your friends\n
|
| 37 |
+
- You can view your groups\n
|
| 38 |
+
- You can view your communities\n
|
| 39 |
+
- You can view your shared reminders\n
|
| 40 |
+
- You can view your shared routines\n
|
| 41 |
+
- You can view your todo lists\n
|
| 42 |
+
- You can view your shared todo lists\n
|
| 43 |
+
- You can view your shared notes\n
|
| 44 |
+
- You can start a timer or a stopwatch\n
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
Identify the user's intent from the given text data.\n
|
| 48 |
|
| 49 |
+
Args:\n
|
| 50 |
+
text_data: {data}.\n\n
|
| 51 |
|
| 52 |
+
Return the intent as one-word string representing the user's intent, one of:
|
| 53 |
+
* if intent = purchasing coins return = "purchase_coins"
|
| 54 |
+
* if intent = viewing friends return = "view_friends"
|
| 55 |
+
* if intent = viewing groups joined return = "view_groups"
|
| 56 |
+
* if intent = viewing communities joined return = "view_communities"
|
| 57 |
+
* if intent = viewing shared reminders return = "shared_reminders"
|
| 58 |
+
* if intent = viewing user's routines return = "my_routines"
|
| 59 |
+
* if intent = viewing all the groups existing on CosmoAI return = "view_all_groups"
|
| 60 |
+
* if intent = viewing all the communities existing on CosmoAI return = "view_all_communities"
|
| 61 |
+
* if intent = viewing user's notes return = "view_notes"
|
| 62 |
+
* if intent = viewing user's posts return = "view_posts"
|
| 63 |
+
* if intent = viewing user's shared notes return = "view_shared_notes"
|
| 64 |
+
* if intent = viewing user's todo lists return = "view_todo_lists"
|
| 65 |
+
* if intent = viewing user's shared todo lists return = "view_shared_todo_lists"
|
| 66 |
+
* if intent = viewing user's shared routines return = "view_shared_routines"
|
| 67 |
+
* if intent = creating a goal return = "create_goal"
|
| 68 |
+
* if intent = creating a reminder return = "create_reminder"
|
| 69 |
+
* if intent = creating a routine return = "create_routine"
|
| 70 |
+
* if intent = creating a group return = "create_group"
|
| 71 |
+
* if intent = creating a community return = "create_community"
|
| 72 |
+
* if intent = creating a note return = "create_note"
|
| 73 |
+
* if intent = creating a post return = "create_post"
|
| 74 |
+
* if intent = creating a todo list return = "create_todo_list"
|
| 75 |
+
* if intent = sharing a reminder return = "share_reminder"
|
| 76 |
+
* if intent = sharing a routine return = "share_routine"
|
| 77 |
+
* if intent = sharing a group return = "share_group"
|
| 78 |
+
* if intent = sharing a todo list return = "share_todo_list"
|
| 79 |
+
* if intent = sharing a note return = "share_note"
|
| 80 |
+
* if intent = knowing your name or who you are or what is your name return = "cosmo_name"
|
| 81 |
+
|
| 82 |
+
|
| 83 |
+
|
| 84 |
+
"""
|
| 85 |
+
)
|
| 86 |
print(intent)
|
| 87 |
# respo = {
|
| 88 |
# "message": intent.last,
|
| 89 |
# "action": "nothing",
|
| 90 |
# "function": "nothing"
|
| 91 |
# }
|
| 92 |
+
if intent.last is not None:
|
| 93 |
+
if "purchase_coins" in intent.last:
|
| 94 |
+
respo = {
|
| 95 |
+
"message": "Click the button below to view Premium Services and Coin Recharge options: ",
|
| 96 |
+
"action": "payment",
|
| 97 |
+
"function": "nothing",
|
| 98 |
+
}
|
| 99 |
+
elif "view_friends" in intent.last:
|
| 100 |
+
respo = {
|
| 101 |
+
"message": "Here's the list of your friends: ",
|
| 102 |
+
"action": "show_friends",
|
| 103 |
+
"function": "nothing",
|
| 104 |
+
}
|
| 105 |
+
elif "view_groups" in intent.last:
|
| 106 |
+
respo = {
|
| 107 |
+
"message": "You are member of following groups: ",
|
| 108 |
+
"action": "show_mygroups",
|
| 109 |
+
"function": "nothing",
|
| 110 |
+
}
|
| 111 |
+
elif "view_communities" in intent.last:
|
| 112 |
+
respo = {
|
| 113 |
+
"message": "You are part of following communities🫶: ",
|
| 114 |
+
"action": "show_mycommunities",
|
| 115 |
+
"function": "nothing",
|
| 116 |
+
}
|
| 117 |
+
elif "shared_reminders" in intent.last:
|
| 118 |
+
respo = {
|
| 119 |
+
"message": "Here's the list of your shared reminders: ",
|
| 120 |
+
"action": "shared_reminders",
|
| 121 |
+
"function": "nothing",
|
| 122 |
+
}
|
| 123 |
+
elif "my_routines" in intent.last:
|
| 124 |
+
respo = {
|
| 125 |
+
"message": "Here's the list of your routines: ",
|
| 126 |
+
"action": "myroutines",
|
| 127 |
+
"function": "nothing",
|
| 128 |
+
}
|
| 129 |
+
elif "cosmo_name" in intent.last:
|
| 130 |
+
respo = {
|
| 131 |
+
"message": "My name is Cosmo. I am your friendly personal assistant.",
|
| 132 |
+
"action": "nothing",
|
| 133 |
+
"function": "nothing",
|
| 134 |
+
}
|
| 135 |
+
else:
|
| 136 |
+
respo = {"message": response.last, "action": "nothing", "function": "nothing"}
|
| 137 |
else:
|
| 138 |
+
respo = {"message": "Unable to understand.", "action": "nothing", "function": "nothing"}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 139 |
return json.dumps(respo)
|
| 140 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 141 |
|
| 142 |
+
gradio_interface = gr.Interface(fn=responsenew, inputs="text", outputs="text")
|
| 143 |
+
gradio_interface.launch()
|