letrunglinh commited on
Commit
2e85200
1 Parent(s): 08439a8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -9
app.py CHANGED
@@ -1,15 +1,20 @@
1
  import gradio as gr
 
2
  from transformers import AutoModelForQuestionAnswering, pipeline,AutoTokenizer
3
- import torch
4
- from optimum.onnxruntime import ORTModelForQuestionAnswering
 
 
 
 
 
 
5
  def question_answer(context, question):
6
- AUTH_TOKEN = "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"
7
- model_checkpoint = "letrunglinh/qa_pnc"
8
- device = "cuda" if torch.cuda.is_available() else "cpu"
9
- tokenizer = AutoTokenizer.from_pretrained(model_checkpoint, use_auth_token=AUTH_TOKEN)
10
- model = ORTModelForQuestionAnswering.from_pretrained(model_checkpoint, from_transformers=True)
11
- model = pipeline('question-answering', model=model,
12
- tokenizer=tokenizer, use_auth_token=AUTH_TOKEN)
13
  to_predict = [
14
  {
15
  "question": question,
 
1
  import gradio as gr
2
+ from transformers import pipeline
3
  from transformers import AutoModelForQuestionAnswering, pipeline,AutoTokenizer
4
+ from optimum.intel import OVModelForQuestionAnswering
5
+ model_checkpoint = "letrunglinh/qa_pnc"
6
+ global model_convert,tokenizer
7
+ tokenizer = AutoTokenizer.from_pretrained(model_checkpoint)
8
+ model_convert = OVModelForQuestionAnswering.from_pretrained(model_checkpoint,export=True)
9
+ model_convert.half()
10
+ model_convert.compile()
11
+
12
  def question_answer(context, question):
13
+
14
+ model = pipeline('question-answering', model=model_convert,
15
+ tokenizer=tokenizer)
16
+
17
+
 
 
18
  to_predict = [
19
  {
20
  "question": question,