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