asiaao commited on
Commit
d505fe6
·
verified ·
1 Parent(s): 159d2ee

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -64
app.py CHANGED
@@ -1,70 +1,40 @@
1
- import streamlit as st
2
- import dateparser
3
- from google.oauth2.credentials import Credentials
4
- from googleapiclient.discovery import build
5
 
6
- # Google Calendar API setup
7
- SCOPES = ['https://www.googleapis.com/auth/calendar']
 
8
 
9
- def authenticate_google_calendar():
10
- """Authenticate and return the Google Calendar service."""
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
- def add_event_to_calendar(service, title, start_datetime):
18
- """Add an event to Google Calendar."""
19
- event = {
20
- 'summary': title,
21
- 'start': {'dateTime': start_datetime, 'timeZone': 'UTC'},
22
- 'end': {'dateTime': start_datetime, 'timeZone': 'UTC'},
23
- }
24
- try:
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
- def parse_input_and_schedule(input_text):
32
- """Parse user input for title and datetime, then schedule the event."""
33
-
34
- # Split the input into words and extract the event title and date/time
35
- words = input_text.split(' at ') # Splitting around 'at' to separate title and time part
36
- if len(words) < 2:
37
- st.error("Could not parse the event. Make sure to specify the title and time (e.g., 'gym for tomorrow at 6pm' or 'meeting for December 7 at 8:30am').")
38
- return
39
-
40
- title = words[0].strip() # The event title
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
- # If parsed_date is earlier than today, it may be misinterpreted, so we adjust
52
- today = dateparser.parse("today")
53
- if parsed_date.date() < today.date():
54
- st.error(f"The date seems to be incorrect. Please check the input format for specific dates like 'December 7 at 3:34pm'.")
55
- return
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
- # Streamlit App
65
- st.title("Smart Scheduler with Google Calendar")
66
- st.write("Add tasks to your schedule using natural language.")
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()