Spaces:
Sleeping
Sleeping
Update chatbot_ui.py
Browse files12345678910111213141516171819202122232425262712345678910111213141516171819202122232425262728293031323334353637383940414243444546import gradio as gr
def chatbot_response(user_input):
if user_input.lower() in ["hello", "hi"]:
return "Hello! How can I help you with your studies today?"
elif "supervised learning" in user_input.lower():
return "Supervised learning is a machine learning approach where models are trained using labeled data."
else:
return "I'm here to assist you with your academic questions. Please ask me anything!"
with gr.Blocks() as demo:
gr.Markdown("# Study Assistance Chatbot")
gr.Markdown("Welcome! Ask me anything related to your academic studies.")
with gr.Row():
with gr.Column():
user_input = gr.Textbox(label="Enter your question here:")
submit_button = gr.Button("Submit")
with gr.Column():
chatbot_output = gr.Textbox(label="Chatbot Response", interactive=False)
submit_button.click(chatbot_response, inputs=user_input, outputs=chatbot_output)
demo.launch()
import gradio as gr # For building the chatbot UIimport random # For generating random responses
# Chatbot response functiondef chatbot_response(user_input): user_input = user_input.lower()
if user_input.strip() == "": # Show the welcome message for empty input return "Welcome! How can I assist you with your studies today?"
if "time management" in user_input: return "Time management is key! Try creating a prioritized to-do list and setting specific study blocks."
elif "study tips" in user_input: tips = [ "Take regular breaks while studying to stay focused.", "Use active recall and spaced repetition for better retention.", "Set a specific goal for each study session." ] return random.choice(tips) # Randomly pick a study tip
elif "hello" in user_input or "hi" in user_input: return "Hello! How can I help you with your studies today?"
else: return "I'm here to assist with general academic questions. Feel free to ask about study tips, time management, or anything else!"
# Gradio interfacewith gr.Blocks() as demo: gr.Markdown("# Study Assistance Chatbot") gr.Markdown("Welcome! Ask me anything related to your academic studies.") with gr.Row(): with gr.Column(): user_input = gr.Textbox(label="Enter your question here:") submit_button = gr.Button("Submit") with gr.Column(): chatbot_output = gr.Textbox(label="Chatbot Response", interactive=False) submit_button.click(chatbot_response, inputs=user_input, outputs=chatbot_output)
# Launch the Gradio appdemo.launch()
chatbot_ui.py+46-27