Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import AutoModelForSeqLM, AutoTokenizer
|
2 |
+
|
3 |
+
import gradio as gd
|
4 |
+
|
5 |
+
mdl_name = "Helsinki-NLP/opus-mt-en-de"
|
6 |
+
|
7 |
+
tk = AutoTokenizer.from_pretrained(mdl_name)
|
8 |
+
model = AutoModelForSeqLM.from_pretrained(mdl_name)
|
9 |
+
|
10 |
+
def translate(text):
|
11 |
+
encodings = tk(text, return_tensors="pt")
|
12 |
+
outputs = model.generate(**encodings)
|
13 |
+
|
14 |
+
response = tk.decode(outputs[0], skip_special_tokens=True)
|
15 |
+
|
16 |
+
return response
|
17 |
+
|
18 |
+
gd.Interface(translate, inputs=["text",], outputs="text").launch()
|
19 |
+
|