Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| from simpletransformers.question_answering import QuestionAnsweringModel | |
| # create pipeline for QA | |
| model = QuestionAnsweringModel("bert", "./fine_tunned_model",use_cuda=False) | |
| def answer_question(context, question): | |
| predictions, raw_outputs = model.predict( | |
| [ | |
| { | |
| "context": context, | |
| "qas": [ | |
| { | |
| "question": question, | |
| "id": "0", | |
| } | |
| ], | |
| } | |
| ] | |
| ) | |
| return predictions[0]['answer'][0] | |
| iface = gr.Interface( | |
| fn=answer_question, | |
| inputs=[ | |
| gr.Textbox(type="text", label="Context"), | |
| gr.Textbox(type="text", label="Question") | |
| ], | |
| outputs=gr.Textbox(type="text", label="Answer") | |
| ) | |
| iface.launch() | |
| #%% | |