File size: 493 Bytes
82ce5ac
ac6a371
 
 
 
 
036c15a
ac6a371
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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()