Spaces:
Sleeping
Sleeping
File size: 848 Bytes
706b60e cdaa05d 706b60e f0124b9 706b60e 5af2d7d 706b60e f0124b9 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
import gradio as grad
from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
model_name = "Helsinki-NLP/opus-mt-en-de"
model = AutoModelForSeq2SeqLM_from_pretrained(model_name)
model_tkn = AutoTokenizer(model_name)
#opus_translation = pipeline("translation", model=model_name)
def translate(text):
inputs = model_tkn(text, return_tensors="pt")
trans_ouput = model.generate(**inputs) #"generate": This method includes the logic for autoregressive generation
response = model_tkn.decode(trans_output[0], skip_special_tokens=True)
#response = opus_translator(text)
return response
txt = grad.Textbox(line=1, label="English", placeholder = "English text here")
txt_out = grad.Textbox(line=1, label= "German", placeholder = "German translation")
grad.Interface(translate, inputs=txt, output=txt_out, theme="dark").launch() |