JeCabrera commited on
Commit
3c01b83
·
verified ·
1 Parent(s): b248ebd

Upload 12 files

Browse files
Files changed (1) hide show
  1. app.py +144 -111
app.py CHANGED
@@ -16,62 +16,68 @@ load_dotenv()
16
  genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
17
 
18
  # Create a reusable function for generation and display
19
- def generate_and_display(col, generator_func, audience, product, temperature, selected_formula, **kwargs):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
  if validate_inputs(audience, product):
21
  try:
22
  with col:
23
- with st.spinner("Generando contenido...", show_time=True):
24
- # Extract only the parameters that the generator function accepts
25
- if generator_func.__name__ == "generate_webinar_script":
26
- generated_content = generator_func(
27
- audience=audience,
28
- topic=product,
29
- temperature=temperature,
30
- selected_formula=selected_formula,
31
- offer=kwargs.get("offer", None) # Add the offer parameter
32
- )
33
- elif generator_func.__name__ == "generate_webinar_names":
34
- generated_content = generator_func(
35
- number_of_names=kwargs.get("number_of_names", 5),
36
- target_audience=audience,
37
- product=product,
38
- temperature=temperature,
39
- selected_formula=selected_formula,
40
- selected_angle=kwargs.get("selected_angle", None)
41
- )
42
- else:
43
- # Generic fallback
44
- generated_content = generator_func(
45
- audience=audience,
46
- topic=product,
47
- temperature=temperature,
48
- selected_formula=selected_formula,
49
- **kwargs
50
- )
51
-
52
- # For webinar scripts, add download buttons
53
- if "script" in kwargs.get("content_type", ""):
54
- timestamp = datetime.datetime.now().strftime("%Y%m%d_%H%M%S")
55
- st.download_button(
56
- label="DESCARGAR GUION DE MI WEBINAR ▶▶",
57
- data=generated_content,
58
- file_name=f"guion_webinar_{timestamp}.md",
59
- mime="text/markdown",
60
- key="download_top"
61
  )
62
 
63
- st.subheader("Tu " + ("guión de webinar:" if "script" in kwargs.get("content_type", "") else "nombres de webinar:"))
64
- st.markdown(generated_content)
65
 
66
- # Add bottom download button for scripts
67
- if "script" in kwargs.get("content_type", ""):
68
- st.download_button(
69
- label="DESCARGAR GUION DE MI WEBINAR ▶▶",
70
- data=generated_content,
71
- file_name=f"guion_webinar_{timestamp}.md",
72
- mime="text/markdown",
73
- key="download_bottom"
74
- )
75
  except ValueError as e:
76
  col.error(f"Error: {str(e)}")
77
  else:
@@ -109,7 +115,8 @@ def generate_content(prompt_instructions, temperature):
109
  return response.text
110
 
111
  # Función para generar nombres de webinars
112
- def generate_webinar_names(number_of_names, target_audience, product, temperature, selected_formula, selected_angle=None):
 
113
  # Incluir las instrucciones del sistema en el prompt principal
114
  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.
115
 
@@ -165,8 +172,8 @@ SUCCESSFUL EXAMPLES OF THE {selected_angle} ANGLE:
165
 
166
  # Instrucciones específicas para la tarea
