Spaces:
Sleeping
Sleeping
Update chatbot_ui.py
Browse files- 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
|
| 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."
|
| 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)
|
| 19 |
|
| 20 |
elif "hello" in user_input or "hi" in user_input:
|
| 21 |
-
return "Hello! How can I
|
| 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,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 |
-
#
|
| 36 |
-
|
| 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 |
+
|