Spaces:
Runtime error
Runtime error
| import gradio as gr | |
| from transformers import pipeline | |
| import numpy as np | |
| model = pipeline("question-answering", model="Eitanli/distilbert-qa-checkpoint-v5") | |
| questions = ['which ingredients are mentioned?', | |
| 'what is the amount of ingredient mentioned?', | |
| 'what are the special instructions mentioned?'] | |
| def predict(context, topk, answer_threshold): | |
| output = 'Recipe analysis:' | |
| for question in questions: | |
| pred = model(question=question, context=context, topk=topk) | |
| answers = '\n'.join([f"{ans['answer']} ({np.round(ans['score'], 2)})" for ans in pred if ans['score'] > answer_threshold]) | |
| output += f'\n\n{question}:\n{answers}' | |
| return output | |
| iface = gr.Interface( | |
| fn=predict, | |
| inputs=[ | |
| gr.Textbox(label="Recipe line"), | |
| gr.Slider(1, 5, step=1.0, value=2, label="top k", info="Choose between 1 and 5"), | |
| gr.Slider(0, 0.99, step=0.01, value=0.8, label="answer_threshold", info="Select a threshold in [0, 0.99]")], | |
| outputs=gr.Textbox(label='Questions and answers') | |
| ) | |
| iface.launch() |