Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,16 +1,15 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
-
# Load
|
| 5 |
qa_pipeline = pipeline(
|
| 6 |
-
"question-answering",
|
| 7 |
-
model="deepset/roberta-base-squad2"
|
| 8 |
-
tokenizer="deepset/roberta-base-squad2"
|
| 9 |
)
|
| 10 |
|
| 11 |
-
#
|
| 12 |
def answer_question(context, question):
|
| 13 |
-
if context.strip()
|
| 14 |
return "Please enter both context and question."
|
| 15 |
|
| 16 |
result = qa_pipeline(
|
|
@@ -20,14 +19,14 @@ def answer_question(context, question):
|
|
| 20 |
|
| 21 |
return result["answer"]
|
| 22 |
|
| 23 |
-
# Gradio
|
| 24 |
-
|
| 25 |
fn=answer_question,
|
| 26 |
inputs=[
|
| 27 |
gr.Textbox(
|
| 28 |
lines=8,
|
| 29 |
label="Context",
|
| 30 |
-
placeholder="Enter paragraph
|
| 31 |
),
|
| 32 |
gr.Textbox(
|
| 33 |
lines=2,
|
|
@@ -37,7 +36,8 @@ app = gr.Interface(
|
|
| 37 |
],
|
| 38 |
outputs=gr.Textbox(label="Answer"),
|
| 39 |
title="RoBERTa Question Answering System",
|
| 40 |
-
description="Ask questions from given context using RoBERTa
|
| 41 |
)
|
| 42 |
|
| 43 |
-
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
+
# Load QA Model
|
| 5 |
qa_pipeline = pipeline(
|
| 6 |
+
task="question-answering",
|
| 7 |
+
model="deepset/roberta-base-squad2"
|
|
|
|
| 8 |
)
|
| 9 |
|
| 10 |
+
# Prediction Function
|
| 11 |
def answer_question(context, question):
|
| 12 |
+
if not context.strip() or not question.strip():
|
| 13 |
return "Please enter both context and question."
|
| 14 |
|
| 15 |
result = qa_pipeline(
|
|
|
|
| 19 |
|
| 20 |
return result["answer"]
|
| 21 |
|
| 22 |
+
# Gradio UI
|
| 23 |
+
demo = gr.Interface(
|
| 24 |
fn=answer_question,
|
| 25 |
inputs=[
|
| 26 |
gr.Textbox(
|
| 27 |
lines=8,
|
| 28 |
label="Context",
|
| 29 |
+
placeholder="Enter paragraph or context here..."
|
| 30 |
),
|
| 31 |
gr.Textbox(
|
| 32 |
lines=2,
|
|
|
|
| 36 |
],
|
| 37 |
outputs=gr.Textbox(label="Answer"),
|
| 38 |
title="RoBERTa Question Answering System",
|
| 39 |
+
description="Ask questions from the given context using RoBERTa."
|
| 40 |
)
|
| 41 |
|
| 42 |
+
# Launch for Hugging Face Spaces
|
| 43 |
+
demo.launch(server_name="0.0.0.0", server_port=7860)
|