File size: 1,490 Bytes
a8e7c75
9dce57b
b26fbd2
9dce57b
 
b26fbd2
9dce57b
 
 
 
 
a8e7c75
9dce57b
 
 
 
 
b760005
9dce57b
b760005
b26fbd2
b760005
 
 
 
 
 
9dce57b
b760005
 
9dce57b
 
b760005
 
9dce57b
b760005
a8e7c75
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
from transformers import pipeline

# Set up the question-answering pipeline with DistilBERT
qa_pipeline = pipeline("question-answering", model="distilbert-base-uncased-distilled-squad")

# Define the context for the chatbot to answer academic-related questions
context = """
You can ask me anything related to academic topics! I can help explain concepts from math, science, and other subjects. 
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.
"""

# Function that uses the QA pipeline to answer questions
def chatbot_response(question):
    # Use the QA pipeline to answer the question based on the context
    result = qa_pipeline(question=question, context=context)
    return result["answer"]

# Define the Gradio interface
with gr.Blocks() as demo:
    gr.Markdown("# Study Assistance Chatbot")
    gr.Markdown("Welcome! Ask me anything related to your academic studies.")
    
    with gr.Row():
        with gr.Column():
            user_input = gr.Textbox(label="Enter your question here:")
            submit_button = gr.Button("Submit")
        
        with gr.Column():
            chatbot_output = gr.Textbox(label="Chatbot Response", interactive=False)
    
    # Link the submit button to the chatbot response function
    submit_button.click(chatbot_response, inputs=user_input, outputs=chatbot_output)

# Launch the Gradio app
demo.launch()