Spaces:
Build error
Build error
Commit
Β·
1629f42
1
Parent(s):
a226e89
question answering text
Browse files
Pipfile
DELETED
@@ -1,14 +0,0 @@
|
|
1 |
-
[[source]]
|
2 |
-
url = "https://pypi.org/simple"
|
3 |
-
verify_ssl = true
|
4 |
-
name = "pypi"
|
5 |
-
|
6 |
-
[packages]
|
7 |
-
transformers = "*"
|
8 |
-
gradio = "*"
|
9 |
-
|
10 |
-
[dev-packages]
|
11 |
-
|
12 |
-
[requires]
|
13 |
-
python_version = "3.9"
|
14 |
-
python_full_version = "3.9.13"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Pipfile.lock
DELETED
The diff for this file is too large to render.
See raw diff
|
|
README.md
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
---
|
2 |
-
title:
|
3 |
emoji: π
|
4 |
colorFrom: blue
|
5 |
colorTo: white
|
|
|
1 |
---
|
2 |
+
title: Question Answer Text
|
3 |
emoji: π
|
4 |
colorFrom: blue
|
5 |
colorTo: white
|
app.py
CHANGED
@@ -1,17 +1,64 @@
|
|
1 |
import gradio as gr
|
2 |
-
from transformers import
|
3 |
-
title = "Vacancy Keyword Extraction"
|
4 |
-
description = "Add a vacancy and ask what keyword you would like to retrieve. For example, What is the job title? What is the city? What is the start date?"
|
5 |
|
|
|
|
|
6 |
|
7 |
-
classifier = pipeline("question-answering", model="deepset/roberta-base-squad2", model_max_length=512)
|
8 |
|
9 |
-
|
10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
return f'{prediction["answer"]}'
|
12 |
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
+
from transformers import pipeline
|
|
|
|
|
3 |
|
4 |
+
title = "Question Answer on Text"
|
5 |
+
description = "Provide a piece of text, ask a question and get a meaningful answer."
|
6 |
|
|
|
7 |
|
8 |
+
classifier = pipeline(
|
9 |
+
"question-answering", model="deepset/roberta-base-squad2", model_max_length=512
|
10 |
+
)
|
11 |
+
|
12 |
+
|
13 |
+
def zero_shot_classification(text_input, question):
|
14 |
+
prediction = classifier(
|
15 |
+
context=text_input,
|
16 |
+
question=question,
|
17 |
+
truncation=True,
|
18 |
+
max_length="max_length",
|
19 |
+
padding=True,
|
20 |
+
)
|
21 |
return f'{prediction["answer"]}'
|
22 |
|
23 |
+
|
24 |
+
examples = [
|
25 |
+
[
|
26 |
+
"""The invoice contains all the goods that are described in the order with number x9820be.
|
27 |
+
The goods are packaged and should arrive at the destination on 31/12/2023.
|
28 |
+
We kindly request to transfer the amount within 30 days of the invoice date to the account number BE00 9999 9999 9999""",
|
29 |
+
"what is the timeline to transfer the money?",
|
30 |
+
],
|
31 |
+
[
|
32 |
+
"""The invoice contains all the goods that are described in the order with number x9820be.
|
33 |
+
The goods are packaged and should arrive at the destination on 31/12/2023.
|
34 |
+
We kindly request to transfer the amount within 30 days of the invoice date to the account number BE00 9999 9999 9999""",
|
35 |
+
"what is the account number to transfer the money?",
|
36 |
+
],[
|
37 |
+
"""The invoice contains all the goods that are described in the order with number x9820be.
|
38 |
+
The goods are packaged and should arrive at the destination on 31/12/2023.
|
39 |
+
We kindly request to transfer the amount within 30 days of the invoice date to the account number BE00 9999 9999 9999""",
|
40 |
+
"order number",
|
41 |
+
],
|
42 |
+
[
|
43 |
+
"""By signing below, Shipper hereby declares that the contents of this consignment are fully and accurately described above by the proper shipping name and are classified,
|
44 |
+
packaged, marked and labelled/placarded, and are in all respects in proper condition for transport according to applicable governmental regulations. As shipper, I hereby
|
45 |
+
certify that the liquid industrial by-product(s) are fully and accurately described on this shipping document, in proper condition for transport, and that the information
|
46 |
+
contained on the shipping document is factual.""",
|
47 |
+
"are the goods described?",
|
48 |
+
],
|
49 |
+
]
|
50 |
+
|
51 |
+
gr.Interface(
|
52 |
+
fn=zero_shot_classification,
|
53 |
+
inputs=[
|
54 |
+
gr.inputs.Textbox(lines=10, label="Text", placeholder="Paste text here ..."),
|
55 |
+
gr.inputs.Textbox(
|
56 |
+
lines=2,
|
57 |
+
label="Question",
|
58 |
+
placeholder="Ask what you want to retrieve from the vacancy.",
|
59 |
+
),
|
60 |
+
],
|
61 |
+
outputs=gr.outputs.Textbox(label="Answer"),
|
62 |
+
title=title,
|
63 |
+
description=description,
|
64 |
+
).launch(share=False)
|