|
from transformers import pipeline |
|
import gradio as gr |
|
|
|
question_answer = pipeline('question-answering',model = 'distilbert/distilbert-base-cased-distilled-squad') |
|
|
|
output = pipe({ |
|
'context': context, |
|
'question': question |
|
}) |
|
|
|
def question_answering(context, question): |
|
|
|
output = question_answer({ |
|
'context': context, |
|
'question': question |
|
}) |
|
|
|
return output['answer'], str(output['score'] * 100) |
|
|
|
iface = gr.Interface( |
|
fn = question_answering, |
|
inputs = [ |
|
gr.Textbox(label = "Context", placeholder = "Enter your context here..", lines = 5), |
|
gr.Textbox(label = "Question", placeholder = "Enter your question", lines = 2) |
|
], |
|
outputs = [ |
|
gr.Textbox(label = "Answer", lines = 2), |
|
gr.Textbox(label = "Accuracy") |
|
] |
|
) |