Spaces:
Runtime error
Runtime error
Eitan Lifshits
commited on
Commit
·
fd71869
1
Parent(s):
41923b5
initial implementation for all questions
Browse files- .gitignore +2 -0
- app.py +29 -0
- requirements.txt +2 -0
.gitignore
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
venv/
|
| 2 |
+
venv
|
app.py
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
|
| 4 |
+
model = pipeline("question-answering", model="Eitanli/distilbert-qa-checkpoint-v3")
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
questions = ['which ingredients are mentioned?',
|
| 8 |
+
'what is the amount of ingredient mentioned?',
|
| 9 |
+
'what are the special instructions mentioned?']
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
def predict(context, topk, answer_threshold):
|
| 13 |
+
output = {}
|
| 14 |
+
for question in questions:
|
| 15 |
+
output['Question'] = question
|
| 16 |
+
answers = model(question=question, context=context, topk=topk)
|
| 17 |
+
output['Answer'] = '\n'.join([ans['answer'] for ans in answers if ans['score'] > answer_threshold])
|
| 18 |
+
return output
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
iface = gr.Interface(
|
| 22 |
+
fn=predict,
|
| 23 |
+
inputs=[
|
| 24 |
+
gr.Textbox(label="Recipe line"),
|
| 25 |
+
gr.Slider(0, 0.99, step=0.01, value=0.8, label="answer_threshold", info="Select a threshold in [0, 0.99]"),
|
| 26 |
+
gr.Slider(1, 5, step=1.0, value=2, label="top k", info="Choose between 1 and 5")],
|
| 27 |
+
outputs=gr.Textbox(label='Questions and answers')
|
| 28 |
+
)
|
| 29 |
+
iface.launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
transformers==4.30.2
|
| 2 |
+
torch>=2.0
|