run480 commited on
Commit
e714e4a
1 Parent(s): a0d3657

Update app.py

Browse files

Next task is language translation.

Files changed (1) hide show
  1. app.py +18 -7
app.py CHANGED
@@ -8,13 +8,24 @@ import ast
8
  # my_pipeline = pipeline('question-answering', model=mdl_name, tokenizer=mdl_name)
9
 
10
  # 2. Different model.
11
- mdl_name = "distilbert-base-cased-distilled-squad"
12
- my_pipeline = pipeline('question-answering', model=mdl_name, tokenizer=mdl_name)
 
 
 
 
 
 
 
 
 
 
 
 
 
13
 
14
- def answer_question(question,context):
15
- text= "{"+"'question': '"+question+"','context': '"+context+"'}"
16
- di=ast.literal_eval(text)
17
- response = my_pipeline(di)
18
  return response
19
 
20
- grad.Interface(answer_question, inputs=["text","text"], outputs="text").launch()
 
8
  # my_pipeline = pipeline('question-answering', model=mdl_name, tokenizer=mdl_name)
9
 
10
  # 2. Different model.
11
+ # mdl_name = "distilbert-base-cased-distilled-squad"
12
+ # my_pipeline = pipeline('question-answering', model=mdl_name, tokenizer=mdl_name)
13
+
14
+ # def answer_question(question,context):
15
+ # text= "{"+"'question': '"+question+"','context': '"+context+"'}"
16
+ # di=ast.literal_eval(text)
17
+ # response = my_pipeline(di)
18
+ # return response
19
+
20
+ # grad.Interface(answer_question, inputs=["text","text"], outputs="text").launch()
21
+
22
+ # 3. Different task: language translation.
23
+ # First model translates English to German.
24
+ mdl_name = "Helsinki-NLP/opus-mt-en-de"
25
+ opus_translator = pipeline("translation", model=mdl_name)
26
 
27
+ def translate(text):
28
+ response = opus_translator(text)
 
 
29
  return response
30
 
31
+ grad.Interface(translate, inputs=["text",], outputs="text").launch()