Spaces:
Sleeping
Sleeping
feat(ui):added new UI
Browse files
app.py
CHANGED
|
@@ -1,6 +1,15 @@
|
|
| 1 |
import gradio as gr
|
|
|
|
| 2 |
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
-
|
| 15 |
-
|
| 16 |
-
gr.
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
with gr.Column():
|
| 24 |
-
chatbot_output = gr.Textbox(label="Chatbot Response", interactive=False)
|
| 25 |
|
| 26 |
-
|
| 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 |
|