Spaces:
Sleeping
Sleeping
Update app.py
Browse files1234567891011121314151617181920212223242526272829303132333435363738import gradio as grfrom transformers import pipeline# Set up the question-answering pipeline with DistilBERTqa_pipeline = pipeline("question-answering", model="distilbert-base-uncased-distilled-squad")# Define the context for the chatbot to answer academic-related questionscontext = """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 questionsdef chatbot_response(question):# Use the QA pipeline to answer the question based on the contextresult = qa_pipeline(question=question, context=context)return result["answer"]# Define the Gradio interfacewith 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 functionsubmit_button.click(chatbot_response, inputs=user_input, outputs=chatbot_output)# Launch the Gradio appdemo.launch()123456789101112131415161718192021222324252627282930import gradio as grdef chatbot_response(user_input):# Handle different questionsif user_input.lower() in ['hello', 'hi', 'hey']:return "Hi there! How can I help you with your studies today?"elif 'supervised learning' in user_input.lower():return "Supervised learning is a machine learning approach where models are trained using labeled data."elif 'help' in user_input.lower():return "I'm here to assist with academic questions. Please specify what you'd like help with."else:return "I'm here to assist with academic questions. Please specify if you'd like help with any specific subject or topic."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)submit_button.click(chatbot_response, inputs=user_input, outputs=chatbot_output)demo.launch()
app.py+13-21