eloi-goncalves commited on
Commit
6fc805b
·
1 Parent(s): 98e1cb0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -2
app.py CHANGED
@@ -1,10 +1,15 @@
1
- from transformers import AutoModelForQuestionAnswering, AutoTokenizer, pipeline
2
  import gradio as grad
3
  import ast
4
 
5
  mdl_name = "deepset/roberta-base-squad2"
6
  my_pipeline = pipeline('question-answering', model=mdl_name, tokenizer=mdl_name)
7
 
 
 
 
 
 
8
  def answer_question(question,context):
9
  text= "{"+"'question': '"+question+"','context': '"+context+"'}"
10
  di=ast.literal_eval(text)
@@ -12,4 +17,13 @@ def answer_question(question,context):
12
  print('response', response)
13
  return response
14
 
15
- grad.Interface(answer_question, inputs=["text","text"], outputs="text").launch()
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import AutoModelForQuestionAnswering, AutoModelForSeq2SeqLM, AutoTokenizer, pipeline
2
  import gradio as grad
3
  import ast
4
 
5
  mdl_name = "deepset/roberta-base-squad2"
6
  my_pipeline = pipeline('question-answering', model=mdl_name, tokenizer=mdl_name)
7
 
8
+ model_translate_name = 'danhsf/m2m100_418M-finetuned-kde4-en-to-pt_BR'
9
+ model_translate = AutoModelForSeq2SeqLM.from_pretrained(model_translate_name)
10
+ model_translate_token = AutoTokenizer.from_pretrained(model_translate_name)
11
+ translate_pipeline = ('translation', model=model_translate_name)
12
+
13
  def answer_question(question,context):
14
  text= "{"+"'question': '"+question+"','context': '"+context+"'}"
15
  di=ast.literal_eval(text)
 
17
  print('response', response)
18
  return response
19
 
20
+
21
+ def translate(text):
22
+ inputs = model_translate_token(text, return_tensor='pt')
23
+ translate_output = model_translate.generate(**inputs)
24
+ response = model_translate_token(translate_output[0], skip_special_tokens=True)
25
+ #response = translate_pipeline(text)
26
+ return response
27
+
28
+ #grad.Interface(answer_question, inputs=["text","text"], outputs="text").launch()
29
+ grad.Interface(translate, inputs=['text',], outputs='text').launch()