File size: 558 Bytes
ab3c637 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
import gradio as gr
from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
def translate(text):
model_name = 'hackathon-pln-es/t5-small-finetuned-spanish-to-quechua'
model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
tokenizer = AutoTokenizer.from_pretrained(model_name)
input = tokenizer(text, return_tensors="pt")
output = model.generate(input["input_ids"], max_length=40, num_beams=4, early_stopping=True)
return tokenizer.decode(output[0])
iface = gr.Interface(fn=translate, inputs="text", outputs="text")
iface.launch() |