George Tsang commited on
Commit
5918aab
·
1 Parent(s): ddaafa1

change to translator

Browse files
Files changed (1) hide show
  1. app.py +7 -13
app.py CHANGED
@@ -1,14 +1,8 @@
1
- from transformers import AutoModelForQuestionAnswering, AutoTokenizer, pipeline
2
  import gradio as grad
3
- import ast
4
-
5
- mdl_name = "distilbert-base-cased-distilled-squad"
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)
11
- response = my_pipeline(di)
12
- return response
13
-
14
- grad.Interface(answer_question, inputs=["text","text"], outputs="text").launch()
 
1
+ from transformers import pipeline
2
  import gradio as grad
3
+ mdl_name = "Helsinki-NLP/opus-mt-en-de"
4
+ opus_translator = pipeline("translation", model=mdl_name)
5
+ def translate(text):
6
+ response = opus_translator(text)
7
+ return response
8
+ grad.Interface(translate, inputs=["text",], outputs="text").launch()