167
  webinar_names_instruction += (
168
- f"\nYour task is to create {number_of_names} irresistible webinar names for {target_audience} "
169
- f"that instantly capture attention and generate registrations for a webinar about {product}. "
170
  f"Focus on awakening genuine interest and communicating the value they will get by registering."
171
  f"\n\n"
172
  f"IMPORTANT: Carefully study these examples of the selected formula. "
@@ -186,7 +193,7 @@ SUCCESSFUL EXAMPLES OF THE {selected_angle} ANGLE:
186
  webinar_names_instruction += "2. Use the same tone and writing style\n"
187
  webinar_names_instruction += "3. Replicate the phrase construction patterns\n"
188
  webinar_names_instruction += "4. Preserve the level of specificity and detail\n"
189
- webinar_names_instruction += f"5. Adapt the content for {target_audience} while maintaining the essence of the examples\n\n"
190
  webinar_names_instruction += f"FORMULA TO FOLLOW:\n{selected_formula['description']}\n\n"
191
  webinar_names_instruction += f"""
192
  GENERATE NOW:
@@ -318,23 +325,23 @@ CREATIVE CONCEPT INSTRUCTIONS:
318
  for i, example in enumerate(selected_formula['examples'], 1):
319
  webinar_script_instruction += f"{i}. {example}\n"
320
 
321
- # Instrucciones específicas - CORREGIR INDENTACIÓN
322
- webinar_script_instruction += f"""
323
- SPECIFIC INSTRUCTIONS:
324
- 1. Create a complete script that follows exactly the provided structure
325
- 2. Include persuasive elements and clear calls to action
326
- 3. Adapt the language and examples specifically for {audience}
327
- 4. Focus on the transformative benefits of {topic}
328
- 5. Include relevant stories and examples that reinforce your points
329
- 6. Use a conversational but professional tone
330
- 7. Make sure each section fulfills its specific purpose in the framework
331
- 8. IMPORTANT: Write the entire script in Spanish
332
- 9. DO NOT include any introductory text like "Here's the webinar script..." or "I've created a webinar script..."
333
- 10. Start directly with the webinar title and content
334
-
335
- GENERATE NOW:
336
- Create a complete webinar script following faithfully the structure of the selected framework.
337
- """
338
 
339
  # Enviar el mensaje al modelo
340
  chat_session = model.start_chat(
@@ -420,45 +427,71 @@ with tab1:
420
 
421
  selected_webinar_formula = webinar_formulas[selected_webinar_formula_key]
422
 
423
- # Actualizar la función generate_webinar_script para incluir la idea creativa
424
  if submit_webinar_script:
425
- # Validar entradas
426
- if validate_inputs(webinar_script_audience, webinar_script_product):
427
- try:
428
- with col2:
429
- with st.spinner("Generando guión de webinar...", show_time=True):
430
- # Usar la función generate_webinar_script existente
431
- generated_content = generate_webinar_script(
432
- audience=webinar_script_audience,
433
- topic=webinar_script_product,
434
- temperature=webinar_script_temperature,
435
- selected_formula=selected_webinar_formula,
436
- offer=webinar_script_offer if webinar_script_offer.strip() else None,
437
- creative_idea=creative_idea if creative_idea.strip() else None
438
- )
439
-
440
- # Mostrar el contenido generado
441
- timestamp = datetime.datetime.now().strftime("%Y%m%d_%H%M%S")
442
- st.download_button(
443
- label="DESCARGAR GUION DE MI WEBINAR ▶▶",
444
- data=generated_content,
445
- file_name=f"guion_webinar_{timestamp}.md",
446
- mime="text/markdown",
447
- key="download_top"
448
- )
449
-
450
- st.subheader("Tu guión de webinar:")
451
- st.markdown(generated_content)
452
-
453
- st.download_button(
454
- label="DESCARGAR GUION DE MI WEBINAR ▶▶",
455
- data=generated_content,
456
- file_name=f"guion_webinar_{timestamp}.md",
457
- mime="text/markdown",
458
- key="download_bottom"
459
- )
460
- except ValueError as e:
461
- col2.error(f"Error: {str(e)}")
462
- else:
463
- col2.error("Por favor, proporciona el público objetivo y el tema del webinar.")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
464
 
 
16
  genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
17
 
18
  # Create a reusable function for generation and display
19
+ # Función auxiliar para mostrar el contenido generado y los botones de descarga
20
+ def display_generated_content(col, generated_content, content_type):
21
+ timestamp = datetime.datetime.now().strftime("%Y%m%d_%H%M%S")
22
+
23
+ # Determinar el tipo de contenido para personalizar los botones y títulos
24
+ if content_type == "script":
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
+ download_label = "DESCARGAR NOMBRES DE WEBINAR ▶▶"
38
+ file_name = f"nombres_webinar_{timestamp}.md"
39
+ subheader_text = "Tus nombres de webinar:"
40
+
41
+ # Mostrar el contenido generado
42
+ col.subheader(subheader_text)
43
+ col.markdown(generated_content)
44
+
45
+ # Mostrar botón de descarga inferior solo para guiones
46
+ if content_type == "script":
47
+ col.download_button(
48
+ label=download_label,
49
+ data=generated_content,
50
+ file_name=file_name,
51
+ mime="text/markdown",
52
+ key=f"download_bottom_{content_type}"
53
+ )
54
+ else:
55
+ col.download_button(
56
+ label=download_label,
57
+ data=generated_content,
58
+ file_name=file_name,
59
+ mime="text/markdown",
60
+ key=f"download_{content_type}"
61
+ )
62
+
63
+ # Implementar la función generate_and_display para reemplazar código duplicado
64
+ def generate_and_display(col, generator_func, audience, product, temperature, selected_formula, content_type, **kwargs):
65
  if validate_inputs(audience, product):
66
  try:
67
  with col:
68
+ with st.spinner(f"Generando {'guión' if content_type == 'script' else 'nombres'} de webinar...", show_time=True):
69
+ # Llamar a la función generadora con los parámetros adecuados
70
+ generated_content = generator_func(
71
+ audience=audience,
72
+ topic=product,
73
+ temperature=temperature,
74
+ selected_formula=selected_formula,
75
+ **kwargs
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
76
  )
77
 
78
+ # Mostrar el contenido generado usando la función auxiliar
79
+ display_generated_content(col, generated_content, content_type)
80
 
 
 
 
 
 
 
 
 
 
81
  except ValueError as e:
82
  col.error(f"Error: {str(e)}")
83
  else:
 
115
  return response.text
116
 
117
  # Función para generar nombres de webinars
118
+ # Refactorizar la función generate_webinar_names para que acepte los mismos parámetros que generate_webinar_script
119
+ def generate_webinar_names(audience, topic, temperature, selected_formula, number_of_names=5, selected_angle=None, **kwargs):
120
  # Incluir las instrucciones del sistema en el prompt principal
121
  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.
122
 
 
172
 
173
  # Instrucciones específicas para la tarea
174
  webinar_names_instruction += (
175
+ f"\nYour task is to create {number_of_names} irresistible webinar names for {audience} "
176
+ f"that instantly capture attention and generate registrations for a webinar about {topic}. "
177
  f"Focus on awakening genuine interest and communicating the value they will get by registering."
178
  f"\n\n"
179
  f"IMPORTANT: Carefully study these examples of the selected formula. "
 
193
  webinar_names_instruction += "2. Use the same tone and writing style\n"
194
  webinar_names_instruction += "3. Replicate the phrase construction patterns\n"
195
  webinar_names_instruction += "4. Preserve the level of specificity and detail\n"
196
+ webinar_names_instruction += f"5. Adapt the content for {audience} while maintaining the essence of the examples\n\n"
197
  webinar_names_instruction += f"FORMULA TO FOLLOW:\n{selected_formula['description']}\n\n"
198
  webinar_names_instruction += f"""
199
  GENERATE NOW:
 
325
  for i, example in enumerate(selected_formula['examples'], 1):
326
  webinar_script_instruction += f"{i}. {example}\n"
327
 
328
+ # Instrucciones específicas - CORREGIR INDENTACIÓN
329
+ webinar_script_instruction += f"""
330
+ SPECIFIC INSTRUCTIONS:
331
+ 1. Create a complete script that follows exactly the provided structure
332
+ 2. Include persuasive elements and clear calls to action
333
+ 3. Adapt the language and examples specifically for {audience}
334
+ 4. Focus on the transformative benefits of {topic}
335
+ 5. Include relevant stories and examples that reinforce your points
336
+ 6. Use a conversational but professional tone
337
+ 7. Make sure each section fulfills its specific purpose in the framework
338
+ 8. IMPORTANT: Write the entire script in Spanish
339
+ 9. DO NOT include any introductory text like "Here's the webinar script..." or "I've created a webinar script..."
340
+ 10. Start directly with the webinar title and content
341
+
342
+ GENERATE NOW:
343
+ Create a complete webinar script following faithfully the structure of the selected framework.
344
+ """
345
 
346
  # Enviar el mensaje al modelo
347
  chat_session = model.start_chat(
 
427
 
428
  selected_webinar_formula = webinar_formulas[selected_webinar_formula_key]
429
 
430
+ # Usar la función generate_and_display para generar y mostrar el guión
431
  if submit_webinar_script:
432
+ generate_and_display(
433
+ col=col2,
434
+ generator_func=generate_webinar_script,
435
+ audience=webinar_script_audience,
436
+ product=webinar_script_product,
437
+ temperature=webinar_script_temperature,
438
+ selected_formula=selected_webinar_formula,
439
+ content_type="script",
440
+ offer=webinar_script_offer if webinar_script_offer.strip() else None,
441
+ creative_idea=creative_idea if creative_idea.strip() else None
442
+ )
443
+
444
+ # Segunda pestaña - Generador de Nombres de Webinar
445
+ with tab2:
446
+ tab2.subheader("Nombres de Webinar")
447
+
448
+ # Crear columnas para la interfaz
449
+ col1, col2 = tab2.columns([1, 2])
450
+
451
+ # Columna de entrada
452
+ with col1:
453
+ # Inputs básicos
454
+ webinar_names_audience = st.text_input("¿Quién es tu público objetivo?", placeholder="Ejemplo: Emprendedores digitales", key="webinar_names_audience")
455
+ webinar_names_product = st.text_input("¿Sobre qué tema es tu webinar?", placeholder="Ejemplo: Marketing de afiliados", key="webinar_names_product")
456
+
457
+ # Opciones avanzadas en el acordeón
458
+ with st.expander("Personaliza tus nombres de webinar"):
459
+ # Selector de fórmula
460
+ selected_name_formula_key = st.selectbox(
461
+ "Selecciona una fórmula para tus nombres",
462
+ options=list(webinar_name_formulas.keys()),
463
+ key="webinar_name_formula"
464
+ )
465
+
466
+ # Selector de ángulo
467
+ selected_angle = st.selectbox(
468
+ "Selecciona un ángulo (opcional)",
469
+ options=["NINGUNO"] + list(angles_webinar_names.keys()),
470
+ key="webinar_name_angle"
471
+ )
472
+
473
+ # Número de nombres a generar
474
+ 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")
475
+
476
+ # Slider de creatividad
477
+ webinar_names_temperature = st.slider("Creatividad", min_value=0.0, max_value=2.0, value=1.0, step=0.1, key="webinar_names_temp")
478
+
479
+ # Botón de generación
480
+ submit_webinar_names = st.button("Generar Nombres de Webinar ▶▶", key="generate_webinar_names")
481
+
482
+ selected_name_formula = webinar_name_formulas[selected_name_formula_key]
483
+
484
+ # Usar la función generate_and_display para generar y mostrar los nombres
485
+ if submit_webinar_names:
486
+ generate_and_display(
487
+ col=col2,
488
+ generator_func=generate_webinar_names,
489
+ audience=webinar_names_audience,
490
+ product=webinar_names_product,
491
+ temperature=webinar_names_temperature,
492
+ selected_formula=selected_name_formula,
493
+ content_type="names",
494
+ number_of_names=number_of_names,
495
+ selected_angle=selected_angle if selected_angle != "NINGUNO" else None
496
+ )
497