jorge-henao commited on
Commit
4d40495
1 Parent(s): 7b650bc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -0
app.py CHANGED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline
3
+
4
+ sonnets_pretrained_model = "datificate/gpt2-small-spanish"
5
+ sonnets_tokenizer = AutoTokenizer.from_pretrained(sonnets_pretrained_model, use_fast=True)
6
+ sonnets_tuned_model = 'hackathon-pln-es/gpt2-small-spanish-disco-poetry'
7
+ sonnets_pipe = pipeline('text2text-generation', model=sonnets_tuned_model, tokenizer=sonnets_tokenizer)
8
+
9
+ def make_new_sonnet(prompt, max_lenght):
10
+ ouputs = sonnets_pipe(prompt, max_length=max_lenght,
11
+ num_beams=5,
12
+ early_stopping=True,
13
+ repetition_penalty=20.0,
14
+ num_return_sequences=1)
15
+ return ouputs[0]['generated_text']
16
+
17
+
18
+ iface = gr.Interface(fn=make_new_sonnet,
19
+ inputs=[
20
+ gr.inputs.Textbox(lines=2, placeholder="Escrbe algo para comenzar", label='Escribe algo para comenzar'),
21
+ gr.inputs.Slider(minimum = 60, maximum = 200, default = 140, step = 10, label='Salida de caracteres')],
22
+ outputs=[
23
+ gr.outputs.Textbox(label="Tu poema"),
24
+ ])
25
+ iface.launch(enable_queue=True)