Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,38 +1,30 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from transformers import pipeline
|
| 3 |
|
| 4 |
-
|
| 5 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
-
# Define the context for the chatbot to answer academic-related questions
|
| 8 |
-
context = """
|
| 9 |
-
You can ask me anything related to academic topics! I can help explain concepts from math, science, and other subjects.
|
| 10 |
-
For example, I can explain calculus, biology, physics, programming, and more! Please type in your question, and I will try to answer it as best as I can.
|
| 11 |
-
"""
|
| 12 |
-
|
| 13 |
-
# Function that uses the QA pipeline to answer questions
|
| 14 |
-
def chatbot_response(question):
|
| 15 |
-
# Use the QA pipeline to answer the question based on the context
|
| 16 |
-
result = qa_pipeline(question=question, context=context)
|
| 17 |
-
return result["answer"]
|
| 18 |
-
|
| 19 |
-
# Define the Gradio interface
|
| 20 |
with gr.Blocks() as demo:
|
| 21 |
gr.Markdown("# Study Assistance Chatbot")
|
| 22 |
gr.Markdown("Welcome! Ask me anything related to your academic studies.")
|
| 23 |
-
|
| 24 |
with gr.Row():
|
| 25 |
with gr.Column():
|
| 26 |
user_input = gr.Textbox(label="Enter your question here:")
|
| 27 |
submit_button = gr.Button("Submit")
|
| 28 |
-
|
| 29 |
with gr.Column():
|
| 30 |
chatbot_output = gr.Textbox(label="Chatbot Response", interactive=False)
|
| 31 |
-
|
| 32 |
-
# Link the submit button to the chatbot response function
|
| 33 |
submit_button.click(chatbot_response, inputs=user_input, outputs=chatbot_output)
|
| 34 |
|
| 35 |
-
# Launch the Gradio app
|
| 36 |
demo.launch()
|
| 37 |
|
| 38 |
|
|
|
|
| 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?"
|
| 7 |
+
elif 'supervised learning' in user_input.lower():
|
| 8 |
+
return "Supervised learning is a machine learning approach where models are trained using labeled data."
|
| 9 |
+
elif 'help' in user_input.lower():
|
| 10 |
+
return "I'm here to assist with academic questions. Please specify what you'd like help with."
|
| 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 |
|
| 30 |
|