studychatbot / app.py
sunny-gurung's picture
Update app.py
2b5543b verified
import gradio as gr
import time
#Provides streaming chatbot response
def streaming_response(user_input, history):
response = chatbot_response(user_input, history)
for i in range(len(response)):
time.sleep(0.1)
yield response[:i + 3]
#Response
def chatbot_response(user_input, history):
# Handle different questions
if user_input.lower() in ['hello', 'hi', 'hey']:
return "Hi there! 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."
elif 'help' in user_input.lower():
return "I'm here to assist with academic questions. Please specify what you'd like help with."
else:
return "I'm here to assist with academic questions. Please specify if you'd like help with any specific subject or topic."
#Block for defining layout of the Chatbot Interface
with gr.Blocks() as app:
chatbot = gr.ChatInterface(
streaming_response,
type="messages",
chatbot=gr.Chatbot(type="messages", height=500),
title="Study Assistance Chatbot",
description="Welcome! Ask me anything related to your academic studies.",
examples=["Hello","Hi", "Hey", "Help"]
)
app.launch()