Spaces:
Sleeping
Sleeping
Update chatbot_ui.py
Browse files1 unmodified line23456789101112131 unmodified line151617181920212223242526274 unmodified lines32333435363738394041421 unmodified lineimport random # For generating random responses# Chatbot response functiondef chatbot_response(user_input, history):user_input = user_input.lower()# Handle time management and study tipsif "time management" in user_input:return "Time management is key! Try creating a prioritized to-do list and setting specific study blocks.", historyelif "study tips" in user_input:tips = [1 unmodified line"Use active recall and spaced repetition for better retention.","Set a specific goal for each study session."]return random.choice(tips), historyelif "hello" in user_input or "hi" in user_input:return "Hello! How can I help you with your studies today?", historyelse:return "I'm here to assist with general academic questions. Feel free to ask about study tips, time management, or anything else!", history# Gradio interface setupwith gr.Blocks() as demo:4 unmodified linesuser_input = gr.Textbox(label="Enter your question here:", placeholder="Type your question...") # Textbox for user inputsubmit_button = gr.Button("Submit") # Submit button for user input# Initialize the chat history as an empty listinitial_history = []# Submit action - to update chat with response and add it to chat historysubmit_button.click(chatbot_response, inputs=[user_input, chatbot], outputs=[user_input, chatbot])# Launch the Gradio appdemo.launch()1 unmodified line23456789101112131 unmodified line151617181920212223242526274 unmodified lines3233343536373839401 unmodified lineimport random # For generating random responses# Chatbot response functiondef chatbot_response(user_input):user_input = user_input.strip().lower()# Handle time management and study tipsif "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 = [1 unmodified line"Use active recall and spaced repetition for better retention.","Set a specific goal for each study session."]return random.choice(tips)elif "hello" in user_input or "hi" in user_input:return "Hello! How can I assist 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 interface setupwith gr.Blocks() as demo:4 unmodified linesuser_input = gr.Textbox(label="Enter your question here:", placeholder="Type your question...") # Textbox for user inputsubmit_button = gr.Button("Submit") # Submit button for user input# Submit action - to update chat with responsesubmit_button.click(chatbot_response, inputs=user_input, outputs=chatbot)# Launch the Gradio appdemo.launch()
chatbot_ui.py+9-11