import gradio as gr from transformers import pipeline model = pipeline("question-answering", model="Eitanli/distilbert-qa-checkpoint-v3") 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 = {} for question in questions: output['Question'] = question answers = model(question=question, context=context, topk=topk) output['Answer'] = '\n'.join([ans['answer'] for ans in answers if ans['score'] > answer_threshold]) return output iface = gr.Interface( fn=predict, inputs=[ gr.Textbox(label="Recipe line"), gr.Slider(0, 0.99, step=0.01, value=0.8, label="answer_threshold", info="Select a threshold in [0, 0.99]"), gr.Slider(1, 5, step=1.0, value=2, label="top k", info="Choose between 1 and 5")], outputs=gr.Textbox(label='Questions and answers') ) iface.launch()