JeCabrera commited on
Commit
25d1401
·
verified ·
1 Parent(s): f32c73b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +120 -57
app.py CHANGED
@@ -1,59 +1,122 @@
1
- system_prompt = """You are a world-class expert copywriter, experienced in creating benefits that emotionally connect and address the desires, problems, and motivations of the target audience.
2
-
3
- OBJECTIVE:
4
- - Generate convincing and specific benefit bullets in Spanish
5
- - Connect emotionally with the audience
6
- - Address real desires, problems, and motivations
7
- - Maintain natural and conversational language
8
- - Orient each benefit towards action
9
-
10
- FORMAT RULES:
11
- - Each benefit must start with "• "
12
- - One benefit per line
13
- - No numbers at the beginning
14
- - No explanations or categories
15
- - Add a line break between each benefit
16
- - Never include : symbols in bullets
17
- - Each benefit must be a complete and concise phrase
18
-
19
- BENEFIT STRUCTURE:
20
- - Must be relevant to target audience
21
- - Must show a specific result
22
- - Must include an emotional element
23
- - Must eliminate an objection or pain point
24
- - Must inspire immediate action
25
-
26
- EJEMPLO DE FORMATO:
27
- Transforma tu negocio con estrategias probadas que duplican tus ingresos en 90 días, sin sacrificar tu tiempo en familia.
28
-
29
- • Domina las técnicas más efectivas para conquistar tu mercado, mientras mantienes el equilibrio entre trabajo y vida personal.
30
-
31
- • Implementa sistemas automatizados que hacen crecer tu empresa incluso mientras duermes, eliminando la necesidad de trabajar más horas.
32
-
33
- IMPORTANT:
34
- - Each benefit must be unique and specific
35
- - Avoid repetitions and generalities
36
- - Maintain a persuasive but honest tone
37
- - Adapt language to audience comprehension level
38
- - Focus on tangible and measurable results
39
- """
40
 
41
- def create_instruction(number_of_benefits, target_audience, product, selected_formula, selected_angle):
42
- angle_instruction = ""
43
- if selected_angle["description"] != "Generate the bullet without any specific angle":
44
- angle_instruction = f"\nApply this angle: {selected_angle['description']}\nStyle: {selected_angle['style']}\nUse these keywords as inspiration: {', '.join(selected_angle['keywords'])}"
 
 
 
 
45
 
