Chat / app.py
CosmoAI's picture
Update app.py
b020f8f verified
raw
history blame
6.83 kB
# elif response[1] == "create_reminder":
# # if values[4] == 'notime':
# # return JsonResponse({
# # 'messages': 'At what time do you want me to remind you?',
# # })
# # else:
# return JsonResponse({
# 'messages': response[0],
# 'action': response[1],
# 'function': {
# 'id': idval,
# 'sound': 'General',
# 'subTitle': 'Task',
# 'type': 'Note',
# 'title': values[0],
# 'description': '',
# 'time': values[1].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': 'Once',
# 'reminders': [{
# 'time': values[1].upper(),
# 'enable': False,
# 'repeat': 'Once',
# 'title': values[0],
# 'id': idval,
# 'note': '',
# 'dates': [],
# }],
# }
# })
# elif response[1] == 'create_todo':
# return JsonResponse({
# 'messages': response[0],
# 'action': response[1],
# 'function': {
# 'name': 'defaulttodo',
# 'id': idval,
# 'subTasks': [{
# 'task':values[0].replace("create a todo", ""),
# 'done': False
# }],
# 'shared': [],
# 'sharedByMe': [],
# },
# })
# elif response[1] == 'create_note':
# return JsonResponse({
# 'messages': response[0],
# 'action': response[1],
# 'function': {
# 'title': 'defaultnote',
# 'id': idval,
# 'type': 'Note',
# 'description': values[0],
# 'time': datetime.now().strftime("%d/%m/%Y"),
# 'mainTime': datetime.now().strftime("%I:%M %p"),
# 'complete': False,
# 'shared': [],
# 'sharedByMe': [],
# }
# })
import gradio as gr
import requests
import time
import os
import json
import google.generativeai as genai
import random
genai.configure(
api_key=os.environ['API_KEY'])
model = genai.GenerativeModel(
model_name='gemini-pro')
def responsenew(data):
query = data
respo = model.generate_content(
query,
generation_config={
'temperature': 0,
'max_output_tokens': 100
}
)
idval = random.randint(1, 1000000000)
print(f"\n\n{data}")
newdata = data.replace("'", '"')
items = json.loads(newdata)
query = items['text']
query = query.lower()
# try:
# items = json.loads(newdata)
# query = items['text']
# query = query.lower()
# print(query)
# except json.JSONDecodeError as e:
# print("Invalid JSON:", e)
response = model.generate_content(query)
print(f"\n{response.text}")
if query is not None:
if "remind me" in query:
values = getValues(query)
if values[0] is not None:
msg = values[0]
else:
msg = "Reminder Alert"
if values[1] is not None:
time = values[1]
else:
time = "5:00 PM"
# time = 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 = {
'message': f"Message: {msg} \nTime: {time} \nDay: {day} \nCreated 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': [],
}],
}
}
return json.dumps(respo)
gradio_interface = gr.Interface(
fn = responsenew,
inputs = "text",
outputs = "text"
)
gradio_interface.launch()
# remind_val = ["create a reminder", "create reminder", "remind me"]
# if remind_val in data:
# return "Reminder created!"
# else:
# return bardChat(data)
# with gr.Blocks() as demo:
# chatbot = gr.Chatbot()
# msg = gr.Textbox()
# clear = gr.ClearButton([msg, chatbot])
# def respond(message, chat_history):
# bot_message = responsenew(message)
# chat_history.append((message, bot_message))
# time.sleep(2)
# return "", chat_history
# msg.submit(respond, [msg, chatbot], [msg, chatbot])
# if __name__ == "__main__":
# demo.launch()