Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
@@ -184,6 +184,74 @@ def create_base_prompt(template_name, audience, product, offer=None, extra_param
|
|
184 |
|
185 |
return prompt
|
186 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
187 |
# Función auxiliar para normalizar nombres de secciones
|
188 |
def normalize_section_key(section_name):
|
189 |
"""Convierte nombres de sección a formato de clave normalizado."""
|
@@ -291,73 +359,4 @@ if submit_sales_page:
|
|
291 |
else:
|
292 |
section_key = normalize_section_key(sales_page_section)
|
293 |
if section_key in st.session_state.sections['content']:
|
294 |
-
display_generated_content(col2, st.session_state.sections['content'][section_key], "sales_page_section", sales_page_section)
|
295 |
-
|
296 |
-
|
297 |
-
def update_section_context(section_name, content):
|
298 |
-
"""Update the context for a section after it's generated."""
|
299 |
-
section_key = normalize_section_key(section_name)
|
300 |
-
|
301 |
-
# Store in content dictionary
|
302 |
-
if 'content' not in st.session_state.sections:
|
303 |
-
st.session_state.sections['content'] = {}
|
304 |
-
st.session_state.sections['content'][section_key] = content
|
305 |
-
|
306 |
-
# Store in context dictionary with timestamp
|
307 |
-
if 'context' not in st.session_state.sections:
|
308 |
-
st.session_state.sections['context'] = {}
|
309 |
-
|
310 |
-
st.session_state.sections['context'][section_key] = {
|
311 |
-
'content': content,
|
312 |
-
'timestamp': datetime.datetime.now().isoformat()
|
313 |
-
}
|
314 |
-
|
315 |
-
def get_relevant_context(current_section):
|
316 |
-
"""Get relevant context based on current section"""
|
317 |
-
context = {}
|
318 |
-
|
319 |
-
section_key = normalize_section_key(current_section)
|
320 |
-
|
321 |
-
if section_key == 'above_the_fold':
|
322 |
-
return context
|
323 |
-
|
324 |
-
specific_relationships = {
|
325 |
-
'problem': ['above_the_fold'],
|
326 |
-
'solution_&_benefits': ['problem'],
|
327 |
-
'authority': ['problem', 'solution_&_benefits'],
|
328 |
-
'offer_&_bonus': ['solution_&_benefits', 'problem'],
|
329 |
-
'social_proof': ['offer_&_bonus', 'solution_&_benefits'],
|
330 |
-
'offer_summary': ['offer_&_bonus', 'solution_&_benefits'],
|
331 |
-
'guarantees': ['offer_&_bonus', 'social_proof'],
|
332 |
-
'faq': ['offer_&_bonus', 'guarantees', 'problem'],
|
333 |
-
'closing': ['offer_&_bonus', 'guarantees', 'problem', 'solution_&_benefits']
|
334 |
-
}
|
335 |
-
|
336 |
-
section_order = [
|
337 |
-
"above_the_fold",
|
338 |
-
"problem",
|
339 |
-
"solution_&_benefits",
|
340 |
-
"authority",
|
341 |
-
"offer_&_bonus",
|
342 |
-
"social_proof",
|
343 |
-
"offer_summary",
|
344 |
-
"guarantees",
|
345 |
-
"faq",
|
346 |
-
"closing"
|
347 |
-
]
|
348 |
-
|
349 |
-
# First, add specific relationships if they exist
|
350 |
-
if section_key in specific_relationships:
|
351 |
-
for rel_section in specific_relationships[section_key]:
|
352 |
-
if rel_section in st.session_state.sections['context']:
|
353 |
-
context[rel_section] = st.session_state.sections['context'][rel_section]['content']
|
354 |
-
|
355 |
-
# Then, for any section after "above_the_fold", add previous sections as context
|
356 |
-
if section_key in section_order:
|
357 |
-
current_index = section_order.index(section_key)
|
358 |
-
if current_index > 0:
|
359 |
-
for prev_section in section_order[:current_index][-3:]:
|
360 |
-
if prev_section in st.session_state.sections['context'] and prev_section not in context:
|
361 |
-
context[prev_section] = st.session_state.sections['context'][prev_section]['content']
|
362 |
-
|
363 |
-
return context
|
|
|
184 |
|
185 |
return prompt
|
186 |
|
187 |
+
def update_section_context(section_name, content):
|
188 |
+
"""Update the context for a section after it's generated."""
|
189 |
+
section_key = normalize_section_key(section_name)
|
190 |
+
|
191 |
+
# Store in content dictionary
|
192 |
+
if 'content' not in st.session_state.sections:
|
193 |
+
st.session_state.sections['content'] = {}
|
194 |
+
st.session_state.sections['content'][section_key] = content
|
195 |
+
|
196 |
+
# Store in context dictionary with timestamp
|
197 |
+
if 'context' not in st.session_state.sections:
|
198 |
+
st.session_state.sections['context'] = {}
|
199 |
+
|
200 |
+
st.session_state.sections['context'][section_key] = {
|
201 |
+
'content': content,
|
202 |
+
'timestamp': datetime.datetime.now().isoformat()
|
203 |
+
}
|
204 |
+
|
205 |
+
def get_relevant_context(current_section):
|
206 |
+
"""Get relevant context based on current section"""
|
207 |
+
context = {}
|
208 |
+
|
209 |
+
section_key = normalize_section_key(current_section)
|
210 |
+
|
211 |
+
if section_key == 'above_the_fold':
|
212 |
+
return context
|
213 |
+
|
214 |
+
specific_relationships = {
|
215 |
+
'problem': ['above_the_fold'],
|
216 |
+
'solution_&_benefits': ['problem'],
|
217 |
+
'authority': ['problem', 'solution_&_benefits'],
|
218 |
+
'offer_&_bonus': ['solution_&_benefits', 'problem'],
|
219 |
+
'social_proof': ['offer_&_bonus', 'solution_&_benefits'],
|
220 |
+
'offer_summary': ['offer_&_bonus', 'solution_&_benefits'],
|
221 |
+
'guarantees': ['offer_&_bonus', 'social_proof'],
|
222 |
+
'faq': ['offer_&_bonus', 'guarantees', 'problem'],
|
223 |
+
'closing': ['offer_&_bonus', 'guarantees', 'problem', 'solution_&_benefits']
|
224 |
+
}
|
225 |
+
|
226 |
+
section_order = [
|
227 |
+
"above_the_fold",
|
228 |
+
"problem",
|
229 |
+
"solution_&_benefits",
|
230 |
+
"authority",
|
231 |
+
"offer_&_bonus",
|
232 |
+
"social_proof",
|
233 |
+
"offer_summary",
|
234 |
+
"guarantees",
|
235 |
+
"faq",
|
236 |
+
"closing"
|
237 |
+
]
|
238 |
+
|
239 |
+
# First, add specific relationships if they exist
|
240 |
+
if section_key in specific_relationships:
|
241 |
+
for rel_section in specific_relationships[section_key]:
|
242 |
+
if rel_section in st.session_state.sections['context']:
|
243 |
+
context[rel_section] = st.session_state.sections['context'][rel_section]['content']
|
244 |
+
|
245 |
+
# Then, for any section after "above_the_fold", add previous sections as context
|
246 |
+
if section_key in section_order:
|
247 |
+
current_index = section_order.index(section_key)
|
248 |
+
if current_index > 0:
|
249 |
+
for prev_section in section_order[:current_index][-3:]:
|
250 |
+
if prev_section in st.session_state.sections['context'] and prev_section not in context:
|
251 |
+
context[prev_section] = st.session_state.sections['context'][prev_section]['content']
|
252 |
+
|
253 |
+
return context
|
254 |
+
|
255 |
# Función auxiliar para normalizar nombres de secciones
|
256 |
def normalize_section_key(section_name):
|
257 |
"""Convierte nombres de sección a formato de clave normalizado."""
|
|
|
359 |
else:
|
360 |
section_key = normalize_section_key(sales_page_section)
|
361 |
if section_key in st.session_state.sections['content']:
|
362 |
+
display_generated_content(col2, st.session_state.sections['content'][section_key], "sales_page_section", sales_page_section)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|