Spaces:
Sleeping
Sleeping
Upload 4 files
Browse files- app.py +3 -29
- formulas.py +161 -81
app.py
CHANGED
@@ -5,7 +5,6 @@ import time
|
|
5 |
from dotenv import load_dotenv
|
6 |
from styles import get_custom_css, get_response_html_wrapper
|
7 |
from formulas import offer_formulas
|
8 |
-
from prompts import create_offer_instruction, create_promise_instruction
|
9 |
import PyPDF2
|
10 |
import docx
|
11 |
from PIL import Image
|
@@ -21,8 +20,8 @@ load_dotenv()
|
|
21 |
genai.configure(api_key=os.getenv('GOOGLE_API_KEY'))
|
22 |
model = genai.GenerativeModel('gemini-2.0-flash')
|
23 |
|
24 |
-
#
|
25 |
-
|
26 |
|
27 |
# Initialize session state variables if they don't exist
|
28 |
if 'submitted' not in st.session_state:
|
@@ -197,37 +196,12 @@ with col2:
|
|
197 |
product_name = "Producto/Servicio"
|
198 |
|
199 |
# Get the instruction using the formula
|
200 |
-
# Usar la función actualizada
|
201 |
-
# In the generate_offer function or wherever the error is occurring
|
202 |
-
# The function definition needs proper indentation for its body
|
203 |
-
# Where you're generating the offer
|
204 |
-
def generate_offer():
|
205 |
-
# Get necessary variables
|
206 |
-
selected_formula_name = st.session_state.formula_type
|
207 |
-
avatar_description = st.session_state.target_audience
|
208 |
-
product_name = st.session_state.product_service
|
209 |
-
|
210 |
-
# Create the base instruction
|
211 |
instruction = create_offer_instruction(
|
212 |
avatar_description=avatar_description,
|
213 |
product_name=product_name,
|
214 |
-
selected_formula_name=
|
215 |
-
offer_formulas=offer_formulas
|
216 |
)
|
217 |
|
218 |
-
# Add file content if available
|
219 |
-
if st.session_state.input_type in ["file", "both"]:
|
220 |
-
additional_context = f"\n\nAdditional context from uploaded file:\n{st.session_state.file_content}"
|
221 |
-
instruction += additional_context
|
222 |
-
|
223 |
-
# Generate the response
|
224 |
-
response = model.generate_content(instruction)
|
225 |
-
offer_result = response.text
|
226 |
-
|
227 |
-
# Update session state
|
228 |
-
st.session_state.offer_result = offer_result
|
229 |
-
st.session_state.generated = True
|
230 |
-
|
231 |
# Add additional context based on input type
|
232 |
if st.session_state.input_type == "manual":
|
233 |
additional_context = f"""
|
|
|
5 |
from dotenv import load_dotenv
|
6 |
from styles import get_custom_css, get_response_html_wrapper
|
7 |
from formulas import offer_formulas
|
|
|
8 |
import PyPDF2
|
9 |
import docx
|
10 |
from PIL import Image
|
|
|
20 |
genai.configure(api_key=os.getenv('GOOGLE_API_KEY'))
|
21 |
model = genai.GenerativeModel('gemini-2.0-flash')
|
22 |
|
23 |
+
# Import the create_offer_instruction function from formulas
|
24 |
+
from formulas import create_offer_instruction, offer_formulas
|
25 |
|
26 |
# Initialize session state variables if they don't exist
|
27 |
if 'submitted' not in st.session_state:
|
|
|
196 |
product_name = "Producto/Servicio"
|
197 |
|
198 |
# Get the instruction using the formula
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
199 |
instruction = create_offer_instruction(
|
200 |
avatar_description=avatar_description,
|
201 |
product_name=product_name,
|
202 |
+
selected_formula_name=st.session_state.formula_type
|
|
|
203 |
)
|
204 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
205 |
# Add additional context based on input type
|
206 |
if st.session_state.input_type == "manual":
|
207 |
additional_context = f"""
|
formulas.py
CHANGED
@@ -1,3 +1,155 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
offer_formulas = {
|
2 |
"Oferta Dorada": {
|
3 |
"description": """
|
@@ -38,6 +190,13 @@ This is the most important part. You must create a specific, quantifiable promis
|
|
38 |
#### 3 **Benefit + Authority + Time or Effort**
|
39 |
In this part, we explain the result they will obtain, supported by an authority factor (proven method, studies, experience, validations) and establishing a time frame or necessary effort to achieve it.
|
40 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
41 |
**Incorrect example:**
|
42 |
"Grow your business with our strategy." (Doesn't say how long it will take or how reliable the strategy is).
|
43 |
|
@@ -92,35 +251,7 @@ In this part, we explain the result they will obtain, supported by an authority
|
|
92 |
CONSIGUE 100 NUEVOS SEGUIDORES CUALIFICADOS POR SEMANA Y CONVIERTE EL 10% EN LEADS INTERESADOS EN TUS SERVICIOS.
|
93 |
|
94 |
Usando nuestra estrategia de contenido viral alcanzarás visibilidad exponencial transformando tu presencia en redes en un canal de captación automático en menos de 30 días."""
|
95 |
-
]
|
96 |
-
"custom_instructions": """
|
97 |
-
SPECIFIC INSTRUCTIONS FOR THIS FORMULA:
|
98 |
-
1. ATTENTION HOOK HANDLING:
|
99 |
-
- Analyze the avatar_description DEEPLY to understand their specific pain points, frustrations, and desires
|
100 |
-
- Select a powerful attention hook that DIRECTLY connects with the avatar's current reality
|
101 |
-
- Use statements, statistics, or shocking revelations, questions as hooks
|
102 |
-
- CUSTOMIZE the hook specifically for this avatar - don't use generic examples
|
103 |
-
- The hook MUST address the SAME problem that your promise will solve
|
104 |
-
|
105 |
-
2. MAINTAIN THEMATIC CONSISTENCY:
|
106 |
-
- The attention hook, quantifiable promise, and benefit statement MUST all address the SAME problem
|
107 |
-
- Create a LOGICAL PROGRESSION from problem (hook) to solution (promise) to implementation (benefit)
|
108 |
-
|
109 |
-
3. Create a compelling QUANTIFIABLE PROMISE that:
|
110 |
-
- Is written COMPLETELY IN CAPITAL LETTERS
|
111 |
-
- Includes concrete numbers (money, time, results)
|
112 |
-
- Uses powerful action verbs (EARN, MULTIPLY, ACHIEVE, MASTER)
|
113 |
-
- Specifies the exact result they will obtain
|
114 |
-
- Optionally includes time or effort required
|
115 |
-
- NEVER uses exclamation marks (!)
|
116 |
-
- DIRECTLY addresses the same problem mentioned in the hook
|
117 |
-
|
118 |
-
4. Craft a benefit statement that:
|
119 |
-
- Clearly explains the result they will obtain
|
120 |
-
- Includes an authority element (proven method, studies, experience)
|
121 |
-
- Establishes a realistic timeframe or effort needed
|
122 |
-
- CONTINUES the same theme established in the hook and promise
|
123 |
-
"""
|
124 |
},
|
125 |
"Fórmula Sueño-Obstáculo": {
|
126 |
"description": """
|
@@ -166,57 +297,6 @@ This formula connects directly with the client's desires and concerns:
|
|
166 |
**Structure Format (Classic example):**
|
167 |
"Se trata de un (training, product or service) llamado ("name of your solution") que te va a permitir (big dream) aún y cuando (big obstacle)"
|
168 |
""",
|
169 |
-
"examples": [
|
170 |
-
"Se trata de un entrenamiento llamado \"Método Flujo Creativo\" que te va a permitir escribir contenido de alto impacto todos los días aún y cuando creas que no tienes talento para la escritura.",
|
171 |
-
"Se trata de un servicio llamado \"Transformación Financiera Total\" que te va a permitir duplicar tus ingresos en 90 días aún y cuando ahora mismo estés endeudado hasta el cuello.",
|
172 |
-
"Se trata de un producto llamado \"Sistema de Meditación Rápida\" que te va a permitir alcanzar estados profundos de calma en solo 5 minutos aún y cuando tengas una mente hiperactiva que no para de pensar."
|
173 |
-
],
|
174 |
-
"custom_instructions": """
|
175 |
-
SPECIFIC INSTRUCTIONS FOR THIS FORMULA:
|
176 |
-
1. PRODUCT/SERVICE NAME HANDLING:
|
177 |
-
- If product_name is provided and not empty, use it EXACTLY as written
|
178 |
-
- If product_name is empty, generic (like "Producto/Servicio"), or contains placeholders, CREATE a compelling name that:
|
179 |
-
* Reflects the target audience's desires and challenges
|
180 |
-
* Communicates the main benefit or transformation
|
181 |
-
* Sounds professional and memorable
|
182 |
-
* Is specific to the niche or industry mentioned in avatar_description
|
183 |
-
- If product_name contains a full phrase like "Un curso llamado Inglés sin problemas", extract only the real name ("Inglés sin problemas")
|
184 |
-
|
185 |
-
2. Analyze ALL available information:
|
186 |
-
- Product/service name (product_name variable) or create one if needed
|
187 |
-
- Target audience description (avatar_description)
|
188 |
-
- Content from uploaded files (if any)
|
189 |
-
|
190 |
-
3. Determine the most appropriate type (curso, webinar, entrenamiento, etc.) based on:
|
191 |
-
- Any type mentioned in product_name
|
192 |
-
- The nature of the solution described in avatar_description
|
193 |
-
- The most suitable format for the target audience's needs
|
194 |
-
|
195 |
-
4. Create a comprehensive offer by combining:
|
196 |
-
- The appropriate type (determined in step 3)
|
197 |
-
- The exact product name (if provided) or your created name (if needed)
|
198 |
-
- A compelling dream based on avatar_description
|
199 |
-
- A relevant obstacle based on avatar_description
|
200 |
-
|
201 |
-
5. The dream should be ambitious but believable, incorporating:
|
202 |
-
- Target audience desires from avatar_description
|
203 |
-
- Explicit goals mentioned in uploaded content (if any)
|
204 |
-
|
205 |
-
6. The obstacle should reflect:
|
206 |
-
- Real problems mentioned in avatar_description
|
207 |
-
- Challenges that would normally prevent achieving the dream
|
208 |
-
|
209 |
-
7. IMPORTANT: Vary the way you start the phrase. Instead of always using "Se trata de un...", use different openings such as:
|
210 |
-
- "Presentamos un..."
|
211 |
-
- "Te ofrecemos un..."
|
212 |
-
- "Descubre nuestro..."
|
213 |
-
- "Conoce el..."
|
214 |
-
- "Hemos creado un..."
|
215 |
-
- "Imagina tener acceso a un..."
|
216 |
-
- "Por fin existe un..."
|
217 |
-
- "Ahora puedes acceder a un..."
|
218 |
-
- "Tenemos para ti un..."
|
219 |
-
- "Disfruta de un..."
|
220 |
-
"""
|
221 |
}
|
222 |
}
|
|
|
1 |
+
# The function create_offer_instruction remains unchanged
|
2 |
+
# Remove the random import since we no longer need it
|
3 |
+
# import random
|
4 |
+
|
5 |
+
# Add this function at the beginning of the file
|
6 |
+
# Define a single system prompt at the top of the file
|
7 |
+
offer_system_prompt = """You are a world-class expert copywriter, experienced in creating compelling offers that connect emotionally with the target audience.
|
8 |
+
|
9 |
+
OBJECTIVE:
|
10 |
+
- Generate a convincing offer in Spanish
|
11 |
+
- Connect emotionally with the audience
|
12 |
+
- Address real desires, problems, and motivations
|
13 |
+
- Maintain natural and conversational language
|
14 |
+
|
15 |
+
CRITICAL OUTPUT RULES:
|
16 |
+
- Output ONLY the offer itself with NO introductory text, explanations, or additional commentary
|
17 |
+
- Start directly with the attention hook or opening phrase
|
18 |
+
- The entire response should be ONLY the offer itself following the formula structure
|
19 |
+
- Do not include phrases like "Aquí tienes una oferta convincente" or "Esta es tu oferta"
|
20 |
+
"""
|
21 |
+
|
22 |
+
def create_offer_instruction(avatar_description, product_name, selected_formula_name):
|
23 |
+
"""
|
24 |
+
Creates instructions for generating an offer based on the selected formula.
|
25 |
+
|
26 |
+
Args:
|
27 |
+
avatar_description: Description of the target audience
|
28 |
+
product_name: Name of the product or service
|
29 |
+
selected_formula_name: Name of the formula to use ("Fórmula Sueño-Obstáculo" or "Oferta Dorada")
|
30 |
+
|
31 |
+
Returns:
|
32 |
+
str: Complete instruction for generating the offer
|
33 |
+
"""
|
34 |
+
# Get the selected formula
|
35 |
+
selected_formula = offer_formulas[selected_formula_name]
|
36 |
+
|
37 |
+
# Add specific instructions for each formula
|
38 |
+
additional_instructions = ""
|
39 |
+
if selected_formula_name == "Fórmula Sueño-Obstáculo":
|
40 |
+
additional_instructions = """
|
41 |
+
SPECIFIC INSTRUCTIONS FOR THIS FORMULA:
|
42 |
+
1. PRODUCT/SERVICE NAME HANDLING:
|
43 |
+
- If product_name is provided and not empty, use it EXACTLY as written
|
44 |
+
- If product_name is empty, generic (like "Producto/Servicio"), or contains placeholders, CREATE a compelling name that:
|
45 |
+
* Reflects the target audience's desires and challenges
|
46 |
+
* Communicates the main benefit or transformation
|
47 |
+
* Sounds professional and memorable
|
48 |
+
* Is specific to the niche or industry mentioned in avatar_description
|
49 |
+
- If product_name contains a full phrase like "Un curso llamado Inglés sin problemas", extract only the real name ("Inglés sin problemas")
|
50 |
+
|
51 |
+
2. Analyze ALL available information:
|
52 |
+
- Product/service name (product_name variable) or create one if needed
|
53 |
+
- Target audience description (avatar_description)
|
54 |
+
- Content from uploaded files (if any)
|
55 |
+
|
56 |
+
3. Determine the most appropriate type (curso, webinar, entrenamiento, etc.) based on:
|
57 |
+
- Any type mentioned in product_name
|
58 |
+
- The nature of the solution described in avatar_description
|
59 |
+
- The most suitable format for the target audience's needs
|
60 |
+
|
61 |
+
4. Create a comprehensive offer by combining:
|
62 |
+
- The appropriate type (determined in step 3)
|
63 |
+
- The exact product name (if provided) or your created name (if needed)
|
64 |
+
- A compelling dream based on avatar_description
|
65 |
+
- A relevant obstacle based on avatar_description
|
66 |
+
|
67 |
+
5. The dream should be ambitious but believable, incorporating:
|
68 |
+
- Target audience desires from avatar_description
|
69 |
+
- Explicit goals mentioned in uploaded content (if any)
|
70 |
+
|
71 |
+
6. The obstacle should reflect:
|
72 |
+
- Real problems mentioned in avatar_description
|
73 |
+
- Challenges that would normally prevent achieving the dream
|
74 |
+
|
75 |
+
7. IMPORTANT: Vary the way you start the phrase. Instead of always using "Se trata de un...", use different openings such as:
|
76 |
+
- "Presentamos un..."
|
77 |
+
- "Te ofrecemos un..."
|
78 |
+
- "Descubre nuestro..."
|
79 |
+
- "Conoce el..."
|
80 |
+
- "Hemos creado un..."
|
81 |
+
- "Imagina tener acceso a un..."
|
82 |
+
- "Por fin existe un..."
|
83 |
+
- "Ahora puedes acceder a un..."
|
84 |
+
- "Tenemos para ti un..."
|
85 |
+
- "Disfruta de un..."
|
86 |
+
"""
|
87 |
+
|
88 |
+
elif selected_formula_name == "Oferta Dorada":
|
89 |
+
additional_instructions = """
|
90 |
+
SPECIFIC INSTRUCTIONS FOR THIS FORMULA:
|
91 |
+
1. ATTENTION HOOK HANDLING:
|
92 |
+
- Analyze the avatar_description DEEPLY to understand their specific pain points, frustrations, and desires
|
93 |
+
- Select a powerful attention hook that DIRECTLY connects with the avatar's current reality
|
94 |
+
- DO NOT use questions as hooks - use statements, statistics, or shocking revelations instead
|
95 |
+
- CUSTOMIZE the hook specifically for this avatar - don't use generic examples
|
96 |
+
- The hook MUST address the SAME problem that your promise will solve
|
97 |
+
|
98 |
+
Choose randomly from these statement hooks and CUSTOMIZE for your avatar:
|
99 |
+
- "El 83% de los [avatar's profession/role] pierden [specific resource] en [specific activity] que nadie aprovecha."
|
100 |
+
- "9 de cada 10 [avatar's field] fracasan en sus primeros 6 meses por este error."
|
101 |
+
- "Lo que nadie te dice sobre [avatar's challenge] es que la mayoría fracasa en los primeros 3 meses."
|
102 |
+
- "El secreto que [competitors/industry] no quieren que sepas sobre [avatar's goal]."
|
103 |
+
- "Tu [avatar's current strategy/approach] está ahuyentando a tus [avatar's desired outcome]."
|
104 |
+
- "Mientras algunos [positive outcome], tú sigues [negative current situation]."
|
105 |
+
- "La mayoría de [current solutions] son una pérdida total de [resources]."
|
106 |
+
- "Hace 6 meses estaba exactamente donde tú estás: [avatar's current struggle]."
|
107 |
+
|
108 |
+
2. MAINTAIN THEMATIC CONSISTENCY:
|
109 |
+
- The attention hook, quantifiable promise, and benefit statement MUST all address the SAME problem
|
110 |
+
- Create a LOGICAL PROGRESSION from problem (hook) to solution (promise) to implementation (benefit)
|
111 |
+
|
112 |
+
3. Create a compelling QUANTIFIABLE PROMISE that:
|
113 |
+
- Is written COMPLETELY IN CAPITAL LETTERS
|
114 |
+
- Includes concrete numbers (money, time, results)
|
115 |
+
- Uses powerful action verbs (EARN, MULTIPLY, ACHIEVE, MASTER)
|
116 |
+
- Specifies the exact result they will obtain
|
117 |
+
- Optionally includes time or effort required
|
118 |
+
- NEVER uses exclamation marks (!)
|
119 |
+
- DIRECTLY addresses the same problem mentioned in the hook
|
120 |
+
|
121 |
+
4. Craft a benefit statement that:
|
122 |
+
- Clearly explains the result they will obtain
|
123 |
+
- Includes an authority element (proven method, studies, experience)
|
124 |
+
- Establishes a realistic timeframe or effort needed
|
125 |
+
- CONTINUES the same theme established in the hook and promise
|
126 |
+
"""
|
127 |
+
|
128 |
+
# Create the instruction using the system prompt at the beginning
|
129 |
+
instruction = f"""{offer_system_prompt}
|
130 |
+
|
131 |
+
FORMULA TO USE:
|
132 |
+
{selected_formula["description"]}
|
133 |
+
|
134 |
+
{additional_instructions}
|
135 |
+
|
136 |
+
PRODUCT/SERVICE:
|
137 |
+
{product_name}
|
138 |
+
|
139 |
+
TARGET AUDIENCE:
|
140 |
+
{avatar_description}
|
141 |
+
|
142 |
+
Create a compelling offer following the formula structure exactly.
|
143 |
+
"""
|
144 |
+
|
145 |
+
# Add examples if available
|
146 |
+
if selected_formula.get("examples") and len(selected_formula["examples"]) > 0:
|
147 |
+
examples_text = "\n\n".join([f"Example {i+1}:\n{example}" for i, example in enumerate(selected_formula["examples"][:3])])
|
148 |
+
instruction += f"\n\nGet inspired by these examples:\n{examples_text}"
|
149 |
+
|
150 |
+
return instruction
|
151 |
+
|
152 |
+
# The rest of your offer_formulas dictionary remains unchanged
|
153 |
offer_formulas = {
|
154 |
"Oferta Dorada": {
|
155 |
"description": """
|
|
|
190 |
#### 3 **Benefit + Authority + Time or Effort**
|
191 |
In this part, we explain the result they will obtain, supported by an authority factor (proven method, studies, experience, validations) and establishing a time frame or necessary effort to achieve it.
|
192 |
|
193 |
+
**Structure Formats:**
|
194 |
+
1. "[Feature] para que puedas [Benefit] con lo que [Meaning]"
|
195 |
+
2. "Con [Feature] podrás [Benefit] permitiéndote [Meaning]"
|
196 |
+
3. "Gracias a [Feature] lograrás [Benefit] haciendo que [Meaning]"
|
197 |
+
4. "Mediante [Feature] conseguirás [Benefit] lo que significa [Meaning]"
|
198 |
+
5. "Usando [Feature] alcanzarás [Benefit] transformando [Meaning]"
|
199 |
+
|
200 |
**Incorrect example:**
|
201 |
"Grow your business with our strategy." (Doesn't say how long it will take or how reliable the strategy is).
|
202 |
|
|
|
251 |
CONSIGUE 100 NUEVOS SEGUIDORES CUALIFICADOS POR SEMANA Y CONVIERTE EL 10% EN LEADS INTERESADOS EN TUS SERVICIOS.
|
252 |
|
253 |
Usando nuestra estrategia de contenido viral alcanzarás visibilidad exponencial transformando tu presencia en redes en un canal de captación automático en menos de 30 días."""
|
254 |
+
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
255 |
},
|
256 |
"Fórmula Sueño-Obstáculo": {
|
257 |
"description": """
|
|
|
297 |
**Structure Format (Classic example):**
|
298 |
"Se trata de un (training, product or service) llamado ("name of your solution") que te va a permitir (big dream) aún y cuando (big obstacle)"
|
299 |
""",
|
300 |
+
"examples": []
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
301 |
}
|
302 |
}
|