Spaces:
Runtime error
Runtime error
Create app.py
Browse files
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()
|