Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,18 +1,18 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
-
# Load QA model
|
| 5 |
-
|
| 6 |
"question-answering",
|
| 7 |
-
model="
|
| 8 |
)
|
| 9 |
|
| 10 |
# Function
|
| 11 |
-
def
|
| 12 |
-
if
|
| 13 |
-
return "Please enter
|
| 14 |
|
| 15 |
-
result =
|
| 16 |
question=question,
|
| 17 |
context=context
|
| 18 |
)
|
|
@@ -21,22 +21,14 @@ def answer_question(context, question):
|
|
| 21 |
|
| 22 |
# UI
|
| 23 |
demo = gr.Interface(
|
| 24 |
-
fn=
|
| 25 |
inputs=[
|
| 26 |
-
gr.Textbox(
|
| 27 |
-
|
| 28 |
-
label="Context",
|
| 29 |
-
placeholder="Paste paragraph here..."
|
| 30 |
-
),
|
| 31 |
-
gr.Textbox(
|
| 32 |
-
lines=2,
|
| 33 |
-
label="Question",
|
| 34 |
-
placeholder="Ask question..."
|
| 35 |
-
)
|
| 36 |
],
|
| 37 |
-
outputs=
|
| 38 |
-
title="🔍
|
| 39 |
-
description="
|
| 40 |
theme=gr.themes.Soft()
|
| 41 |
)
|
| 42 |
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
+
# Load lightweight QA model
|
| 5 |
+
qa_pipeline = pipeline(
|
| 6 |
"question-answering",
|
| 7 |
+
model="distilbert-base-cased-distilled-squad"
|
| 8 |
)
|
| 9 |
|
| 10 |
# Function
|
| 11 |
+
def answer(context, question):
|
| 12 |
+
if context.strip() == "" or question.strip() == "":
|
| 13 |
+
return "Please enter context and question."
|
| 14 |
|
| 15 |
+
result = qa_pipeline(
|
| 16 |
question=question,
|
| 17 |
context=context
|
| 18 |
)
|
|
|
|
| 21 |
|
| 22 |
# UI
|
| 23 |
demo = gr.Interface(
|
| 24 |
+
fn=answer,
|
| 25 |
inputs=[
|
| 26 |
+
gr.Textbox(lines=8, label="Context"),
|
| 27 |
+
gr.Textbox(lines=2, label="Question")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
],
|
| 29 |
+
outputs="text",
|
| 30 |
+
title="🔍 QA System",
|
| 31 |
+
description="Ask questions from given context.",
|
| 32 |
theme=gr.themes.Soft()
|
| 33 |
)
|
| 34 |
|