Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,23 +1,22 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from transformers import pipeline
|
| 3 |
|
| 4 |
-
#
|
| 5 |
-
|
| 6 |
-
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 7 |
-
model = AutoModelForCausalLM.from_pretrained(model_name)
|
| 8 |
|
| 9 |
-
#
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
-
#
|
| 13 |
-
def chatbot_response(
|
| 14 |
-
#
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
# Extract and return the generated text
|
| 18 |
-
return response[0]['generated_text']
|
| 19 |
|
| 20 |
-
#
|
| 21 |
with gr.Blocks() as demo:
|
| 22 |
gr.Markdown("# Study Assistance Chatbot")
|
| 23 |
gr.Markdown("Welcome! Ask me anything related to your academic studies.")
|
|
@@ -26,14 +25,18 @@ with gr.Blocks() as demo:
|
|
| 26 |
with gr.Column():
|
| 27 |
user_input = gr.Textbox(label="Enter your question here:")
|
| 28 |
submit_button = gr.Button("Submit")
|
|
|
|
| 29 |
with gr.Column():
|
| 30 |
chatbot_output = gr.Textbox(label="Chatbot Response", interactive=False)
|
| 31 |
-
|
|
|
|
| 32 |
submit_button.click(chatbot_response, inputs=user_input, outputs=chatbot_output)
|
| 33 |
|
|
|
|
| 34 |
demo.launch()
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
| 3 |
|
| 4 |
+
# Set up the question-answering pipeline with DistilBERT
|
| 5 |
+
qa_pipeline = pipeline("question-answering", model="distilbert-base-uncased-distilled-squad")
|
|
|
|
|
|
|
| 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.")
|
|
|
|
| 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 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
+
|