modernisa / app.py
versae's picture
Update app.py
9328f46
raw
history blame
1.08 kB
import gradio as gr
from transformers import AutoTokenizer, pipeline, T5ForConditionalGeneration
model_name = "versae/modernisa-pre"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = T5ForConditionalGeneration.from_pretrained(model_name)
def modernisa(inputs):
lines = [line for line in inputs.strip().split('\n') if line.strip()]
text2text_generator = pipeline("text2text-generation", model=model, tokenizer=tokenizer)
outputs = text2text_generator(lines, max_length=150)
return "\n".join(output["generated_text"] for output in outputs)
sample = """Otra vez, Don Iuan, me dad,
y otras mil vezes los braços.
Otra, y otras mil sean lazos
de nuestra antigua amistad.
Como venis?
Yo me siento
tan alegre, tan vfano,
tan venturoso, tan vano,
que no podrà el pensamiento
encareceros jamàs
las venturas que posseo,
porque el pensamiento creo"""
gr.Interface(
fn=modernisa,
inputs=gr.inputs.Textbox(lines=12, label="Enter Old Spanish", default=sample),
outputs=gr.outputs.Textbox(lines=12, label="Modern Spanish"),
).launch(inline=False)