File size: 1,840 Bytes
4d40495
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b8b622c
131353d
81628dc
 
 
131353d
 
 
4d40495
 
 
 
 
131353d
 
 
 
b8b622c
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
import gradio as gr
from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline

sonnets_pretrained_model = "datificate/gpt2-small-spanish"
sonnets_tokenizer = AutoTokenizer.from_pretrained(sonnets_pretrained_model, use_fast=True)
sonnets_tuned_model = 'hackathon-pln-es/gpt2-small-spanish-disco-poetry'
sonnets_pipe = pipeline('text2text-generation', model=sonnets_tuned_model, tokenizer=sonnets_tokenizer)

def make_new_sonnet(prompt, max_lenght):
    ouputs = sonnets_pipe(prompt, max_length=max_lenght, 
                  num_beams=5, 
                  early_stopping=True, 
                  repetition_penalty=20.0, 
                  num_return_sequences=1)
    return ouputs[0]['generated_text']

article = "<p style='text-align: center'>Don't miss this other cool space based in a model of different styles of poetry in spanish: <a href='https://huggingface.co/spaces/hackathon-pln-es/poem-generation-es' target='_blank'>poem-generation-es</a></p>"
examples = [
    ['vendrá la muerte y tendrá tus ojos',140],
    ['buenas cosas pasan cuando anochece', 200],
    ['al despertar el dinosaurio todavía estaba ahí', 140 ]
]
iface = gr.Interface(fn=make_new_sonnet,
                      title= "Generador de poesía basada en sonetos en español",
                      inputs=[
                              gr.inputs.Textbox(lines=2, placeholder="Escrbe algo para comenzar", label='Escribe algo para comenzar'),
                              gr.inputs.Slider(minimum = 60, maximum = 200, default = 140, step = 10, label='Salida de caracteres')],
                      outputs=[
                               gr.outputs.Textbox(label="Tu poema"),
                              ],
                      article= article,
                      examples = examples
                     )
iface.launch(enable_queue=True)