Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -2,6 +2,7 @@ from dotenv import load_dotenv
|
|
2 |
import streamlit as st
|
3 |
import os
|
4 |
import google.generativeai as genai
|
|
|
5 |
|
6 |
# Cargar variables de entorno
|
7 |
load_dotenv()
|
@@ -10,67 +11,30 @@ load_dotenv()
|
|
10 |
genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
|
11 |
|
12 |
# Función para obtener la respuesta del modelo Gemini
|
13 |
-
def get_gemini_response(input_prompt,
|
14 |
if not input_prompt:
|
15 |
return "Por favor, escribe un mensaje para generar contenido."
|
16 |
|
|
|
|
|
17 |
model = genai.GenerativeModel('gemini-2.0-flash')
|
18 |
full_prompt = f"""
|
19 |
-
You are a creative storyteller. Write a {mood}
|
20 |
Use exactly {length} words.
|
21 |
|
22 |
Target Audience: {target_audience}
|
23 |
Call to Action: {cta_type}
|
|
|
24 |
|
25 |
-
|
26 |
-
Then, write a story that naturally leads to this benefit.
|
27 |
-
|
28 |
-
Structure:
|
29 |
-
1. Introduce a relatable problem that captures the audience's attention
|
30 |
-
2. Develop the story with natural narrative and emotional connection
|
31 |
-
3. Show consequences of inaction
|
32 |
-
4. Present the solution organically
|
33 |
-
5. Close with a natural invitation to {cta_type} that shows how it will transform their situation
|
34 |
-
- For product purchase: Show how buying transforms their situation
|
35 |
-
- For PDF guide: Highlight how the guide provides the knowledge they need
|
36 |
-
- For webinar: Emphasize how the live training will help them succeed
|
37 |
|
38 |
Keep in mind:
|
39 |
- Write for {target_audience}
|
40 |
-
- Use simple, clear language
|
41 |
-
- Avoid technical terms or complex words
|
42 |
- Tell the story in short paragraphs
|
43 |
- End with a natural {cta_type} invitation
|
44 |
-
|
45 |
-
Example format:
|
46 |
-
Make the CTA feel natural and focus on the transformation they'll experience.
|
47 |
-
|
48 |
-
### **Ejemplo de historia bien escrita:**
|
49 |
-
En una lejana galaxia, el maestro Xylo dictaba clases en la Tierra.
|
50 |
-
|
51 |
-
Sus métodos eran monótonos, y sus alumnos bostezaban sin parar.
|
52 |
-
|
53 |
-
“¿Por qué no prestan atención?”, se preguntaba.
|
54 |
-
|
55 |
-
Frustrado, investigó y descubrió que el problema no eran los niños, sino sus clases aburridas.
|
56 |
-
|
57 |
-
Por eso decidió cambiar.
|
58 |
-
|
59 |
-
Tomó un curso online para hacer sus lecciones dinámicas y sorprendentes.
|
60 |
-
|
61 |
-
Pronto, sus alumnos rieron, participaron y aprendieron con entusiasmo.
|
62 |
-
|
63 |
-
Si Xylo pudo transformar sus clases, tú también.
|
64 |
-
|
65 |
-
Inscríbete hoy aquí.
|
66 |
-
|
67 |
-
**Importante:**
|
68 |
-
- **Haz que la historia sea humana y emocional**, evitando frases promocionales evidentes.
|
69 |
-
- Format the output in clear, separate paragraphs with line breaks
|
70 |
-
- Only write {genre}, anything else.
|
71 |
"""
|
72 |
response = model.generate_content([full_prompt])
|
73 |
-
|
74 |
return response.parts[0].text if response and response.parts else "Error al generar contenido."
|
75 |
|
76 |
# Configurar la aplicación Streamlit
|
@@ -90,16 +54,17 @@ col1, col2 = st.columns([1, 1])
|
|
90 |
with col1:
|
91 |
# Entrada de texto principal
|
92 |
input_prompt = st.text_area("Escribe de qué quieres que trate la historia:", placeholder="Escribe aquí tu idea...")
|
|
|
|
|
93 |
|
94 |
-
# Campos de texto libre
|
95 |
-
target_audience = st.text_input("Público Objetivo:", placeholder="Ejemplo: Profesionales de 25-35 años interesados en tecnología...")
|
96 |
-
|
97 |
-
# CTA como campo de texto libre
|
98 |
-
cta_type = st.text_input("Llamado a la acción:", placeholder="Ejemplo: Curso de marketing digital, Guía para emprendedores, Webinar gratuito...")
|
99 |
-
|
100 |
-
# Opciones avanzadas en acordeón
|
101 |
with st.expander("Opciones avanzadas"):
|
102 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
103 |
length = st.slider("Longitud del texto (palabras):",
|
104 |
min_value=100,
|
105 |
max_value=150,
|
|
|
2 |
import streamlit as st
|
3 |
import os
|
4 |
import google.generativeai as genai
|
5 |
+
from story_formulas import story_formulas
|
6 |
|
7 |
# Cargar variables de entorno
|
8 |
load_dotenv()
|
|
|
11 |
genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
|
12 |
|
13 |
# Función para obtener la respuesta del modelo Gemini
|
14 |
+
def get_gemini_response(input_prompt, formula_type, length, mood, target_audience, cta_type):
|
15 |
if not input_prompt:
|
16 |
return "Por favor, escribe un mensaje para generar contenido."
|
17 |
|
18 |
+
formula = story_formulas[formula_type]
|
19 |
+
|
20 |
model = genai.GenerativeModel('gemini-2.0-flash')
|
21 |
full_prompt = f"""
|
22 |
+
You are a creative storyteller. Write a {mood} story in Spanish about "{input_prompt}" using everyday words and natural conversation.
|
23 |
Use exactly {length} words.
|
24 |
|
25 |
Target Audience: {target_audience}
|
26 |
Call to Action: {cta_type}
|
27 |
+
Story Formula: {formula_type}
|
28 |
|
29 |
+
{formula["description"]}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
30 |
|
31 |
Keep in mind:
|
32 |
- Write for {target_audience}
|
33 |
+
- Use simple, clear language
|
|
|
34 |
- Tell the story in short paragraphs
|
35 |
- End with a natural {cta_type} invitation
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
36 |
"""
|
37 |
response = model.generate_content([full_prompt])
|
|
|
38 |
return response.parts[0].text if response and response.parts else "Error al generar contenido."
|
39 |
|
40 |
# Configurar la aplicación Streamlit
|
|
|
54 |
with col1:
|
55 |
# Entrada de texto principal
|
56 |
input_prompt = st.text_area("Escribe de qué quieres que trate la historia:", placeholder="Escribe aquí tu idea...")
|
57 |
+
target_audience = st.text_input("Público Objetivo:", placeholder="Ejemplo: Profesionales de 25-35 años...")
|
58 |
+
cta_type = st.text_input("Llamado a la acción:", placeholder="Ejemplo: Curso de marketing digital...")
|
59 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
60 |
with st.expander("Opciones avanzadas"):
|
61 |
+
formula_type = st.selectbox(
|
62 |
+
"Fórmula narrativa:",
|
63 |
+
options=list(story_formulas.keys()),
|
64 |
+
format_func=lambda x: x
|
65 |
+
)
|
66 |
+
st.info(story_formulas[formula_type]["description"])
|
67 |
+
|
68 |
length = st.slider("Longitud del texto (palabras):",
|
69 |
min_value=100,
|
70 |
max_value=150,
|