Jaehan commited on
Commit
0fdff2d
·
1 Parent(s): 02a3c7a

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -0
app.py ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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()