File size: 1,338 Bytes
a8e7c75
846940f
b26fbd2
846940f
 
 
 
cf44030
2b5543b
846940f
 
 
8ae3903
 
 
 
 
 
 
 
 
b26fbd2
846940f
 
 
 
 
c12c354
846940f
 
 
 
8ae3903
846940f
b760005
a8e7c75
82048a4
cbb60b6
a8e7c75
d20e712
4c522a2
9dce57b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
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()