Spaces:
Sleeping
Sleeping
File size: 656 Bytes
706b60e cdaa05d 706b60e |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
import gradio as grad
from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
model_name = "Helsini-NLP/opus-mt-en-de"
model = AutoModelForSeq2SeqLM(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
grad.Interface(translate, inputs="text", output="text").launch() |