Bert_ita_QandA / app.py
z-uo's picture
Update app.py
c8e9f8f
import gradio as gr
from transformers import pipeline
nlp_qa = pipeline(
'question-answering',
model='mrm8488/bert-italian-finedtuned-squadv1-it-alfa',
tokenizer='mrm8488/bert-italian-finedtuned-squadv1-it-alfa'
)
def start(question, context):
response = nlp_qa({
'question': question,
'context': context
})
text_hilight_output = [
(context[:response['start']], None),
(context[response['start']:response['end']], 'Answer'),
(context[response['end']:], None)
]
return text_hilight_output, response['answer'], {response['answer']: response['score']}
face = gr.Interface(
fn=start,
inputs=[
gr.inputs.Textbox(lines=1, placeholder="Question Here… "),
gr.inputs.Textbox(lines=10, placeholder="Context Here… ")
],
outputs=[
gr.outputs.HighlightedText(label='Context'),
gr.outputs.Textbox(label="Answer"),
gr.outputs.Label(num_top_classes=1, label='Score'),
]
)
face.launch()