Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
|
| 4 |
+
# Load the question answering model
|
| 5 |
+
qa = pipeline("question-answering")
|
| 6 |
+
|
| 7 |
+
# Define the function to generate the answer
|
| 8 |
+
def generate_answer(context, question):
|
| 9 |
+
result = qa(question=question, context=context)
|
| 10 |
+
return result["answer"]
|
| 11 |
+
|
| 12 |
+
# Define the Gradio interface
|
| 13 |
+
inputs = [
|
| 14 |
+
gr.inputs.Textbox(label="Enter some context"),
|
| 15 |
+
gr.inputs.Textbox(label="Enter a question")
|
| 16 |
+
]
|
| 17 |
+
outputs = gr.outputs.Textbox(label="Answer")
|
| 18 |
+
|
| 19 |
+
title = "Question Answering with Hugging Face"
|
| 20 |
+
description = "Answer questions based on a given context using Hugging Face's question answering model"
|
| 21 |
+
|
| 22 |
+
iface = gr.Interface(fn=generate_answer, inputs=inputs, outputs=outputs, title=title, description=description)
|
| 23 |
+
|
| 24 |
+
# Launch the Gradio app
|
| 25 |
+
iface.launch()
|