46
- return (
47
- f"{system_prompt}\n\n"
48
- f"Your task is to create {number_of_benefits} irresistible benefits designed for {target_audience}. "
49
- f"The goal is to show how {product} can transform the reader's life, connecting naturally and emotionally. "
50
- f"Avoid using literal or repetitive mentions, and highlight concrete solutions, showing how the product removes obstacles or satisfies real desires. "
51
- f"{angle_instruction}\n"
52
- f"IMPORTANT: Keep bullets short and direct, maximum 100 characters per bullet. "
53
- f"Use the selected formula as a guide:\n\n{selected_formula['description']}\n\n"
54
- f"Get inspired by these examples:\n"
55
- f"- {selected_formula['examples'][0]}\n"
56
- f"- {selected_formula['examples'][1]}\n"
57
- f"- {selected_formula['examples'][2]}\n\n"
58
- f"Your goal is to inspire desire and action, avoiding explanations or categories in the response."
59
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from dotenv import load_dotenv
2
+ import streamlit as st
3
+ import os
4
+ import google.generativeai as genai
5
+ from bullet_formulas import bullet_formulas
6
+ from style import styles
7
+ from prompts import create_instruction
8
+ from angles import bullet_angles
9
+
10
+ # Cargar las variables de entorno
11
+ load_dotenv()
12
+
13
+ # Configurar la API de Google
14
+ genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
15
+
16
+ # Función para generar bullets de beneficios
17
+ @st.cache_resource
18
+ def get_model(temperature):
19
+ generation_config = {
20
+ "temperature": temperature,
21
+ }
22
+ return genai.GenerativeModel('gemini-2.0-flash', generation_config=generation_config)
23
+
24
+ # Update the generate_benefits function to include selected_angle
25
+ def generate_benefits(number_of_benefits, target_audience, product, temperature, selected_formula, selected_angle):
26
+ if not target_audience or not product:
27
+ return "Por favor, completa todos los campos requeridos."
 
 
 
 
 
 
 
 
 
 
 
 
28
 
29
+ model = get_model(temperature)
30
+ benefits_instruction = create_instruction(
31
+ number_of_benefits,
32
+ target_audience,
33
+ product,
34
+ selected_formula,
35
+ selected_angle
36
+ )
37
 
38
+ response = model.generate_content([benefits_instruction], generation_config={"temperature": temperature})
39
+ return response.parts[0].text if response and response.parts else "Error generating content."
40
+
41
+ # Configurar la interfaz de usuario con Streamlit
42
+ st.set_page_config(page_title="Bullet Benefits Generator", layout="wide")
43
+
44
+ # Leer el contenido del archivo manual.md
45
+ with open("manual.md", "r", encoding="utf-8") as file:
46
+ manual_content = file.read()
47
+
48
+ # Mostrar el contenido del manual en el sidebar
49
+ st.sidebar.markdown(manual_content)
50
+
51
+ # Ocultar elementos de la interfaz
52
+ st.markdown(styles["main_layout"], unsafe_allow_html=True)
53
+
54
+ # Centrar el título y el subtítulo
55
+ st.markdown("<h1 style='text-align: center;'>Bullet Benefits Generator</h1>", unsafe_allow_html=True)
56
+ st.markdown("<h4 style='text-align: center;'>Transforma características en beneficios irresistibles que conectan emocionalmente con tu audiencia.</h4>", unsafe_allow_html=True)
57
+
58
+ # Añadir CSS personalizado para el botón
59
+ st.markdown(styles["button"], unsafe_allow_html=True)
60
+
61
+ # Crear columnas
62
+ col1, col2 = st.columns([1, 2])
63
+
64
+ # Columnas de entrada
65
+ # Inside the column section
66
+ with col1:
67
+ target_audience = st.text_input("¿Quién es tu público objetivo?", placeholder="Ejemplo: Estudiantes Universitarios")
68
+ product = st.text_input("¿Qué producto tienes en mente?", placeholder="Ejemplo: Curso de Inglés")
69
+ number_of_benefits = st.selectbox("Número de Beneficios", options=[1, 2, 3, 4, 5, 6, 7, 8, 9, 10], index=4)
70
+
71
+ # Fix indentation - remove extra spaces
72
+ with st.expander("Opciones avanzadas"):
73
+ selected_formula_key = st.selectbox(
74
+ "Tipo de bullet", # Added label
75
+ options=list(bullet_formulas.keys()),
76
+ label_visibility="visible"
77
+ )
78
+ selected_formula = bullet_formulas[selected_formula_key]
79
+
80
+ selected_angle_key = st.selectbox(
81
+ "Ángulo del bullet", # Added label
82
+ options=list(bullet_angles.keys()),
83
+ label_visibility="visible"
84
+ )
85
+ selected_angle = bullet_angles[selected_angle_key]
86
+
87
+ temperature = st.slider(
88
+ "Nivel de creatividad", # Added label
89
+ min_value=0.0,
90
+ max_value=2.0,
91
+ value=1.0,
92
+ step=0.1,
93
+ label_visibility="visible"
94
+ )
95
+
96
+ submit = st.button("GENERAR LOS BULLETS POINTS")
97
+
98
+ # Mostrar los beneficios generados
99
+ # Update the submit section to include selected_angle
100
+ if submit:
101
+ if target_audience and product and selected_formula:
102
+ with st.spinner('Generando beneficios...'):
103
+ generated_benefits = generate_benefits(
104
+ number_of_benefits,
105
+ target_audience,
106
+ product,
107
+ temperature,
108
+ selected_formula,
109
+ selected_angle
110
+ )
111
+ if not isinstance(generated_benefits, str):
112
+ col2.error("Error al generar beneficios")
113
+ else:
114
+ col2.markdown(f"""
115
+ <div style="{styles['results_container']}">
116
+ <h3>Beneficios Generados:</h3>
117
+ <p>{generated_benefits}</p>
118
+ </div>
119
+ """, unsafe_allow_html=True)
120
+
121
+ else:
122
+ col2.warning("Por favor, completa todos los campos antes de generar beneficios.")