Update app.py
Browse files
app.py
CHANGED
|
@@ -1,70 +1,40 @@
|
|
| 1 |
-
import
|
| 2 |
-
import
|
| 3 |
-
from
|
| 4 |
-
from googleapiclient.discovery import build
|
| 5 |
|
| 6 |
-
#
|
| 7 |
-
|
|
|
|
| 8 |
|
| 9 |
-
def
|
| 10 |
-
|
| 11 |
-
creds = Credentials.from_authorized_user_file('token.json', SCOPES)
|
| 12 |
-
if not creds or not creds.valid:
|
| 13 |
-
st.error("Authentication required. Please set up your Google Calendar credentials.")
|
| 14 |
-
return None
|
| 15 |
-
return build('calendar', 'v3', credentials=creds)
|
| 16 |
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
event_result = service.events().insert(calendarId='primary', body=event).execute()
|
| 26 |
-
return event_result
|
| 27 |
-
except Exception as e:
|
| 28 |
-
st.error(f"Failed to add event: {e}")
|
| 29 |
-
return None
|
| 30 |
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
date_input = ' at '.join(words[1:]).strip() # The time portion, including relative or absolute date
|
| 42 |
-
|
| 43 |
-
# Parse the date/time using dateparser
|
| 44 |
-
parsed_date = dateparser.parse(date_input, settings={'PREFER_DATES_FROM': 'future'})
|
| 45 |
-
|
| 46 |
-
# If the date is parsed as the next day (incorrect), we can force it to use the exact date
|
| 47 |
-
if not parsed_date:
|
| 48 |
-
st.error(f"Could not parse the date and time: {date_input}. Please try again.")
|
| 49 |
-
return
|
| 50 |
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
# Show the parsed event details
|
| 58 |
-
st.write(f"Event Title: {title}")
|
| 59 |
-
st.write(f"Scheduled Time: {parsed_date}")
|
| 60 |
-
|
| 61 |
-
# Add event to Google Calendar (this would be the integration part)
|
| 62 |
-
st.success(f"Event '{title}' scheduled for {parsed_date}!")
|
| 63 |
|
| 64 |
-
#
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
user_input = st.text_input("What would you like to schedule?", "")
|
| 69 |
-
if user_input:
|
| 70 |
-
parse_input_and_schedule(user_input)
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from chatbot_schedule import schedule_bot_response
|
| 3 |
+
from chatbot_wellness import wellness_bot_response
|
|
|
|
| 4 |
|
| 5 |
+
# Define interfaces for each chatbot
|
| 6 |
+
def task_schedule_interface(user_input):
|
| 7 |
+
return schedule_bot_response(user_input)
|
| 8 |
|
| 9 |
+
def wellness_chatbot_interface(user_id, user_input):
|
| 10 |
+
return wellness_bot_response(user_id, user_input)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
+
# Create Gradio interfaces
|
| 13 |
+
task_bot = gr.Interface(
|
| 14 |
+
fn=task_schedule_interface,
|
| 15 |
+
inputs=gr.Textbox(label="Describe your task and time (e.g., Schedule meeting for tomorrow at 6PM)"),
|
| 16 |
+
outputs="text",
|
| 17 |
+
title="Task Scheduler Chatbot",
|
| 18 |
+
description="Helps you schedule tasks into your Google Calendar."
|
| 19 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
+
wellness_bot = gr.Interface(
|
| 22 |
+
fn=wellness_chatbot_interface,
|
| 23 |
+
inputs=[
|
| 24 |
+
gr.Textbox(label="Enter your unique user ID (e.g., email, username)"),
|
| 25 |
+
gr.Textbox(label="What would you like to discuss?"),
|
| 26 |
+
],
|
| 27 |
+
outputs="text",
|
| 28 |
+
title="Mental Wellness Chatbot",
|
| 29 |
+
description="Supports your mental wellness with tailored motivational advice."
|
| 30 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
|
| 32 |
+
# Combine into a tabbed interface
|
| 33 |
+
app = gr.TabbedInterface(
|
| 34 |
+
interfaces=[task_bot, wellness_bot],
|
| 35 |
+
tab_names=["Task Scheduler", "Mental Wellness Support"]
|
| 36 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
|
| 38 |
+
# Launch the app
|
| 39 |
+
if __name__ == "__main__":
|
| 40 |
+
app.launch()
|
|
|
|
|
|
|
|
|
|
|
|