sunny-gurung commited on
Commit
846940f
·
verified ·
1 Parent(s): a255af4

feat(ui):added new UI

Browse files
Files changed (1) hide show
  1. app.py +20 -15
app.py CHANGED
@@ -1,6 +1,15 @@
1
  import gradio as gr
 
2
 
3
- def chatbot_response(user_input):
 
 
 
 
 
 
 
 
4
  # Handle different questions
5
  if user_input.lower() in ['hello', 'hi', 'hey']:
6
  return "Hi there! How can I help you with your studies today?"
@@ -11,22 +20,18 @@ def chatbot_response(user_input):
11
  else:
12
  return "I'm here to assist with academic questions. Please specify if you'd like help with any specific subject or topic."
13
 
14
- with gr.Blocks() as demo:
15
- gr.Markdown("# Study Assistance Chatbot")
16
- gr.Markdown("Welcome! Ask me anything related to your academic studies.")
17
-
18
- with gr.Row():
19
- with gr.Column():
20
- user_input = gr.Textbox(label="Enter your question here:")
21
- submit_button = gr.Button("Submit")
22
-
23
- with gr.Column():
24
- chatbot_output = gr.Textbox(label="Chatbot Response", interactive=False)
25
 
26
- submit_button.click(chatbot_response, inputs=user_input, outputs=chatbot_output)
27
 
28
- demo.launch()
29
- from datasets import load_dataset
30
 
31
 
32
 
 
1
  import gradio as gr
2
+ import time
3
 
4
+ #Provides streaming chatbot response
5
+ def streaming_response(user_input, history):
6
+ response = chatbot_response(user_input, history)
7
+ for i in range(len(response)):
8
+ time.sleep(0.3)
9
+ yield response[:i+1]
10
+
11
+ #Response
12
+ def chatbot_response(user_input, history):
13
  # Handle different questions
14
  if user_input.lower() in ['hello', 'hi', 'hey']:
15
  return "Hi there! How can I help you with your studies today?"
 
20
  else:
21
  return "I'm here to assist with academic questions. Please specify if you'd like help with any specific subject or topic."
22
 
23
+ #Block for defining layout of the Chatbot Interface
24
+ with gr.Blocks() as app:
25
+ chatbot = gr.ChatInterface(
26
+ streaming_response,
27
+ type="messages",
28
+ title="Study Assistance Chatbot",
29
+ description="Welcome! Ask me anything related to your academic studies.",
30
+ examples=["Hello","Hi", "Hey", "Help"]
31
+ )
 
 
32
 
33
+ app.launch()
34
 
 
 
35
 
36
 
37