Spaces:
Sleeping
Sleeping
Update chatbot_ui.py
Browse files- chatbot_ui.py +46 -27
chatbot_ui.py
CHANGED
|
@@ -1,27 +1,46 @@
|
|
| 1 |
-
import gradio as gr
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
return "
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
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 |
+
if user_input.strip() == "": # Show the welcome message for empty input
|
| 9 |
+
return "Welcome! How can I assist you with your studies today?"
|
| 10 |
+
|
| 11 |
+
if "time management" in user_input:
|
| 12 |
+
return "Time management is key! Try creating a prioritized to-do list and setting specific study blocks."
|
| 13 |
+
|
| 14 |
+
elif "study tips" in user_input:
|
| 15 |
+
tips = [
|
| 16 |
+
"Take regular breaks while studying to stay focused.",
|
| 17 |
+
"Use active recall and spaced repetition for better retention.",
|
| 18 |
+
"Set a specific goal for each study session."
|
| 19 |
+
]
|
| 20 |
+
return random.choice(tips) # Randomly pick a study tip
|
| 21 |
+
|
| 22 |
+
elif "hello" in user_input or "hi" in user_input:
|
| 23 |
+
return "Hello! How can I help you with your studies today?"
|
| 24 |
+
|
| 25 |
+
else:
|
| 26 |
+
return "I'm here to assist with general academic questions. Feel free to ask about study tips, time management, or anything else!"
|
| 27 |
+
|
| 28 |
+
# Gradio interface
|
| 29 |
+
with gr.Blocks() as demo:
|
| 30 |
+
gr.Markdown("# Study Assistance Chatbot")
|
| 31 |
+
gr.Markdown("Welcome! Ask me anything related to your academic studies.")
|
| 32 |
+
|
| 33 |
+
with gr.Row():
|
| 34 |
+
with gr.Column():
|
| 35 |
+
user_input = gr.Textbox(label="Enter your question here:")
|
| 36 |
+
submit_button = gr.Button("Submit")
|
| 37 |
+
|
| 38 |
+
with gr.Column():
|
| 39 |
+
chatbot_output = gr.Textbox(label="Chatbot Response", interactive=False)
|
| 40 |
+
|
| 41 |
+
submit_button.click(chatbot_response, inputs=user_input, outputs=chatbot_output)
|
| 42 |
+
|
| 43 |
+
# Launch the Gradio app
|
| 44 |
+
demo.launch()
|
| 45 |
+
|
| 46 |
+
|