MissieMcCown commited on
Commit
3fd078e
·
verified ·
1 Parent(s): 4f2661c

Update chatbot_ui.py

Browse files
Files changed (1) hide show
  1. chatbot_ui.py +9 -11
chatbot_ui.py CHANGED
@@ -2,12 +2,12 @@ import gradio as gr # For building the chatbot UI
2
  import random # For generating random responses
3
 
4
  # Chatbot response function
5
- def chatbot_response(user_input, history):
6
- user_input = user_input.lower()
7
 
8
  # Handle time management and study tips
9
  if "time management" in user_input:
10
- return "Time management is key! Try creating a prioritized to-do list and setting specific study blocks.", history
11
 
12
  elif "study tips" in user_input:
13
  tips = [
@@ -15,13 +15,13 @@ def chatbot_response(user_input, history):
15
  "Use active recall and spaced repetition for better retention.",
16
  "Set a specific goal for each study session."
17
  ]
18
- return random.choice(tips), history
19
 
20
  elif "hello" in user_input or "hi" in user_input:
21
- return "Hello! How can I help you with your studies today?", history
22
 
23
  else:
24
- return "I'm here to assist with general academic questions. Feel free to ask about study tips, time management, or anything else!", history
25
 
26
  # Gradio interface setup
27
  with gr.Blocks() as demo:
@@ -32,11 +32,9 @@ with gr.Blocks() as demo:
32
  user_input = gr.Textbox(label="Enter your question here:", placeholder="Type your question...") # Textbox for user input
33
  submit_button = gr.Button("Submit") # Submit button for user input
34
 
35
- # Initialize the chat history as an empty list
36
- initial_history = []
37
-
38
- # Submit action - to update chat with response and add it to chat history
39
- submit_button.click(chatbot_response, inputs=[user_input, chatbot], outputs=[user_input, chatbot])
40
 
41
  # Launch the Gradio app
42
  demo.launch()
 
 
2
  import random # For generating random responses
3
 
4
  # Chatbot response function
5
+ def chatbot_response(user_input):
6
+ user_input = user_input.strip().lower()
7
 
8
  # Handle time management and study tips
9
  if "time management" in user_input:
10
+ return "Time management is key! Try creating a prioritized to-do list and setting specific study blocks."
11
 
12
  elif "study tips" in user_input:
13
  tips = [
 
15
  "Use active recall and spaced repetition for better retention.",
16
  "Set a specific goal for each study session."
17
  ]
18
+ return random.choice(tips)
19
 
20
  elif "hello" in user_input or "hi" in user_input:
21
+ return "Hello! How can I assist you with your studies today?"
22
 
23
  else:
24
+ return "I'm here to assist with general academic questions. Feel free to ask about study tips, time management, or anything else!"
25
 
26
  # Gradio interface setup
27
  with gr.Blocks() as demo:
 
32
  user_input = gr.Textbox(label="Enter your question here:", placeholder="Type your question...") # Textbox for user input
33
  submit_button = gr.Button("Submit") # Submit button for user input
34
 
35
+ # Submit action - to update chat with response
36
+ submit_button.click(chatbot_response, inputs=user_input, outputs=chatbot)
 
 
 
37
 
38
  # Launch the Gradio app
39
  demo.launch()
40
+