opus-mt-en-de / app.py
Manu101's picture
Update app.py
036c15a verified
raw
history blame contribute delete
493 Bytes
from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
import gradio as gd
mdl_name = "Helsinki-NLP/opus-mt-en-de"
tk = AutoTokenizer.from_pretrained(mdl_name)
model = AutoModelForSeq2SeqLM.from_pretrained(mdl_name)
def translate(text):
encodings = tk(text, return_tensors="pt")
outputs = model.generate(**encodings)
response = tk.decode(outputs[0], skip_special_tokens=True)
return response
gd.Interface(translate, inputs=["text",], outputs="text").launch()