Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -139,6 +139,12 @@ def generate_fb_ad(target_audience, product, temperature, selected_formula, sele
|
|
139 |
headline=headline # Pass the headline to the instruction creator
|
140 |
)
|
141 |
|
|
|
|
|
|
|
|
|
|
|
|
|
142 |
# Si hay contenido de archivo, a帽adirlo a la instrucci贸n
|
143 |
if file_content:
|
144 |
ad_instruction += f"\n\nAdem谩s, utiliza la siguiente informaci贸n como referencia para crear el anuncio:\n\n{file_content[:max_file_chars]}"
|
@@ -348,10 +354,17 @@ if submit_ad:
|
|
348 |
st.error("Error al generar el anuncio")
|
349 |
else:
|
350 |
# Clean the generated ad text to remove any random characters
|
|
|
|
|
|
|
351 |
# Remove any single letters that appear on their own line
|
352 |
-
cleaned_ad = "\n".join([line for line in
|
353 |
if not (len(line.strip()) == 1 and line.strip().isalpha())])
|
354 |
|
|
|
|
|
|
|
|
|
355 |
# Display only the ad without separate headline and without storing in session state
|
356 |
st.markdown(f"""
|
357 |
<div style="{styles['results_container']}">
|
|
|
139 |
headline=headline # Pass the headline to the instruction creator
|
140 |
)
|
141 |
|
142 |
+
# Ensure the headline is properly integrated in the instruction
|
143 |
+
if headline:
|
144 |
+
ad_instruction = ad_instruction.replace("[HEADLINE]", headline)
|
145 |
+
# Add explicit instruction to use the headline
|
146 |
+
ad_instruction += f"\n\nUtiliza este titular exactamente como est谩 escrito: '{headline}'"
|
147 |
+
|
148 |
# Si hay contenido de archivo, a帽adirlo a la instrucci贸n
|
149 |
if file_content:
|
150 |
ad_instruction += f"\n\nAdem谩s, utiliza la siguiente informaci贸n como referencia para crear el anuncio:\n\n{file_content[:max_file_chars]}"
|
|
|
354 |
st.error("Error al generar el anuncio")
|
355 |
else:
|
356 |
# Clean the generated ad text to remove any random characters
|
357 |
+
# First, remove any markdown code block markers
|
358 |
+
cleaned_ad = generated_ad.replace("```", "").replace("text", "")
|
359 |
+
|
360 |
# Remove any single letters that appear on their own line
|
361 |
+
cleaned_ad = "\n".join([line for line in cleaned_ad.split("\n")
|
362 |
if not (len(line.strip()) == 1 and line.strip().isalpha())])
|
363 |
|
364 |
+
# Remove any lines with just symbols or very short content
|
365 |
+
cleaned_ad = "\n".join([line for line in cleaned_ad.split("\n")
|
366 |
+
if not (len(line.strip()) <= 3 and not line.strip().isalnum())])
|
367 |
+
|
368 |
# Display only the ad without separate headline and without storing in session state
|
369 |
st.markdown(f"""
|
370 |
<div style="{styles['results_container']}">
|