Update app.py
Browse files
app.py
CHANGED
@@ -2,538 +2,310 @@ from dotenv import load_dotenv
|
|
2 |
import streamlit as st
|
3 |
import os
|
4 |
import google.generativeai as genai
|
5 |
-
import
|
6 |
-
import
|
7 |
-
from
|
8 |
-
|
9 |
-
|
10 |
-
from
|
11 |
-
|
12 |
-
|
|
|
13 |
load_dotenv()
|
14 |
|
15 |
-
# Configurar
|
16 |
genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
|
17 |
|
18 |
-
#
|
19 |
-
|
20 |
-
|
21 |
-
|
|
|
|
|
22 |
|
23 |
-
|
24 |
-
|
25 |
-
download_label = "DESCARGAR GUION DE MI WEBINAR ▶▶"
|
26 |
-
file_name = f"guion_webinar_{timestamp}.md"
|
27 |
-
subheader_text = "Tu guión de webinar:"
|
28 |
-
# Mostrar botón de descarga superior para guiones
|
29 |
-
col.download_button(
|
30 |
-
label=download_label,
|
31 |
-
data=generated_content,
|
32 |
-
file_name=file_name,
|
33 |
-
mime="text/markdown",
|
34 |
-
key=f"download_top_{content_type}"
|
35 |
-
)
|
36 |
-
else: # nombres
|
37 |
-
subheader_text = "Tus nombres de webinar:"
|
38 |
|
39 |
-
#
|
40 |
-
|
41 |
-
|
|
|
|
|
|
|
|
|
|
|
42 |
|
43 |
-
#
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
data=generated_content,
|
48 |
-
file_name=file_name,
|
49 |
-
mime="text/markdown",
|
50 |
-
key=f"download_bottom_{content_type}"
|
51 |
-
)
|
52 |
-
|
53 |
-
# Implementar la función generate_and_display para reemplazar código duplicado
|
54 |
-
def generate_and_display(col, generator_func, audience, product, temperature, selected_formula, content_type, **kwargs):
|
55 |
-
if validate_inputs(audience, product):
|
56 |
-
try:
|
57 |
-
with col:
|
58 |
-
with st.spinner(f"Generando {'guión' if content_type == 'script' else 'nombres'} de webinar...", show_time=True):
|
59 |
-
# Llamar a la función generadora con los parámetros adecuados
|
60 |
-
generated_content = generator_func(
|
61 |
-
audience=audience,
|
62 |
-
topic=product,
|
63 |
-
temperature=temperature,
|
64 |
-
selected_formula=selected_formula,
|
65 |
-
**kwargs
|
66 |
-
)
|
67 |
-
|
68 |
-
# Mostrar el contenido generado usando la función auxiliar
|
69 |
-
display_generated_content(col, generated_content, content_type)
|
70 |
-
|
71 |
-
except ValueError as e:
|
72 |
-
col.error(f"Error: {str(e)}")
|
73 |
-
else:
|
74 |
-
col.error("Por favor, proporciona el público objetivo y el tema del webinar.")
|
75 |
-
|
76 |
-
# Función para crear la configuración del modelo (evita duplicación)
|
77 |
-
def create_model_config(temperature):
|
78 |
-
return {
|
79 |
-
"temperature": temperature,
|
80 |
-
"top_p": 0.65,
|
81 |
-
"top_k": 360,
|
82 |
-
"max_output_tokens": 8196,
|
83 |
-
}
|
84 |
-
|
85 |
-
# Función para inicializar el modelo
|
86 |
-
def initialize_model(temperature):
|
87 |
-
config = create_model_config(temperature)
|
88 |
-
return genai.GenerativeModel(
|
89 |
-
model_name="gemini-2.0-flash",
|
90 |
-
generation_config=config,
|
91 |
-
)
|
92 |
-
|
93 |
-
# Refactored model interaction function to reduce duplication
|
94 |
-
def generate_content(prompt_instructions, temperature):
|
95 |
-
model = initialize_model(temperature)
|
96 |
-
chat_session = model.start_chat(
|
97 |
-
history=[
|
98 |
-
{
|
99 |
-
"role": "user",
|
100 |
-
"parts": [prompt_instructions],
|
101 |
-
},
|
102 |
-
]
|
103 |
-
)
|
104 |
-
response = chat_session.send_message("Generate the content following exactly the provided instructions. All content must be in Spanish.")
|
105 |
-
return response.text
|
106 |
-
|
107 |
-
# Función para generar nombres de webinars
|
108 |
-
# Refactorizar la función generate_webinar_names para que acepte los mismos parámetros que generate_webinar_script
|
109 |
-
def generate_webinar_names(audience, topic, temperature, selected_formula, number_of_names=5, selected_angle=None, **kwargs):
|
110 |
-
# Incluir las instrucciones del sistema en el prompt principal
|
111 |
-
system_prompt = """You are a world-class copywriter, with expertise in crafting compelling webinar titles that immediately capture the audience's attention and drive registrations.
|
112 |
-
|
113 |
-
FORMAT RULES:
|
114 |
-
- Each webinar name must start with number and period
|
115 |
-
- One webinar name per line
|
116 |
-
- No explanations or categories
|
117 |
-
- Add a line break between each name
|
118 |
-
- Avoid unnecessary : symbols
|
119 |
-
- Each webinar name must be a complete and intriguing title
|
120 |
-
- WRITE ALL WEBINAR NAMES IN SPANISH
|
121 |
-
|
122 |
-
FORMAT EXAMPLE:
|
123 |
-
1. Nombre del Webinar 1.
|
124 |
-
|
125 |
-
2. Nombre del Webinar 2.
|
126 |
-
|
127 |
-
3. Nombre del Webinar 3.
|
128 |
-
|
129 |
-
4. Nombre del Webinar 4.
|
130 |
-
|
131 |
-
5. Nombre del Webinar 5.
|
132 |
-
|
133 |
-
IMPORTANT:
|
134 |
-
- Each webinar name must be unique and memorable
|
135 |
-
- Avoid clichés and generalities
|
136 |
-
- Maintain an intriguing but credible tone
|
137 |
-
- Adapt speaking language from the audience
|
138 |
-
- Focus on transformative benefits
|
139 |
-
- Follow the selected formula structure
|
140 |
-
- WRITE ALL WEBINAR NAMES IN SPANISH"""
|
141 |
-
|
142 |
-
# Iniciar el prompt con las instrucciones del sistema
|
143 |
-
webinar_names_instruction = f"{system_prompt}\n\n"
|
144 |
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
{
|
151 |
-
|
152 |
-
IMPORTANT: The {selected_angle} angle should be applied as a "style layer" over the formula structure:
|
153 |
-
1. Keep the base structure of the formula intact
|
154 |
-
2. Apply the tone and style of the {selected_angle} angle
|
155 |
-
3. Ensure that each element of the formula reflects the angle
|
156 |
-
4. The angle affects "how" it is said, not "what" is said
|
157 |
-
|
158 |
-
SUCCESSFUL EXAMPLES OF THE {selected_angle} ANGLE:
|
159 |
-
"""
|
160 |
-
for example in angles_webinar_names[selected_angle]["examples"]:
|
161 |
-
webinar_names_instruction += f"- {example}\n"
|
162 |
|
163 |
-
|
164 |
-
webinar_names_instruction += (
|
165 |
-
f"\nYour task is to create {number_of_names} irresistible webinar names for {audience} "
|
166 |
-
f"that instantly capture attention and generate registrations for a webinar about {topic}. "
|
167 |
-
f"Focus on awakening genuine interest and communicating the value they will get by registering."
|
168 |
-
f"\n\n"
|
169 |
-
f"IMPORTANT: Carefully study these examples of the selected formula. "
|
170 |
-
f"Each example represents the style and structure to follow"
|
171 |
-
f":\n\n"
|
172 |
-
)
|
173 |
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
|
|
179 |
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
webinar_names_instruction += "4. Preserve the level of specificity and detail\n"
|
186 |
-
webinar_names_instruction += f"5. Adapt the content for {audience} while maintaining the essence of the examples\n\n"
|
187 |
-
webinar_names_instruction += f"FORMULA TO FOLLOW:\n{selected_formula['description']}\n\n"
|
188 |
-
webinar_names_instruction += f"""
|
189 |
-
GENERATE NOW:
|
190 |
-
Create {number_of_names} webinar names that faithfully follow the style and structure of the examples shown.
|
191 |
-
"""
|
192 |
-
|
193 |
-
# Enviar el mensaje al modelo
|
194 |
-
# Use the common generate_content function
|
195 |
-
return generate_content(webinar_names_instruction, temperature)
|
196 |
-
|
197 |
-
# Update the create_input_section function to include the product/offer field
|
198 |
-
def create_input_section(col, audience_key, product_key, formulas, formula_key, offer_key=None):
|
199 |
-
audience = col.text_input("¿Quién es tu público objetivo?", placeholder="Ejemplo: Emprendedores digitales", key=audience_key)
|
200 |
-
product = col.text_input("¿Sobre qué tema es tu webinar?", placeholder="Ejemplo: Marketing de afiliados", key=product_key)
|
201 |
|
202 |
-
|
203 |
-
|
204 |
-
if offer_key:
|
205 |
-
offer = col.text_input("¿Cuál es tu producto u oferta?", placeholder="Ejemplo: Curso de marketing de afiliados", key=offer_key)
|
206 |
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
options=formula_keys,
|
212 |
-
key=formula_key
|
213 |
-
)
|
214 |
|
215 |
-
|
216 |
-
return audience, product, selected_formula_key, offer
|
217 |
-
else:
|
218 |
-
return audience, product, selected_formula_key
|
219 |
-
|
220 |
-
# Update the generate_webinar_script function to include the offer parameter
|
221 |
-
def generate_webinar_script(audience, topic, temperature, selected_formula, offer=None, creative_idea=None):
|
222 |
-
model = initialize_model(temperature)
|
223 |
|
224 |
-
|
225 |
-
|
226 |
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
- Crafts irresistible calls to action that drives conversions
|
242 |
-
- Ensures the language resonates with the target audience
|
243 |
-
|
244 |
-
3. AUDIENCE PSYCHOLOGY SPECIALIST:
|
245 |
-
- Expert in understanding audience motivations and objections
|
246 |
-
- Creates content that builds genuine connection and trust
|
247 |
-
- Identifies and addresses hidden fears and desires
|
248 |
-
- Ensures the content feels personal and relevant
|
249 |
-
|
250 |
-
4. STORYTELLING MASTER:
|
251 |
-
- Creates compelling narratives that illustrate key points
|
252 |
-
- Develops relatable examples and case studies
|
253 |
-
- Ensures stories support the transformation being offered
|
254 |
-
- Makes complex concepts accessible through narrative
|
255 |
-
|
256 |
-
5. WEBINAR ENGAGEMENT EXPERT:
|
257 |
-
- Specializes in maintaining audience attention throughout
|
258 |
-
- Creates interactive elements and engagement hooks
|
259 |
-
- Develops compelling transitions between sections
|
260 |
-
- Ensures the webinar flows naturally and keeps interest high
|
261 |
-
|
262 |
-
FORMAT REQUIREMENTS:
|
263 |
-
- Create a complete webinar script with clear sections and subsections
|
264 |
-
- Include specific talking points for each section
|
265 |
-
- Write in a conversational, engaging tone
|
266 |
-
- Include persuasive elements and calls to action
|
267 |
-
- Follow the selected webinar framework structure exactly
|
268 |
-
- WRITE THE ENTIRE SCRIPT IN SPANISH
|
269 |
-
- Start directly with the webinar content without introductory text
|
270 |
-
- DO NOT include any explanatory text at the beginning like "Here's the webinar script..." or "I've created a webinar script..."
|
271 |
-
|
272 |
-
COLLABORATIVE PROCESS:
|
273 |
-
As a team of experts, you will:
|
274 |
-
1. Analyze the framework '{selected_formula['description']}' to understand its core principles
|
275 |
-
2. Identify how to best adapt this framework for {audience} learning about {topic}{offer_text}
|
276 |
-
3. Create persuasive language that resonates with {audience}
|
277 |
-
4. Ensure the script maintains engagement throughout
|
278 |
-
5. Follow the exact structure provided in the framework"""
|
279 |
-
|
280 |
-
# Añadir instrucciones para la idea creativa si existe
|
281 |
-
if creative_idea:
|
282 |
-
system_prompt += f"""
|
283 |
-
CREATIVE CONCEPT:
|
284 |
-
Use the following creative concept as the central theme for the webinar:
|
285 |
-
"{creative_idea}"
|
286 |
-
|
287 |
-
CREATIVE CONCEPT INSTRUCTIONS:
|
288 |
-
1. This concept should be the unifying theme across the entire webinar
|
289 |
-
2. Use it as a metaphor or analogy throughout the presentation
|
290 |
-
3. Develop different aspects of this concept in each section
|
291 |
-
4. Make sure the concept naturally connects to the product benefits
|
292 |
-
5. The concept should make the webinar more memorable and engaging
|
293 |
-
"""
|
294 |
-
|
295 |
-
# Update the task instructions to include the offer
|
296 |
-
offer_instruction = f" and selling {offer}" if offer else ""
|
297 |
|
298 |
-
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
-
|
308 |
-
|
309 |
-
|
310 |
-
for i, step in enumerate(selected_formula['structure'], 1):
|
311 |
-
webinar_script_instruction += f"{i}. {step}\n"
|
312 |
-
|
313 |
-
# Ejemplos de webinars exitosos
|
314 |
-
webinar_script_instruction += "\n\nEXAMPLES OF SUCCESSFUL WEBINARS WITH THIS STRUCTURE:\n"
|
315 |
-
for i, example in enumerate(selected_formula['examples'], 1):
|
316 |
-
webinar_script_instruction += f"{i}. {example}\n"
|
317 |
-
|
318 |
-
# Instrucciones específicas - Reforzar el español
|
319 |
-
webinar_script_instruction += f"""
|
320 |
-
SPECIFIC INSTRUCTIONS:
|
321 |
-
1. Create a complete script that follows exactly the provided structure
|
322 |
-
2. Include persuasive elements and clear calls to action
|
323 |
-
3. Adapt the language and examples specifically for {audience}
|
324 |
-
4. Focus on the transformative benefits of {topic}
|
325 |
-
5. Include relevant stories and examples that reinforce your points
|
326 |
-
6. Use a conversational but professional tone
|
327 |
-
7. Make sure each section fulfills its specific purpose in the framework
|
328 |
-
8. IMPORTANT: Write the ENTIRE script in Spanish (neutral Latin American Spanish)
|
329 |
-
9. DO NOT include any introductory text like "Here's the webinar script..." or "I've created a webinar script..."
|
330 |
-
10. Start directly with the webinar title and content
|
331 |
-
11. ALL section titles, headers, and content MUST be in Spanish
|
332 |
-
12. Ensure ALL examples, stories, and calls to action are in Spanish
|
333 |
-
|
334 |
-
GENERATE NOW:
|
335 |
-
Create a complete webinar script following faithfully the structure of the selected framework, entirely in Spanish.
|
336 |
-
"""
|
337 |
-
|
338 |
-
# Enviar el mensaje al modelo
|
339 |
-
chat_session = model.start_chat(
|
340 |
-
history=[
|
341 |
-
{
|
342 |
-
"role": "user",
|
343 |
-
"parts": [webinar_script_instruction],
|
344 |
-
},
|
345 |
-
]
|
346 |
-
)
|
347 |
-
response = chat_session.send_message("Generate the webinar script IN NEUTRAL SPANISH following exactly the provided structure. All content must be in neutral Spanish (not Spain Spanish). Start directly with the webinar content without any introductory text.")
|
348 |
|
349 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
350 |
|
351 |
-
#
|
352 |
-
|
353 |
-
has_audience = audience.strip() != ""
|
354 |
-
has_product = product.strip() != ""
|
355 |
-
return has_audience and has_product
|
356 |
|
357 |
-
#
|
358 |
-
|
359 |
-
css_path = "styles/styles.css"
|
360 |
-
if os.path.exists(css_path):
|
361 |
-
try:
|
362 |
-
with open(css_path, "r") as f:
|
363 |
-
st.markdown(f"<style>{f.read()}</style>", unsafe_allow_html=True)
|
364 |
-
except Exception as e:
|
365 |
-
st.warning(f"Error al cargar el archivo CSS: {str(e)}")
|
366 |
-
else:
|
367 |
-
st.warning(f"No se encontró el archivo CSS en {css_path}")
|
368 |
|
369 |
-
#
|
370 |
-
st.
|
371 |
-
|
372 |
-
layout="wide",
|
373 |
-
initial_sidebar_state="expanded",
|
374 |
-
menu_items=None # This removes the three dots menu
|
375 |
-
)
|
376 |
-
load_css() # This will load the styles from styles.css
|
377 |
|
378 |
-
#
|
379 |
with open("manual.md", "r", encoding="utf-8") as file:
|
380 |
manual_content = file.read()
|
381 |
-
|
382 |
-
# Mostrar el contenido del manual en el sidebar
|
383 |
st.sidebar.markdown(manual_content)
|
384 |
|
385 |
-
#
|
386 |
-
st.
|
387 |
-
st.markdown("<h3 style='text-align: center;'>Crea guiones y títulos de webinars persuasivos que convierten</h3>", unsafe_allow_html=True)
|
388 |
|
389 |
-
#
|
390 |
-
|
391 |
-
|
392 |
-
|
393 |
-
|
394 |
-
|
|
|
395 |
|
396 |
-
|
397 |
-
|
|
|
|
|
398 |
|
399 |
-
|
400 |
-
|
401 |
-
|
402 |
-
|
403 |
-
|
404 |
-
|
|
|
|
|
|
|
|
|
|
|
405 |
|
406 |
-
#
|
407 |
-
|
|
|
|
|
|
|
|
|
|
|
408 |
|
409 |
-
#
|
410 |
-
|
411 |
-
|
412 |
-
|
413 |
-
|
414 |
-
|
415 |
-
|
416 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
417 |
|
418 |
-
#
|
419 |
-
|
420 |
-
|
421 |
-
|
422 |
-
|
423 |
-
|
424 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
425 |
|
426 |
-
#
|
427 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
428 |
|
429 |
-
selected_webinar_formula = webinar_formulas[selected_webinar_formula_key]
|
430 |
-
|
431 |
-
# Usar la función generate_and_display para generar y mostrar el guión
|
432 |
-
if submit_webinar_script:
|
433 |
-
generate_and_display(
|
434 |
-
col=col2,
|
435 |
-
generator_func=generate_webinar_script,
|
436 |
-
audience=webinar_script_audience,
|
437 |
-
product=webinar_script_product,
|
438 |
-
temperature=webinar_script_temperature,
|
439 |
-
selected_formula=selected_webinar_formula,
|
440 |
-
content_type="script",
|
441 |
-
offer=webinar_script_offer if webinar_script_offer.strip() else None,
|
442 |
-
creative_idea=creative_idea if creative_idea.strip() else None
|
443 |
-
)
|
444 |
|
445 |
-
#
|
446 |
-
|
447 |
-
|
448 |
-
|
449 |
-
|
450 |
-
|
451 |
-
|
452 |
-
# Columna de entrada
|
453 |
-
with col1:
|
454 |
-
# Inputs básicos
|
455 |
-
webinar_names_audience = st.text_input("¿Quién es tu público objetivo?", placeholder="Ejemplo: Emprendedores digitales", key="webinar_names_audience")
|
456 |
-
webinar_names_product = st.text_input("¿Sobre qué tema es tu webinar?", placeholder="Ejemplo: Marketing de afiliados", key="webinar_names_product")
|
457 |
|
458 |
-
#
|
459 |
-
|
460 |
|
461 |
-
#
|
462 |
-
|
463 |
-
# Selector de fórmula
|
464 |
-
selected_name_formula_key = st.selectbox(
|
465 |
-
"Selecciona una fórmula para tus nombres",
|
466 |
-
options=list(webinar_name_formulas.keys()),
|
467 |
-
key="webinar_name_formula"
|
468 |
-
)
|
469 |
-
|
470 |
-
# Selector de ángulo
|
471 |
-
selected_angle = st.selectbox(
|
472 |
-
"Selecciona un ángulo (opcional)",
|
473 |
-
options=["NINGUNO"] + list(angles_webinar_names.keys()),
|
474 |
-
key="webinar_name_angle"
|
475 |
-
)
|
476 |
-
|
477 |
-
# Número de nombres a generar
|
478 |
-
number_of_names = st.slider("Número de nombres a generar", min_value=3, max_value=15, value=5, step=1, key="number_of_names")
|
479 |
-
|
480 |
-
# Slider de creatividad
|
481 |
-
webinar_names_temperature = st.slider("Creatividad", min_value=0.0, max_value=2.0, value=1.0, step=0.1, key="webinar_names_temp")
|
482 |
|
483 |
-
|
484 |
-
|
485 |
-
|
486 |
-
|
487 |
-
|
488 |
-
|
489 |
-
|
490 |
-
|
491 |
-
product=webinar_names_product,
|
492 |
-
temperature=webinar_names_temperature,
|
493 |
-
selected_formula=selected_name_formula,
|
494 |
-
content_type="names",
|
495 |
-
number_of_names=number_of_names,
|
496 |
-
selected_angle=selected_angle if selected_angle != "NINGUNO" else None
|
497 |
)
|
498 |
|
499 |
-
|
500 |
-
|
501 |
-
|
502 |
-
|
503 |
-
|
504 |
-
|
505 |
-
|
506 |
-
|
507 |
-
|
508 |
-
|
509 |
-
|
510 |
-
|
511 |
-
|
512 |
-
|
513 |
-
|
514 |
-
# Download button
|
515 |
-
st.download_button(
|
516 |
-
label="DESCARGAR GUIÓN DE WEBINAR",
|
517 |
-
data=download_content,
|
518 |
-
file_name=f"guion_webinar_{timestamp}.txt",
|
519 |
-
mime="text/plain"
|
520 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
521 |
|
522 |
-
|
523 |
-
st.
|
524 |
-
st.markdown(generated_content)
|
525 |
-
|
526 |
-
# Create download content with timestamp
|
527 |
-
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
528 |
-
download_content = generated_content
|
529 |
|
530 |
# Download button
|
531 |
st.download_button(
|
532 |
-
label="DESCARGAR
|
533 |
data=download_content,
|
534 |
-
file_name=f"
|
535 |
mime="text/plain"
|
536 |
-
)
|
537 |
-
|
538 |
-
# ... existing code ...
|
539 |
-
|
|
|
2 |
import streamlit as st
|
3 |
import os
|
4 |
import google.generativeai as genai
|
5 |
+
from puv_formulas import puv_formulas
|
6 |
+
from styles import apply_styles, format_creative_response
|
7 |
+
from options import tone_options, creative_approaches
|
8 |
+
import PyPDF2
|
9 |
+
import docx
|
10 |
+
from PIL import Image
|
11 |
+
import datetime # Add this import for timestamp
|
12 |
+
|
13 |
+
# Cargar variables de entorno
|
14 |
load_dotenv()
|
15 |
|
16 |
+
# Configurar API de Google Gemini
|
17 |
genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
|
18 |
|
19 |
+
# Función para obtener la respuesta del modelo Gemini
|
20 |
+
def get_gemini_response(product_service, target_audience, main_benefit, tone_of_voice, temperature, file_content="", image_parts=None, creative_approach=""):
|
21 |
+
# Adjust prompt based on what's provided
|
22 |
+
business_info = f"Target Audience: {target_audience}\n"
|
23 |
+
business_info += f"Product/Service: {product_service}\n"
|
24 |
+
business_info += f"Main Benefit: {main_benefit}\n"
|
25 |
|
26 |
+
if tone_of_voice:
|
27 |
+
business_info += f"Brand Tone of Voice: {tone_of_voice}\n"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
|
29 |
+
# Add creative approach to business info if provided
|
30 |
+
if creative_approach:
|
31 |
+
# Get the description from the dictionary
|
32 |
+
from options import creative_approaches
|
33 |
+
approach_description = creative_approaches.get(creative_approach, "")
|
34 |
+
business_info += f"\nCREATIVE APPROACH: {creative_approach}\n"
|
35 |
+
business_info += f"Description: {approach_description}\n"
|
36 |
+
business_info += f"IMPORTANT: Please follow this creative approach strictly when generating concepts.\n"
|
37 |
|
38 |
+
# Add file content if available
|
39 |
+
reference_info = ""
|
40 |
+
if file_content:
|
41 |
+
reference_info = f"\nREFERENCE MATERIAL:\n{file_content}\n"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
42 |
|
43 |
+
model = genai.GenerativeModel('gemini-2.0-flash')
|
44 |
+
full_prompt = f"""
|
45 |
+
You are a Creative Concept expert. Analyze (internally only, do not output the analysis) the following information:
|
46 |
+
BUSINESS INFORMATION:
|
47 |
+
{business_info}
|
48 |
+
{reference_info}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
49 |
|
50 |
+
A Creative Idea is a set of pieces created to sell a brand, product, or service, united by the same idea that is transmitted through a creative concept.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
51 |
|
52 |
+
First, analyze (but don't output) these points:
|
53 |
+
1. TARGET AUDIENCE ANALYSIS:
|
54 |
+
- What everyday concepts are they familiar with?
|
55 |
+
- What TV shows, movies, or cultural references resonate with them?
|
56 |
+
- What emotions and experiences are meaningful to them?
|
57 |
+
- What mental images would be easy for them to recall?
|
58 |
|
59 |
+
2. PRODUCT/SERVICE ANALYSIS:
|
60 |
+
- What is the main benefit or promise?
|
61 |
+
- What makes it unique or different?
|
62 |
+
- What transformation does it offer?
|
63 |
+
- What process or journey does the customer go through?
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
64 |
|
65 |
+
Based on your internal analysis, create THREE different Creative Concepts in Spanish language.
|
66 |
+
Each concept should be a DIRECT ANALOGY or METAPHOR that connects your product/service to something completely different but familiar.
|
|
|
|
|
67 |
|
68 |
+
Examples of good creative concepts:
|
69 |
+
- "Escribir copy es como cocinar tu plato favorito porque necesitas los ingredientes correctos para que todos quieran probarlo"
|
70 |
+
- "Tu negocio es como un equipo de fútbol: necesita buenos jugadores (productos) y una estrategia clara para ganar clientes"
|
71 |
+
- "Tu curso es como Netflix: ofrece contenido que engancha y soluciones que la gente realmente quiere ver"
|
|
|
|
|
|
|
72 |
|
73 |
+
For each concept, include:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
74 |
|
75 |
+
CONCEPT: A clear statement of the main benefit
|
76 |
+
CREATIVITY: A direct analogy or metaphor connecting your product to something completely different but familiar
|
77 |
|
78 |
+
CRITICAL INSTRUCTIONS:
|
79 |
+
- Each concept MUST use a direct "X es como Y porque Z" structure
|
80 |
+
- Use SIMPLE, EVERYDAY language that anyone can understand
|
81 |
+
- Avoid technical jargon, complex words, or business terminology
|
82 |
+
- Write as if you're explaining to a friend in a casual conversation
|
83 |
+
- Use everyday objects, activities, movies, TV shows or cultural references everyone knows
|
84 |
+
- Make the connection SURPRISING and UNEXPECTED - connect things that normally wouldn't be connected
|
85 |
+
- Challenge conventional thinking by finding parallels between your product and something completely different
|
86 |
+
- Create analogies that make people say "I never thought of it that way!"
|
87 |
+
- Focus on the main benefit
|
88 |
+
- Create clear mental images
|
89 |
+
- Be easy to remember
|
90 |
+
- Use the brand's tone of voice if provided
|
91 |
+
- Format with proper spacing between sections
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
92 |
|
93 |
+
Output EXACTLY in this format (no additional text) in Spanish language:
|
94 |
+
|
95 |
+
CONCEPTO CREATIVO 1:
|
96 |
+
|
97 |
+
Concepto:
|
98 |
+
[Main message/benefit in simple, conversational language]
|
99 |
+
|
100 |
+
Creatividad:
|
101 |
+
[Direct analogy using everyday language: "X es como Y porque Z"]
|
102 |
+
|
103 |
+
|
104 |
+
CONCEPTO CREATIVO 2:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
105 |
|
106 |
+
Concepto:
|
107 |
+
[Main message/benefit]
|
108 |
+
|
109 |
+
Creatividad:
|
110 |
+
[Direct analogy: "X es como Y porque Z"]
|
111 |
+
|
112 |
+
|
113 |
+
CONCEPTO CREATIVO 3:
|
114 |
+
|
115 |
+
Concepto:
|
116 |
+
[Main message/benefit]
|
117 |
+
|
118 |
+
Creatividad:
|
119 |
+
[Direct analogy: "X es como Y porque Z"]
|
120 |
+
"""
|
121 |
+
|
122 |
+
# Handle text-only or text+image requests
|
123 |
+
if image_parts:
|
124 |
+
response = model.generate_content([full_prompt, image_parts], generation_config={"temperature": temperature})
|
125 |
+
else:
|
126 |
+
response = model.generate_content([full_prompt], generation_config={"temperature": temperature})
|
127 |
+
|
128 |
+
return response.parts[0].text if response and response.parts else "Error generating content."
|
129 |
|
130 |
+
# Configurar la aplicación Streamlit
|
131 |
+
st.set_page_config(page_title="Generador de Ideas Creativas", page_icon="💡", layout="wide")
|
|
|
|
|
|
|
132 |
|
133 |
+
# Aplicar estilos
|
134 |
+
st.markdown(apply_styles(), unsafe_allow_html=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
135 |
|
136 |
+
# Título de la app
|
137 |
+
st.markdown("<h1>Generador de Ideas Creativas</h1>", unsafe_allow_html=True)
|
138 |
+
st.markdown("<h3>Crea conceptos creativos poderosos que conecten con tu audiencia y transmitan el valor de tu marca de manera memorable.</h3>", unsafe_allow_html=True)
|
|
|
|
|
|
|
|
|
|
|
139 |
|
140 |
+
# Sidebar manual
|
141 |
with open("manual.md", "r", encoding="utf-8") as file:
|
142 |
manual_content = file.read()
|
|
|
|
|
143 |
st.sidebar.markdown(manual_content)
|
144 |
|
145 |
+
# Crear dos columnas
|
146 |
+
col1, col2 = st.columns([1, 1])
|
|
|
147 |
|
148 |
+
# Columna izquierda para inputs
|
149 |
+
# In the app.py file, update the main_benefit field label and create an accordion for tone options
|
150 |
+
with col1:
|
151 |
+
product_service = st.text_area(
|
152 |
+
"¿Cuál es tu producto o servicio?",
|
153 |
+
placeholder="Ejemplo: Curso de copywriting con IA, Programa de coaching..."
|
154 |
+
)
|
155 |
|
156 |
+
main_benefit = st.text_area(
|
157 |
+
"¿Cuál es tu Oferta Dorada/PUV?",
|
158 |
+
placeholder="Ejemplo: Aprender copywriting a través de transformaciones reales de textos..."
|
159 |
+
)
|
160 |
|
161 |
+
target_audience = st.text_area(
|
162 |
+
"¿Cuál es tu público objetivo?",
|
163 |
+
placeholder="Ejemplo: Emprendedores que quieren mejorar sus textos comerciales..."
|
164 |
+
)
|
165 |
+
|
166 |
+
# Generate button after main inputs
|
167 |
+
generate_button = st.button("Generar Ideas Creativas")
|
168 |
+
|
169 |
+
with st.expander("Opciones avanzadas"):
|
170 |
+
# Replace nested expanders with a selectbox for tone selection
|
171 |
+
st.write("Tono de voz de la marca (opcional)")
|
172 |
|
173 |
+
# Use selectbox for tone selection
|
174 |
+
selected_tone = st.selectbox(
|
175 |
+
"Selecciona un tono:",
|
176 |
+
options=list(tone_options.keys()),
|
177 |
+
index=0,
|
178 |
+
key="tone_selectbox"
|
179 |
+
)
|
180 |
|
181 |
+
# Display the description of the selected tone
|
182 |
+
if selected_tone != "Ninguno":
|
183 |
+
st.info(tone_options[selected_tone])
|
184 |
+
# Store the selected tone
|
185 |
+
st.session_state.selected_tone = selected_tone
|
186 |
+
else:
|
187 |
+
# Clear any previously selected tone
|
188 |
+
if "selected_tone" in st.session_state:
|
189 |
+
del st.session_state.selected_tone
|
190 |
+
|
191 |
+
# Use the stored tone or empty string
|
192 |
+
tone_of_voice = st.session_state.get("selected_tone", "")
|
193 |
+
|
194 |
+
# Añadir cargador de archivos
|
195 |
+
uploaded_file = st.file_uploader("📄 Archivo o imagen de referencia",
|
196 |
+
type=['txt', 'pdf', 'docx', 'jpg', 'jpeg', 'png'])
|
197 |
+
|
198 |
+
file_content = ""
|
199 |
+
is_image = False
|
200 |
+
image_parts = None
|
201 |
+
|
202 |
+
if uploaded_file is not None:
|
203 |
+
file_type = uploaded_file.name.split('.')[-1].lower()
|
204 |
|
205 |
+
# Manejar archivos de texto
|
206 |
+
if file_type in ['txt', 'pdf', 'docx']:
|
207 |
+
if file_type == 'txt':
|
208 |
+
try:
|
209 |
+
file_content = uploaded_file.read().decode('utf-8')
|
210 |
+
except Exception as e:
|
211 |
+
st.error(f"Error al leer el archivo TXT: {str(e)}")
|
212 |
+
file_content = ""
|
213 |
+
|
214 |
+
elif file_type == 'pdf':
|
215 |
+
try:
|
216 |
+
pdf_reader = PyPDF2.PdfReader(uploaded_file)
|
217 |
+
file_content = ""
|
218 |
+
for page in pdf_reader.pages:
|
219 |
+
file_content += page.extract_text() + "\n"
|
220 |
+
except Exception as e:
|
221 |
+
st.error(f"Error al leer el archivo PDF: {str(e)}")
|
222 |
+
file_content = ""
|
223 |
+
|
224 |
+
elif file_type == 'docx':
|
225 |
+
try:
|
226 |
+
doc = docx.Document(uploaded_file)
|
227 |
+
file_content = "\n".join([para.text for para in doc.paragraphs])
|
228 |
+
except Exception as e:
|
229 |
+
st.error(f"Error al leer el archivo DOCX: {str(e)}")
|
230 |
+
file_content = ""
|
231 |
|
232 |
+
# Manejar archivos de imagen
|
233 |
+
elif file_type in ['jpg', 'jpeg', 'png']:
|
234 |
+
try:
|
235 |
+
image = Image.open(uploaded_file)
|
236 |
+
image_bytes = uploaded_file.getvalue()
|
237 |
+
image_parts = {
|
238 |
+
"mime_type": uploaded_file.type,
|
239 |
+
"data": image_bytes
|
240 |
+
}
|
241 |
+
is_image = True
|
242 |
+
except Exception as e:
|
243 |
+
st.error(f"Error al procesar la imagen: {str(e)}")
|
244 |
+
is_image = False
|
245 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
246 |
|
247 |
+
# Add creative approach selector (moved outside nested expander)
|
248 |
+
selected_approach = st.selectbox(
|
249 |
+
"Enfoque creativo:",
|
250 |
+
options=list(creative_approaches.keys()),
|
251 |
+
index=0,
|
252 |
+
key="approach_selectbox"
|
253 |
+
)
|
|
|
|
|
|
|
|
|
|
|
254 |
|
255 |
+
# Display the description of the selected approach
|
256 |
+
st.info(creative_approaches[selected_approach])
|
257 |
|
258 |
+
# Store the selected approach
|
259 |
+
st.session_state.selected_approach = selected_approach
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
260 |
|
261 |
+
# Temperature slider
|
262 |
+
temperature = st.slider(
|
263 |
+
"Nivel de creatividad:",
|
264 |
+
min_value=0.0,
|
265 |
+
max_value=2.0,
|
266 |
+
value=1.0,
|
267 |
+
step=0.1,
|
268 |
+
help="Valores más altos generan ideas más creativas pero menos predecibles."
|
|
|
|
|
|
|
|
|
|
|
|
|
269 |
)
|
270 |
|
271 |
+
with col2:
|
272 |
+
if generate_button:
|
273 |
+
# Store the response in session state so it persists across reruns
|
274 |
+
with st.spinner("Creando tus ideas creativas..."):
|
275 |
+
st.session_state.creative_response = get_gemini_response(
|
276 |
+
product_service,
|
277 |
+
target_audience,
|
278 |
+
main_benefit,
|
279 |
+
tone_of_voice,
|
280 |
+
temperature,
|
281 |
+
file_content,
|
282 |
+
image_parts,
|
283 |
+
st.session_state.get("selected_approach", "")
|
284 |
+
# Removed contrast_level parameter
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
285 |
)
|
286 |
+
|
287 |
+
# Display the response if it exists in session state
|
288 |
+
if 'creative_response' in st.session_state:
|
289 |
+
st.write("### Conceptos Creativos")
|
290 |
+
|
291 |
+
# Format the response with custom styling
|
292 |
+
formatted_response = format_creative_response(st.session_state.creative_response)
|
293 |
+
|
294 |
+
# Use markdown with HTML to display the formatted response
|
295 |
+
st.markdown(formatted_response, unsafe_allow_html=True)
|
296 |
+
|
297 |
+
# Add download button if we have a valid response
|
298 |
+
if st.session_state.creative_response and not st.session_state.creative_response.startswith("Error") and not st.session_state.creative_response.startswith("Debes"):
|
299 |
+
# Get current timestamp for the filename
|
300 |
+
timestamp = datetime.datetime.now().strftime("%Y%m%d_%H%M%S")
|
301 |
|
302 |
+
# Prepare content for download (use the original unformatted response)
|
303 |
+
download_content = st.session_state.creative_response
|
|
|
|
|
|
|
|
|
|
|
304 |
|
305 |
# Download button
|
306 |
st.download_button(
|
307 |
+
label="DESCARGAR IDEAS CREATIVAS",
|
308 |
data=download_content,
|
309 |
+
file_name=f"conceptos_creativos_{timestamp}.txt",
|
310 |
mime="text/plain"
|
311 |
+
)
|
|
|
|
|
|