Spaces:
Sleeping
Sleeping
Upload 19 files
Browse files
app.py
CHANGED
@@ -19,16 +19,19 @@ def initialize_model(temperature=1.0):
|
|
19 |
)
|
20 |
|
21 |
# Initialize session state variables at the app level
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
|
|
|
|
|
|
32 |
|
33 |
# Funci贸n para generar contenido y procesar el JSON
|
34 |
def generate_content(prompt, temperature=1.0):
|
@@ -54,8 +57,6 @@ def generate_content(prompt, temperature=1.0):
|
|
54 |
json_data = json.loads(json_str.strip())
|
55 |
|
56 |
# Store the JSON data in session state
|
57 |
-
if 'metadata' not in st.session_state:
|
58 |
-
st.session_state.metadata = {}
|
59 |
st.session_state.metadata = json_data
|
60 |
|
61 |
# Update avatar details and other metadata elements
|
@@ -86,7 +87,6 @@ def display_generated_content(column, content, key_prefix):
|
|
86 |
copy_button_key = f"{key_prefix}_copy_button"
|
87 |
if column.button("Copiar al portapapeles", key=copy_button_key):
|
88 |
# Use JavaScript to copy to clipboard
|
89 |
-
# Fix: Escape backticks properly in JavaScript without using backslash in f-string
|
90 |
content_escaped = content.replace("`", "\\`")
|
91 |
js_code = f"""
|
92 |
<script>
|
@@ -96,12 +96,222 @@ def display_generated_content(column, content, key_prefix):
|
|
96 |
column.components.html(js_code, height=0)
|
97 |
column.success("隆Contenido copiado al portapapeles!")
|
98 |
|
99 |
-
#
|
100 |
-
|
101 |
-
|
102 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
103 |
|
104 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
105 |
if submit_sales_page:
|
106 |
# Validar entradas
|
107 |
if validate_inputs(sales_page_audience, sales_page_product):
|
@@ -114,20 +324,6 @@ if submit_sales_page:
|
|
114 |
# Crear un contenedor para el spinner en la columna 2
|
115 |
with col2:
|
116 |
with st.spinner("Generando secci贸n de p谩gina de ventas...", show_time=True):
|
117 |
-
# Mapear la selecci贸n a la funci贸n correspondiente
|
118 |
-
section_functions = {
|
119 |
-
"Above the Fold (Encabezado)": generate_above_the_fold,
|
120 |
-
"Problem (Problema)": generate_problem_section,
|
121 |
-
"Solution & Benefits (Soluci贸n y Beneficios)": generate_solution_section,
|
122 |
-
"Authority (Autoridad)": generate_authority_section,
|
123 |
-
"Offer & Bonus (Oferta y Bonus)": generate_offer_section,
|
124 |
-
"Social Proof (Prueba Social)": generate_social_proof_section,
|
125 |
-
"Guarantees (Garant铆as)": generate_guarantees_section,
|
126 |
-
"Call to Action (Llamada a la Acci贸n)": generate_cta_section,
|
127 |
-
"P.S. (Post-Data)": generate_ps_section,
|
128 |
-
"Final Call to Action (Llamada Final)": generate_final_cta_section
|
129 |
-
}
|
130 |
-
|
131 |
# Obtener la funci贸n correspondiente
|
132 |
generator_func = section_functions[sales_page_section]
|
133 |
|
|
|
19 |
)
|
20 |
|
21 |
# Initialize session state variables at the app level
|
22 |
+
session_state_vars = {
|
23 |
+
'headline_content': "",
|
24 |
+
'problem_content': "",
|
25 |
+
'solution_content': "",
|
26 |
+
'avatar_details': {},
|
27 |
+
'product_details': {},
|
28 |
+
'generated_sections': {},
|
29 |
+
'metadata': {}
|
30 |
+
}
|
31 |
+
|
32 |
+
for var, default in session_state_vars.items():
|
33 |
+
if var not in st.session_state:
|
34 |
+
st.session_state[var] = default
|
35 |
|
36 |
# Funci贸n para generar contenido y procesar el JSON
|
37 |
def generate_content(prompt, temperature=1.0):
|
|
|
57 |
json_data = json.loads(json_str.strip())
|
58 |
|
59 |
# Store the JSON data in session state
|
|
|
|
|
60 |
st.session_state.metadata = json_data
|
61 |
|
62 |
# Update avatar details and other metadata elements
|
|
|
87 |
copy_button_key = f"{key_prefix}_copy_button"
|
88 |
if column.button("Copiar al portapapeles", key=copy_button_key):
|
89 |
# Use JavaScript to copy to clipboard
|
|
|
90 |
content_escaped = content.replace("`", "\\`")
|
91 |
js_code = f"""
|
92 |
<script>
|
|
|
96 |
column.components.html(js_code, height=0)
|
97 |
column.success("隆Contenido copiado al portapapeles!")
|
98 |
|
99 |
+
# Add this function to validate inputs
|
100 |
+
def validate_inputs(audience, product):
|
101 |
+
"""Validate that required inputs are provided."""
|
102 |
+
return audience.strip() != "" and product.strip() != ""
|
103 |
+
|
104 |
+
# Make sure to define your UI elements before using them
|
105 |
+
# Add this before the submit button
|
106 |
+
st.title("Generador de P谩ginas de Ventas")
|
107 |
+
|
108 |
+
# Create two columns for layout
|
109 |
+
col1, col2 = st.columns([1, 2])
|
110 |
+
|
111 |
+
with col1:
|
112 |
+
st.subheader("Configuraci贸n")
|
113 |
+
|
114 |
+
# Input fields
|
115 |
+
sales_page_audience = st.text_input("P煤blico objetivo:",
|
116 |
+
help="Describe a qui茅n va dirigida tu p谩gina de ventas")
|
117 |
+
|
118 |
+
sales_page_product = st.text_input("Producto/Servicio:",
|
119 |
+
help="Describe el producto o servicio que est谩s vendiendo")
|
120 |
+
|
121 |
+
sales_page_offer = st.text_area("Oferta espec铆fica (opcional):",
|
122 |
+
help="Detalles espec铆ficos de tu oferta, como precio, bonos, etc.")
|
123 |
+
|
124 |
+
sales_page_section = st.selectbox(
|
125 |
+
"Secci贸n a generar:",
|
126 |
+
[
|
127 |
+
"Above the Fold (Encabezado)",
|
128 |
+
"Problem (Problema)",
|
129 |
+
"Solution & Benefits (Soluci贸n y Beneficios)",
|
130 |
+
"Authority (Autoridad)",
|
131 |
+
"Offer & Bonus (Oferta y Bonus)",
|
132 |
+
"Social Proof (Prueba Social)",
|
133 |
+
"Guarantees (Garant铆as)",
|
134 |
+
"Call to Action (Llamada a la Acci贸n)",
|
135 |
+
"P.S. (Post-Data)",
|
136 |
+
"Final Call to Action (Llamada Final)"
|
137 |
+
]
|
138 |
+
)
|
139 |
+
|
140 |
+
sales_page_temperature = st.slider(
|
141 |
+
"Creatividad:",
|
142 |
+
min_value=0.0,
|
143 |
+
max_value=1.0,
|
144 |
+
value=0.7,
|
145 |
+
step=0.1,
|
146 |
+
help="Valores m谩s altos = m谩s creatividad, valores m谩s bajos = m谩s consistencia"
|
147 |
+
)
|
148 |
+
|
149 |
+
# Now create the submit button
|
150 |
+
submit_sales_page = st.button("Generar Secci贸n", key="generate_sales_page")
|
151 |
+
|
152 |
+
# Add these section generator functions before the section_functions dictionary
|
153 |
+
|
154 |
+
def load_prompt_template(filename):
|
155 |
+
"""Load a prompt template from the prompts directory."""
|
156 |
+
prompt_path = os.path.join(os.path.dirname(__file__), "prompts", filename)
|
157 |
+
with open(prompt_path, "r", encoding="utf-8") as file:
|
158 |
+
return file.read()
|
159 |
+
|
160 |
+
def generate_above_the_fold(audience, product, temperature=0.7, offer=None):
|
161 |
+
"""Generate the Above the Fold (headline) section."""
|
162 |
+
prompt_template = load_prompt_template("above_the_fold.txt")
|
163 |
+
|
164 |
+
# Create the prompt with the audience and product information
|
165 |
+
prompt = f"{prompt_template}\n\nAUDIENCE: {audience}\nPRODUCT/SERVICE: {product}"
|
166 |
+
if offer:
|
167 |
+
prompt += f"\nOFFER: {offer}"
|
168 |
+
|
169 |
+
# Generate the content
|
170 |
+
return generate_content(prompt, temperature)
|
171 |
+
|
172 |
+
def generate_problem_section(audience, product, temperature=0.7, offer=None):
|
173 |
+
"""Generate the Problem section."""
|
174 |
+
prompt_template = load_prompt_template("problem.txt")
|
175 |
+
|
176 |
+
# Create context dictionary with any existing session state data
|
177 |
+
context = {}
|
178 |
+
if 'headline_content' in st.session_state:
|
179 |
+
context['headline_content'] = st.session_state.headline_content
|
180 |
+
if 'avatar_details' in st.session_state:
|
181 |
+
context['avatar_details'] = st.session_state.avatar_details
|
182 |
+
if 'product_details' in st.session_state:
|
183 |
+
context['product_details'] = st.session_state.product_details
|
184 |
+
|
185 |
+
# Create the prompt with the audience and product information
|
186 |
+
prompt = f"{prompt_template}\n\nAUDIENCE: {audience}\nPRODUCT/SERVICE: {product}\nCONTEXT: {context}"
|
187 |
+
if offer:
|
188 |
+
prompt += f"\nOFFER: {offer}"
|
189 |
+
|
190 |
+
# Generate the content
|
191 |
+
return generate_content(prompt, temperature)
|
192 |
+
|
193 |
+
def generate_solution_section(audience, product, temperature=0.7, offer=None):
|
194 |
+
"""Generate the Solution & Benefits section."""
|
195 |
+
prompt_template = load_prompt_template("solution_benefits.txt")
|
196 |
+
|
197 |
+
# Create context dictionary with any existing session state data
|
198 |
+
context = {}
|
199 |
+
if 'headline_content' in st.session_state:
|
200 |
+
context['headline_content'] = st.session_state.headline_content
|
201 |
+
if 'problem_content' in st.session_state:
|
202 |
+
context['problem_content'] = st.session_state.problem_content
|
203 |
+
if 'avatar_details' in st.session_state:
|
204 |
+
context['avatar_details'] = st.session_state.avatar_details
|
205 |
+
|
206 |
+
# Create the prompt with the audience and product information
|
207 |
+
prompt = f"{prompt_template}\n\nAUDIENCE: {audience}\nPRODUCT/SERVICE: {product}\nCONTEXT: {context}"
|
208 |
+
if offer:
|
209 |
+
prompt += f"\nOFFER: {offer}"
|
210 |
+
|
211 |
+
# Generate the content
|
212 |
+
return generate_content(prompt, temperature)
|
213 |
|
214 |
+
def generate_authority_section(audience, product, temperature=0.7, offer=None):
|
215 |
+
"""Generate the Authority section."""
|
216 |
+
prompt_template = load_prompt_template("authority.txt")
|
217 |
+
|
218 |
+
# Create the prompt with the audience and product information
|
219 |
+
prompt = f"{prompt_template}\n\nAUDIENCE: {audience}\nPRODUCT/SERVICE: {product}"
|
220 |
+
if offer:
|
221 |
+
prompt += f"\nOFFER: {offer}"
|
222 |
+
|
223 |
+
# Generate the content
|
224 |
+
return generate_content(prompt, temperature)
|
225 |
+
|
226 |
+
def generate_offer_section(audience, product, temperature=0.7, offer=None):
|
227 |
+
"""Generate the Offer & Bonus section."""
|
228 |
+
prompt_template = load_prompt_template("offer_bonus.txt")
|
229 |
+
|
230 |
+
# Create the prompt with the audience and product information
|
231 |
+
prompt = f"{prompt_template}\n\nAUDIENCE: {audience}\nPRODUCT/SERVICE: {product}"
|
232 |
+
if offer:
|
233 |
+
prompt += f"\nOFFER DETAILS: {offer}"
|
234 |
+
else:
|
235 |
+
prompt += "\nOFFER DETAILS: Create a compelling offer based on the product/service and audience."
|
236 |
+
|
237 |
+
# Generate the content
|
238 |
+
return generate_content(prompt, temperature)
|
239 |
+
|
240 |
+
def generate_social_proof_section(audience, product, temperature=0.7, offer=None):
|
241 |
+
"""Generate the Social Proof section."""
|
242 |
+
prompt_template = load_prompt_template("social_proof.txt")
|
243 |
+
|
244 |
+
# Create the prompt with the audience and product information
|
245 |
+
prompt = f"{prompt_template}\n\nAUDIENCE: {audience}\nPRODUCT/SERVICE: {product}"
|
246 |
+
if offer:
|
247 |
+
prompt += f"\nOFFER: {offer}"
|
248 |
+
|
249 |
+
# Generate the content
|
250 |
+
return generate_content(prompt, temperature)
|
251 |
+
|
252 |
+
def generate_guarantees_section(audience, product, temperature=0.7, offer=None):
|
253 |
+
"""Generate the Guarantees section."""
|
254 |
+
prompt_template = load_prompt_template("guarantees.txt")
|
255 |
+
|
256 |
+
# Create the prompt with the audience and product information
|
257 |
+
prompt = f"{prompt_template}\n\nAUDIENCE: {audience}\nPRODUCT/SERVICE: {product}"
|
258 |
+
if offer:
|
259 |
+
prompt += f"\nOFFER: {offer}"
|
260 |
+
|
261 |
+
# Generate the content
|
262 |
+
return generate_content(prompt, temperature)
|
263 |
+
|
264 |
+
def generate_cta_section(audience, product, temperature=0.7, offer=None):
|
265 |
+
"""Generate the Call to Action section."""
|
266 |
+
prompt_template = load_prompt_template("cta.txt")
|
267 |
+
|
268 |
+
# Create the prompt with the audience and product information
|
269 |
+
prompt = f"{prompt_template}\n\nAUDIENCE: {audience}\nPRODUCT/SERVICE: {product}"
|
270 |
+
if offer:
|
271 |
+
prompt += f"\nOFFER: {offer}"
|
272 |
+
|
273 |
+
# Generate the content
|
274 |
+
return generate_content(prompt, temperature)
|
275 |
+
|
276 |
+
def generate_ps_section(audience, product, temperature=0.7, offer=None):
|
277 |
+
"""Generate the P.S. (Post-Data) section."""
|
278 |
+
prompt_template = load_prompt_template("ps.txt")
|
279 |
+
|
280 |
+
# Create the prompt with the audience and product information
|
281 |
+
prompt = f"{prompt_template}\n\nAUDIENCE: {audience}\nPRODUCT/SERVICE: {product}"
|
282 |
+
if offer:
|
283 |
+
prompt += f"\nOFFER: {offer}"
|
284 |
+
|
285 |
+
# Generate the content
|
286 |
+
return generate_content(prompt, temperature)
|
287 |
+
|
288 |
+
def generate_final_cta_section(audience, product, temperature=0.7, offer=None):
|
289 |
+
"""Generate the Final Call to Action section."""
|
290 |
+
prompt_template = load_prompt_template("final_cta.txt")
|
291 |
+
|
292 |
+
# Create the prompt with the audience and product information
|
293 |
+
prompt = f"{prompt_template}\n\nAUDIENCE: {audience}\nPRODUCT/SERVICE: {product}"
|
294 |
+
if offer:
|
295 |
+
prompt += f"\nOFFER: {offer}"
|
296 |
+
|
297 |
+
# Generate the content
|
298 |
+
return generate_content(prompt, temperature)
|
299 |
+
|
300 |
+
# Define section functions mapping once
|
301 |
+
section_functions = {
|
302 |
+
"Above the Fold (Encabezado)": generate_above_the_fold,
|
303 |
+
"Problem (Problema)": generate_problem_section,
|
304 |
+
"Solution & Benefits (Soluci贸n y Beneficios)": generate_solution_section,
|
305 |
+
"Authority (Autoridad)": generate_authority_section,
|
306 |
+
"Offer & Bonus (Oferta y Bonus)": generate_offer_section,
|
307 |
+
"Social Proof (Prueba Social)": generate_social_proof_section,
|
308 |
+
"Guarantees (Garant铆as)": generate_guarantees_section,
|
309 |
+
"Call to Action (Llamada a la Acci贸n)": generate_cta_section,
|
310 |
+
"P.S. (Post-Data)": generate_ps_section,
|
311 |
+
"Final Call to Action (Llamada Final)": generate_final_cta_section
|
312 |
+
}
|
313 |
+
|
314 |
+
# Then use it in the conditional
|
315 |
if submit_sales_page:
|
316 |
# Validar entradas
|
317 |
if validate_inputs(sales_page_audience, sales_page_product):
|
|
|
324 |
# Crear un contenedor para el spinner en la columna 2
|
325 |
with col2:
|
326 |
with st.spinner("Generando secci贸n de p谩gina de ventas...", show_time=True):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
327 |
# Obtener la funci贸n correspondiente
|
328 |
generator_func = section_functions[sales_page_section]
|
329 |
|