Spaces:
Paused
Paused
import gradio as gr | |
from transformers import pipeline | |
from transformers import pipeline,AutoTokenizer | |
from optimum.intel import OVModelForQuestionAnswering | |
model_checkpoint = "letrunglinh/qa_pnc" | |
global model_convert,tokenizer | |
tokenizer = AutoTokenizer.from_pretrained(model_checkpoint) | |
model_convert = OVModelForQuestionAnswering.from_pretrained(model_checkpoint,export=True, compile=False) | |
model_convert.half() | |
model_convert.compile() | |
def question_answer(context, question): | |
model = pipeline('question-answering', model=model_convert, | |
tokenizer=tokenizer) | |
to_predict = [ | |
{ | |
"question": question, | |
"context": context, | |
} | |
] | |
answers = model(to_predict) | |
return answers['answer'], answers['score'] | |
gr.Interface(fn=question_answer, inputs=["text", "text"], outputs=["textbox","textbox"], theme = "grass", share = True).launch() |