File size: 693 Bytes
706b60e
cdaa05d
706b60e
525cbef
706b60e
f9cdac1
37c9c33
706b60e
 
 
 
 
543197a
706b60e
 
 
c8552a5
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import gradio as grad
from transformers import AutoModelForSeq2SeqLM, AutoTokenizer

model_name = "Helsinki-NLP/opus-mt-en-grk"

model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
model_tkn = AutoTokenizer.from_pretrained(model_name)

#opus_translation = pipeline("translation", model=model_name)

def translate(text):
    inputs = model_tkn(text, return_tensors="pt")
    trans_output = 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", outputs="text").launch()