Jaehan commited on
Commit
247182b
1 Parent(s): 0fdff2d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -12
app.py CHANGED
@@ -1,19 +1,18 @@
1
- from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
2
  import gradio as grad
3
 
4
- model_name = "Helsinki-NLP/opus-mt-ko-en"
5
- model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
6
- tokenizer = AutoTokenizer.from_pretrained(model_name)
7
 
8
- #opus_translator = pipeline("translation", model=model_name)
9
 
10
  def translate(text):
11
- inputs = tokenizer(text, return_tensors="pt")
12
- translation_output = model.generate(**input)
13
- response = tokenizer.decode(translation_output[0], skip_special_tokens=True)
14
 
15
- #response = opus_translator(text)
16
- return response
17
 
18
- # Web UI
19
- grad.Interface(translate, inputs=["text"], outputs=["text"]).launch()
 
1
+ from transformers import AutoModelForSeq2SeqLM,AutoTokenizer
2
  import gradio as grad
3
 
4
+ mdl_name = "Helsinki-NLP/opus-mt-ko-en"
5
+ mdl = AutoModelForSeq2SeqLM.from_pretrained(mdl_name)
6
+ my_tkn = AutoTokenizer.from_pretrained(mdl_name)
7
 
8
+ #opus_translator = pipeline("translation", model=mdl_name)
9
 
10
  def translate(text):
11
+ inputs = my_tkn(text, return_tensors="pt")
12
+ trans_output = mdl.generate(**inputs)
13
+ response = my_tkn.decode(trans_output[0], skip_special_tokens=True)
14
 
15
+ #response = opus_translator(text)
16
+ return response
17
 
18
+ grad.Interface(translate, inputs=["text",], outputs="text").launch()