File size: 1,863 Bytes
7c96d4d 18dbafb 7c96d4d 1ae55fd e6e654d 48dce21 e6e654d 1ae55fd 18dbafb b6287db 4366f76 18dbafb 83cefeb 956e550 2ae896a 956e550 2c5321c 26b6523 f2ea4cf 74484cc 1271ce0 f2ea4cf 1271ce0 cf05f54 74b256d cf05f54 1271ce0 1ae55fd 792cfa4 3c0fbbd df5be20 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
import gradio as gr
from transformers import AutoModelForSeq2SeqLM
from transformers import AutoTokenizer
article='''
# Team members
- Emilio Alejandro Morales [(milmor)](https://huggingface.co/milmor)
- Rodrigo Martínez Arzate [(rockdrigoma)](https://huggingface.co/rockdrigoma)
- Luis Armando Mercado [(luisarmando)](https://huggingface.co/luisarmando)
- Jacobo del Valle [(jjdv)](https://huggingface.co/jjdv)
'''
model = AutoModelForSeq2SeqLM.from_pretrained('hackathon-pln-es/t5-small-spanish-nahuatl')
tokenizer = AutoTokenizer.from_pretrained('hackathon-pln-es/t5-small-spanish-nahuatl')
def predict(input):
input_ids = tokenizer('translate Spanish to Nahuatl: ' + input, return_tensors='pt').input_ids
outputs = model.generate(input_ids, max_length=512)
outputs = tokenizer.batch_decode(outputs, skip_special_tokens=True)[0]
return outputs
gr.Interface(
fn=predict,
inputs=gr.inputs.Textbox(lines=2, label="Input Text in Spanish"),
outputs=[
gr.outputs.Textbox(label="Translated text in Nahuatl"),
],
theme="peach",
title='🌽 Spanish to Nahuatl Automatic Translation',
description='This model is a T5 Transformer (t5-small) fine-tuned on spanish and nahuatl sentences collected from the web. The dataset is normalized using "sep" normalization from py-elotl. For more details visit https://huggingface.co/hackathon-pln-es/t5-small-spanish-nahuatl',
examples=[
'conejo',
'estrella',
'Muchos perros son blancos',
'te amo',
'quiero comer',
'esto se llama agua',
'Mi hermano es un ajolote',
'mi abuelo se llama Juan',
'El pueblo del ajolote',
'te amo con todo mi corazón'],
article=article,
allow_flagging="manual",
flagging_options=["right translation", "wrong translation", "error", "other"],
flagging_dir="logs"
).launch(enable_queue=True)
|