Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| from transformers import pipeline | |
| # Load the question answering model | |
| qa = pipeline("question-answering") | |
| # Define the function to generate the answer | |
| def generate_answer(context, question): | |
| result = qa(question=question, context=context) | |
| return result["answer"] | |
| # Define the Gradio interface | |
| inputs = [ | |
| gr.components.Textbox(label="Enter some context"), | |
| gr.components.Textbox(label="Enter a question") | |
| ] | |
| outputs = gr.components.Textbox(label="Answer") | |
| title = "Question Answering with Hugging Face" | |
| description = "Answer questions based on a given context using Hugging Face's question answering model" | |
| iface = gr.Interface(fn=generate_answer, inputs=inputs, outputs=outputs, title=title, description=description) | |
| # Launch the Gradio app | |
| iface.launch() |