Spaces:
Sleeping
Sleeping
Adding application and requirements file
Browse files- app.py +57 -0
- requirements.txt +4 -0
app.py
ADDED
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import pipeline
|
3 |
+
|
4 |
+
def qa_interface(context, question):
|
5 |
+
model_checkpoint = "AirrStorm/BERT-SQUAD-QA-Finetuned"
|
6 |
+
question_answerer = pipeline("question-answering", model=model_checkpoint)
|
7 |
+
answer = question_answerer(question=question, context=context)
|
8 |
+
return answer['answer']
|
9 |
+
|
10 |
+
# Define inputs
|
11 |
+
inputs = [
|
12 |
+
gr.Textbox(
|
13 |
+
lines=10,
|
14 |
+
label="Context",
|
15 |
+
placeholder="Enter the context where the answer can be found...",
|
16 |
+
),
|
17 |
+
gr.Textbox(
|
18 |
+
label="Question",
|
19 |
+
placeholder="Enter a specific question based on the provided context..."
|
20 |
+
)
|
21 |
+
]
|
22 |
+
|
23 |
+
# Define example inputs
|
24 |
+
examples = [
|
25 |
+
[
|
26 |
+
"The Eiffel Tower is one of the most famous landmarks in Paris, France. It was constructed in 1889 and stands approximately 330 meters tall.",
|
27 |
+
"When was the Eiffel Tower constructed?"
|
28 |
+
],
|
29 |
+
[
|
30 |
+
"Python is a versatile programming language known for its simplicity and readability. It is widely used for web development, data analysis, artificial intelligence, and more.",
|
31 |
+
"What is Python known for?"
|
32 |
+
],
|
33 |
+
[
|
34 |
+
"The Great Wall of China stretches over 13,000 miles and was built to protect Chinese states from invasions. It is considered one of the greatest architectural achievements in history.",
|
35 |
+
"How long is the Great Wall of China?"
|
36 |
+
],
|
37 |
+
]
|
38 |
+
|
39 |
+
# Create the Gradio interface
|
40 |
+
interface = gr.Interface(
|
41 |
+
fn=qa_interface,
|
42 |
+
inputs=inputs,
|
43 |
+
outputs=gr.Textbox(
|
44 |
+
label="Answer",
|
45 |
+
placeholder="The model's answer will appear here."
|
46 |
+
),
|
47 |
+
title="Question Answering (QA) Tool",
|
48 |
+
description=(
|
49 |
+
"This tool uses a Question Answering (QA) model to find and return the most relevant answer "
|
50 |
+
"to a specific question based on the provided context.\n\n"
|
51 |
+
"Provide a context paragraph and a related question to get started!"
|
52 |
+
),
|
53 |
+
examples=examples,
|
54 |
+
theme="hugging-face", # Optional theme for a polished look
|
55 |
+
)
|
56 |
+
|
57 |
+
interface.launch()
|
requirements.txt
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
transformers
|
2 |
+
torch
|
3 |
+
SentencePiece
|
4 |
+
sacremoses
|