Spaces:
Runtime error
Runtime error
jorge-henao
commited on
Commit
•
39a5f31
1
Parent(s):
1299806
Create new file
Browse files
app.py
ADDED
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline
|
3 |
+
|
4 |
+
pretrained_model = "datificate/gpt2-small-spanish"
|
5 |
+
tokenizer = AutoTokenizer.from_pretrained(pretrained_model, use_fast=True)
|
6 |
+
tuned_model = 'jorge-henao/gpt2-small-spanish-historias-conflicto-col'
|
7 |
+
sonnets_pipe = pipeline('text2text-generation', model=tuned_model, tokenizer=tokenizer)
|
8 |
+
|
9 |
+
def make_new_story(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 |
+
description = """
|
19 |
+
<p>
|
20 |
+
<br></br>
|
21 |
+
<br>Este espacio hace parte de un proyecto open source que busca ayudar con el entendimiento de temas relevantes para el país, como estas elecciones y la memoria histórica Colombiana. <a href= "https://github.com/jorge-henao/ask_to_democracy">repo en github con FastAPI</a></br>
|
22 |
+
Por: Jorge Henao 🇨🇴 <a href="https://twitter.com/jhenaotw" target='_blank'>Twitter</a> <a href="https://www.linkedin.com/in/henaojorge" target='_blank'/>LinkedIn</a>
|
23 |
+
</p>
|
24 |
+
"""
|
25 |
+
|
26 |
+
examples = [
|
27 |
+
['cuando salí no había nadie', 20 ],
|
28 |
+
['La última vez que la vi', 140],
|
29 |
+
['LLegaron y mi vida se fue', 140]
|
30 |
+
]
|
31 |
+
|
32 |
+
iface = gr.Interface(fn=make_new_story,
|
33 |
+
title= "Generador de historias basadas en el conflicto Colombiano",
|
34 |
+
description = description,
|
35 |
+
inputs=[
|
36 |
+
gr.inputs.Textbox(lines=2, placeholder="Escrbe algo para comenzar", label='Escribe algo para comenzar'),
|
37 |
+
gr.inputs.Slider(minimum = 20, maximum = 200, default = 140, step = 5, label='Salida máxima de caracteres')],
|
38 |
+
outputs=[
|
39 |
+
gr.outputs.Textbox(label="Tu poema"),
|
40 |
+
],
|
41 |
+
examples = examples,
|
42 |
+
theme = 'peach'
|
43 |
+
)
|
44 |
+
iface.launch(enable_queue=True)
|