Spaces:
Sleeping
Sleeping
Upload 2 files
Browse files- app.py +29 -0
- requirements.txt +3 -0
app.py
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
|
| 4 |
+
# Load QA pipeline
|
| 5 |
+
qa_pipeline = pipeline("question-answering", model="distilbert-base-uncased-distilled-squad")
|
| 6 |
+
|
| 7 |
+
def answer_question(context, question):
|
| 8 |
+
result = qa_pipeline(question=question, context=context)
|
| 9 |
+
return result['answer']
|
| 10 |
+
|
| 11 |
+
with gr.Blocks() as demo:
|
| 12 |
+
gr.Markdown("## 📘 Question Answering App (Extractive QA)")
|
| 13 |
+
|
| 14 |
+
context = gr.Textbox(
|
| 15 |
+
lines=8,
|
| 16 |
+
placeholder="Paste a paragraph or article here...",
|
| 17 |
+
label="Context Paragraph"
|
| 18 |
+
)
|
| 19 |
+
question = gr.Textbox(
|
| 20 |
+
lines=2,
|
| 21 |
+
placeholder="Type your question here...",
|
| 22 |
+
label="Question"
|
| 23 |
+
)
|
| 24 |
+
output = gr.Textbox(label="Answer")
|
| 25 |
+
|
| 26 |
+
btn = gr.Button("Get Answer")
|
| 27 |
+
btn.click(fn=answer_question, inputs=[context, question], outputs=output)
|
| 28 |
+
|
| 29 |
+
demo.launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio>=3.30
|
| 2 |
+
transformers>=4.40
|
| 3 |
+
torch>=1.13
|