JeCabrera commited on
Commit
313a725
verified
1 Parent(s): 45727b2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +63 -54
app.py CHANGED
@@ -201,64 +201,73 @@ with col2:
201
  else:
202
  product_name = "Producto/Servicio"
203
 
204
- # Get the instruction using the formula
205
- instruction = create_offer_instruction(
206
- avatar_description=avatar_description,
207
- product_name=product_name,
208
- selected_formula_name=st.session_state.formula_type
209
- )
210
-
211
- # Removing the creative hook instruction for Oferta Dorada
212
-
213
- # Add instruction for generating benefit bullets based on the promise
214
- bullet_content = None
215
- if hasattr(st.session_state, 'file_content') and st.session_state.input_type in ["file", "both"]:
216
- bullet_content = st.session_state.file_content
217
 
218
- instruction += create_bullet_instruction(
219
- avatar_description=avatar_description,
220
- product_name=product_name,
221
- uploaded_content=bullet_content
222
- )
223
-
224
- # Add instruction for generating bonuses that complement the offer
225
- instruction += create_bonus_instruction(
226
- avatar_description=avatar_description,
227
- product_name=product_name,
228
- selected_formula_name=st.session_state.formula_type
229
- )
230
-
231
- # Add additional context based on input type
232
- if st.session_state.input_type == "manual":
233
- additional_context = f"""
234
- Additional information:
235
- Skills: {st.session_state.skills}
236
- """
237
- instruction += additional_context
238
- elif st.session_state.input_type == "file":
239
- additional_context = f"""
240
- Additional information from file:
241
- {st.session_state.file_content}
242
- """
243
- instruction += additional_context
244
- elif st.session_state.input_type == "both":
245
- additional_context = f"""
246
- Additional information:
247
- Skills: {st.session_state.skills}
248
- File content: {st.session_state.file_content}
249
- """
250
- instruction += additional_context
251
 
252
- try:
253
- generation_config = genai.GenerationConfig(temperature=st.session_state.temperature)
 
 
 
 
254
 
255
- if "image" in st.session_state.input_type:
256
- response = model.generate_content([instruction, st.session_state.image_parts[0]], generation_config=generation_config)
257
- else:
258
- response = model.generate_content(instruction, generation_config=generation_config)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
259
 
260
- st.session_state.offer_result = response.text
261
- st.session_state.generated = True # Mark as generated
262
 
263
  except Exception as e:
264
  st.error(f'Ocurri贸 un error: {str(e)}')
 
201
  else:
202
  product_name = "Producto/Servicio"
203
 
204
+ # Get the instruction using the formula
205
+ instruction = create_offer_instruction(
206
+ avatar_description=avatar_description,
207
+ product_name=product_name,
208
+ selected_formula_name=st.session_state.formula_type
209
+ )
 
 
 
 
 
 
 
210
 
211
+ # Add instruction for generating benefit bullets based on the promise
212
+ bullet_content = None
213
+ if hasattr(st.session_state, 'file_content') and st.session_state.input_type in ["file", "both"]:
214
+ bullet_content = st.session_state.file_content
215
+
216
+ instruction += create_bullet_instruction(
217
+ avatar_description=avatar_description,
218
+ product_name=product_name,
219
+ uploaded_content=bullet_content
220
+ )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
221
 
222
+ # Add instruction for generating bonuses that complement the offer
223
+ instruction += create_bonus_instruction(
224
+ avatar_description=avatar_description,
225
+ product_name=product_name,
226
+ selected_formula_name=st.session_state.formula_type
227
+ )
228
 
229
+ # Add additional context based on input type
230
+ if st.session_state.input_type == "manual":
231
+ additional_context = f"""
232
+ Additional information:
233
+ Skills: {st.session_state.skills}
234
+ """
235
+ instruction += additional_context
236
+ elif st.session_state.input_type == "file":
237
+ additional_context = f"""
238
+ Additional information from file:
239
+ {st.session_state.file_content}
240
+ """
241
+ instruction += additional_context
242
+ elif st.session_state.input_type == "both":
243
+ additional_context = f"""
244
+ Additional information:
245
+ Skills: {st.session_state.skills}
246
+ File content: {st.session_state.file_content}
247
+ """
248
+ instruction += additional_context
249
+
250
+ try:
251
+ generation_config = genai.GenerationConfig(temperature=st.session_state.temperature)
252
+
253
+ if "image" in st.session_state.input_type:
254
+ response = model.generate_content([instruction, st.session_state.image_parts[0]], generation_config=generation_config)
255
+ else:
256
+ response = model.generate_content(instruction, generation_config=generation_config)
257
+
258
+ # Get the response text
259
+ response_text = response.text
260
+
261
+ # Special processing for Oferta Dorada to remove any markdown or formatting that might cause the box
262
+ if st.session_state.formula_type == "Oferta Dorada":
263
+ # Remove any potential markdown formatting that might be causing the box
264
+ response_text = response_text.replace("```", "").replace("`", "")
265
+ # Remove any HTML tags that might be in the response
266
+ response_text = response_text.replace("<div>", "").replace("</div>", "")
267
+ response_text = response_text.replace("<p>", "").replace("</p>", "")
268
 
269
+ st.session_state.offer_result = response_text
270
+ st.session_state.generated = True # Mark as generated
271
 
272
  except Exception as e:
273
  st.error(f'Ocurri贸 un error: {str(e)}')