Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
|
| 2 |
+
import gradio as grad
|
| 3 |
+
|
| 4 |
+
mdl_name = "Helsinki-NLP/opus-mt-en-de"
|
| 5 |
+
|
| 6 |
+
mdl = AutoModelForSeq2SeqLM.from_pretrained(mdl_name)
|
| 7 |
+
|
| 8 |
+
my_tkn = AutoTokenizer.from_pretrained(mdl_name)
|
| 9 |
+
|
| 10 |
+
#opus_translator = pipeline("translation", model=mdl_name)
|
| 11 |
+
|
| 12 |
+
def translate(text):
|
| 13 |
+
|
| 14 |
+
inputs = my_tkn(text,
|
| 15 |
+
return_tensors="pt")
|
| 16 |
+
|
| 17 |
+
trans_output = mdl.generate(**inputs)
|
| 18 |
+
|
| 19 |
+
response = my_tkn.decode(trans_output[0],
|
| 20 |
+
skip_special_tokens = True)
|
| 21 |
+
|
| 22 |
+
#response = opus_translator(text)
|
| 23 |
+
return response
|
| 24 |
+
|
| 25 |
+
grad.Interface(translate,
|
| 26 |
+
inputs=["text",],
|
| 27 |
+
outputs="text").launch()
|