Spaces:
Sleeping
Sleeping
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() | |