Upload app.py
Browse files
app.py
ADDED
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import random
|
3 |
+
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
|
4 |
+
|
5 |
+
model_name = 'MR1B4RR4/Spanish_lyrics_model'
|
6 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
7 |
+
model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
|
8 |
+
|
9 |
+
def poema(text, num_lines):
|
10 |
+
num_lines=num_lines
|
11 |
+
poem = text
|
12 |
+
prev_output = ''
|
13 |
+
|
14 |
+
for i in range(num_lines):
|
15 |
+
|
16 |
+
input_text = f"""{poem}"""
|
17 |
+
inputs = tokenizer(input_text, return_tensors="pt")
|
18 |
+
|
19 |
+
outputs = model.generate(inputs["input_ids"],
|
20 |
+
do_sample = True,
|
21 |
+
max_length = 30,
|
22 |
+
repetition_penalty = 20.0,
|
23 |
+
top_k = 50,
|
24 |
+
top_p = 0.92)
|
25 |
+
detok_outputs = [tokenizer.decode(x, skip_special_tokens=True) for x in outputs]
|
26 |
+
pre_output = detok_outputs[0]
|
27 |
+
|
28 |
+
poem += '\n' + pre_output
|
29 |
+
return poem
|
30 |
+
|
31 |
+
|
32 |
+
iface = gr.Interface(
|
33 |
+
fn=poema,
|
34 |
+
title='Generation of Spanish poems',
|
35 |
+
description="""
|
36 |
+
|
37 |
+
Descripcion........
|
38 |
+
""",
|
39 |
+
theme='huggingface',
|
40 |
+
inputs=
|
41 |
+
[
|
42 |
+
gr.inputs.Textbox(lines=4, placeholder='texto inicial', label='Texto inicial'),
|
43 |
+
gr.inputs.Textbox(lines=4, placeholder='Numero de lineas', label='Numero de lineas')
|
44 |
+
],
|
45 |
+
outputs=
|
46 |
+
[
|
47 |
+
gr.outputs.Textbox(label="Texto generado"),
|
48 |
+
# gr.outputs.Audio(label="Primeros segundos")
|
49 |
+
])
|
50 |
+
iface.launch(enable_queue=True)
|