Spaces:
Runtime error
Runtime error
vincentclaes
commited on
Commit
·
73c5cd9
0
Parent(s):
Duplicate from drift-ai/question-answer-text
Browse files- .gitattributes +34 -0
- README.md +13 -0
- app.py +71 -0
- requirements.txt +3 -0
.gitattributes
ADDED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
*.7z filter=lfs diff=lfs merge=lfs -text
|
2 |
+
*.arrow filter=lfs diff=lfs merge=lfs -text
|
3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
4 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
5 |
+
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
6 |
+
*.ftz filter=lfs diff=lfs merge=lfs -text
|
7 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
8 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
9 |
+
*.joblib filter=lfs diff=lfs merge=lfs -text
|
10 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
11 |
+
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
12 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
13 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
14 |
+
*.npy filter=lfs diff=lfs merge=lfs -text
|
15 |
+
*.npz filter=lfs diff=lfs merge=lfs -text
|
16 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
17 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
18 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
19 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
20 |
+
*.pickle filter=lfs diff=lfs merge=lfs -text
|
21 |
+
*.pkl filter=lfs diff=lfs merge=lfs -text
|
22 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
23 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
24 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
25 |
+
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
26 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
27 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
28 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
29 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
30 |
+
*.wasm filter=lfs diff=lfs merge=lfs -text
|
31 |
+
*.xz filter=lfs diff=lfs merge=lfs -text
|
32 |
+
*.zip filter=lfs diff=lfs merge=lfs -text
|
33 |
+
*.zst filter=lfs diff=lfs merge=lfs -text
|
34 |
+
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
README.md
ADDED
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
title: Question Answer Text
|
3 |
+
emoji: 🚀
|
4 |
+
colorFrom: blue
|
5 |
+
colorTo: white
|
6 |
+
sdk: gradio
|
7 |
+
sdk_version: 3.12.0
|
8 |
+
app_file: app.py
|
9 |
+
pinned: false
|
10 |
+
duplicated_from: drift-ai/question-answer-text
|
11 |
+
---
|
12 |
+
|
13 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app.py
ADDED
@@ -0,0 +1,71 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import pipeline
|
3 |
+
|
4 |
+
title = "Question Answer on Text"
|
5 |
+
description = """
|
6 |
+
- Provide a piece of text.
|
7 |
+
- Ask a question or specify an entity you would like to extract.
|
8 |
+
- Receive an answer.
|
9 |
+
|
10 |
+
Try out the examples at the bottom.
|
11 |
+
"""
|
12 |
+
|
13 |
+
|
14 |
+
classifier = pipeline(
|
15 |
+
"question-answering", model="deepset/roberta-base-squad2", model_max_length=512
|
16 |
+
)
|
17 |
+
|
18 |
+
|
19 |
+
def zero_shot_classification(text_input, question):
|
20 |
+
prediction = classifier(
|
21 |
+
context=text_input,
|
22 |
+
question=question,
|
23 |
+
truncation=True,
|
24 |
+
max_length="max_length",
|
25 |
+
padding=True,
|
26 |
+
)
|
27 |
+
return f'{prediction["answer"]}'
|
28 |
+
|
29 |
+
|
30 |
+
examples = [
|
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 IE12BOFI90000112345678. """,
|
35 |
+
"what is the timeline to transfer the money?",
|
36 |
+
],
|
37 |
+
[
|
38 |
+
"""The invoice contains all the goods that are described in the order with number x9820be.
|
39 |
+
The goods are packaged and should arrive at the destination on 31/12/2023.
|
40 |
+
We kindly request to transfer the amount within 30 days of the invoice date to the account number IE12BOFI90000112345678""",
|
41 |
+
"what is the account number to transfer the money?",
|
42 |
+
],[
|
43 |
+
"""The invoice contains all the goods that are described in the order with number x9820be.
|
44 |
+
The goods are packaged and should arrive at the destination on 31/12/2023.
|
45 |
+
We kindly request to transfer the amount within 30 days of the invoice date to the account number IE12BOFI90000112345678""",
|
46 |
+
"order number",
|
47 |
+
],
|
48 |
+
[
|
49 |
+
"""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,
|
50 |
+
packaged, marked and labelled/placarded, and are in all respects in proper condition for transport according to applicable governmental regulations. As shipper, I hereby
|
51 |
+
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
|
52 |
+
contained on the shipping document is factual.""",
|
53 |
+
"are the goods described?",
|
54 |
+
],
|
55 |
+
]
|
56 |
+
|
57 |
+
gr.Interface(
|
58 |
+
fn=zero_shot_classification,
|
59 |
+
inputs=[
|
60 |
+
gr.inputs.Textbox(lines=10, label="Text", placeholder="Paste text here ..."),
|
61 |
+
gr.inputs.Textbox(
|
62 |
+
lines=2,
|
63 |
+
label="Question",
|
64 |
+
placeholder="Ask what you want to retrieve from the vacancy.",
|
65 |
+
),
|
66 |
+
],
|
67 |
+
outputs=gr.outputs.Textbox(label="Answer"),
|
68 |
+
title=title,
|
69 |
+
description=description,
|
70 |
+
examples=examples,
|
71 |
+
).launch(share=False)
|
requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
transformers
|
2 |
+
gradio
|
3 |
+
torch
|