Spaces:
Running
Running
File size: 12,338 Bytes
e460bb5 c1548d4 b396381 c1548d4 a544103 8494dad 71ad11e e460bb5 b396381 71ad11e e460bb5 a91e5a1 71ad11e 12c38ef 21d05ce 2c30c16 12c38ef c659812 83e0b34 9690650 918129d 53bdc6c 9bce928 234bcdb 9bce928 234bcdb e719e47 53bdc6c afbc0cf f07ac8e a544103 c0c96d3 a544103 de19598 a544103 c0c96d3 a544103 de19598 a544103 c0c96d3 c073f0e afbc0cf c073f0e afbc0cf c073f0e afbc0cf c073f0e afbc0cf c073f0e afbc0cf c073f0e 609b253 afbc0cf 5e6d946 a25a912 5e6d946 afbc0cf 8373fe1 9598c37 8373fe1 66b8789 c073f0e a544103 c073f0e c1548d4 afbc0cf 4238098 b396381 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 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 87 88 89 90 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 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 |
import google.generativeai as palm
import gradio as gr
import os
import json
from getvalues import getValues
from datetime import datetime
import uuid
import re
# 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):
idval = str(uuid.uuid4())
print(f"\n\n{data}")
newdata = data.replace("'", '"')
try:
items = json.loads(newdata)
text = items['text']
print(text)
except json.JSONDecodeError as e:
print("Invalid JSON:", e)
response = palm.chat( messages=data)
print(f"\n{response.last}")
if data is not None:
if re.search(r"(Remind me|Remind me to)", data):
values = getValues(data)
if values[0] is not None:
msg = values[0]
else:
msg = "Reminder Alert"
if values[1] is not None:
time = values[1]
else:
time1 = datetime.now()
time2 = time1 + timedelta(hours=1)
time = time2.strftime("%d-%m-%Y %H:%M:%S.%f")
if values[2] is not None:
day = values[2]
else:
day = "today"
if values[3] is not None:
date = values[3]
else:
date = datetime.today()
if values[4] is not None:
reps = values[4]
else:
reps = "Once"
respo = {
'messages': f"Your reminder for {msg} on {time} for {day} has been created successfully.",
'action': "create_reminder",
'function': {
'id': idval,
'sound': 'General',
'subTitle': 'Task',
'type': 'Note',
'title': msg,
'description': '',
'time': time.upper(),
'timestamp' : datetime.now().strftime("%d-%m-%Y %H:%M:%S.%f"),
'enable': False,
'report': [],
'icon': 'https://firebasestorage.googleapis.com/v0/b/cosmo-f5007.appspot.com/o/categories%2FIcons%2Ftaskicon.svg?alt=media&token=56f3fc55-8eda-4463-bceb-7bf3198dff3c',
'color': 'FFD700',
'sharedToMe': [],
'sharedByMe': [],
'repeat': reps,
'reminders': [{
'time': time.upper(),
'enable': False,
'repeat': reps,
'title': msg,
'id': idval,
'note': '',
'dates': [],
}],
}
}
elif re.search(r"(Add todo|Add to do)", data):
respo = {
'messages': "Todo added!",
'action': "create_todo",
'function': {
'name': 'defaulttodo',
'id': idval,
'subTasks': [{
'task':data.replace("add todo", "").replace("add to do",""),
'done': False
}],
'shared': [],
'sharedByMe': [],
},
}
elif "Note down" in data:
respo = {
'messages': "Got it!",
'action': "create_note",
'function': {
'title': 'defaultnote',
'id': idval,
'type': 'Note',
'description': data.replace("note down",""),
'time': datetime.now().strftime("%d/%m/%Y"),
'mainTime': datetime.now().strftime("%I:%M %p"),
'complete': False,
'shared': [],
'sharedByMe': [],
}
}
elif "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 "what is your name" or "what's your name" or "who are you" in data:
# 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": "Whoops, seems like we're a bit overloaded! Don't worry, your request is in the queue and we'll get back to you as soon as possible.",
"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()
|