JeCabrera commited on
Commit
8fce1b4
verified
1 Parent(s): 5b9a3d9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -72
app.py CHANGED
@@ -20,6 +20,9 @@ load_dotenv()
20
  genai.configure(api_key=os.getenv('GOOGLE_API_KEY'))
21
  model = genai.GenerativeModel('gemini-2.0-flash')
22
 
 
 
 
23
  # Initialize session state variables if they don't exist
24
  if 'submitted' not in st.session_state:
25
  st.session_state.submitted = False
@@ -50,7 +53,7 @@ col1, col2 = st.columns([4, 6])
50
  # Main input section in left column
51
  with col1:
52
  # Define the generate_offer function first
53
- def generate_offer():
54
  has_manual_input = bool(skills or product_service)
55
  has_file_input = bool(uploaded_file is not None and not is_image)
56
  has_image_input = bool(uploaded_file is not None and is_image)
@@ -101,7 +104,7 @@ with col1:
101
  help='Describe tu producto o servicio')
102
 
103
  # Generate button moved here - right after product/service
104
- st.button('Generar Oferta 馃帀', on_click=generate_offer)
105
 
106
  # Accordion for additional settings
107
  with st.expander('鈿欙笍 Configuraci贸n Avanzada'):
@@ -183,91 +186,50 @@ with col1:
183
  with col2:
184
  if st.session_state.submitted and not st.session_state.generated:
185
  with st.spinner('Creando tu oferta perfecta...'):
186
- base_prompt = f"""You are a professional copywriter specializing in creating irresistible offers.
187
- First, analyze the target audience/avatar based on the information provided:
188
- Target Audience: {st.session_state.target_audience if hasattr(st.session_state, 'target_audience') and st.session_state.target_audience else 'General audience'}
189
-
190
- Consider their:
191
- - Pain points and frustrations
192
- - Desires and aspirations
193
- - Current situation
194
- - Emotional state
195
- - Objections they might have
196
 
197
- Then, create a compelling and persuasive offer using the {st.session_state.formula_type} formula that speaks directly to this avatar.
198
- """
 
 
 
 
 
 
 
 
 
 
199
 
 
200
  if st.session_state.input_type == "manual":
201
- prompt = base_prompt + f"""
202
- Based on the following information:
203
  Skills: {st.session_state.skills}
204
- Product/Service: {st.session_state.product_service}
205
  """
 
206
  elif st.session_state.input_type == "file":
207
- prompt = base_prompt + f"""
208
- Based on the following information from the uploaded file:
209
- File Content: {st.session_state.file_content}
210
- """
211
- elif st.session_state.input_type == "image":
212
- prompt = base_prompt + f"""
213
- Based on the image provided, create an offer that highlights the visual elements and appeals to the target audience.
214
  """
 
215
  elif st.session_state.input_type == "both":
216
- prompt = base_prompt + f"""
217
- Based on the following combined information:
218
  Skills: {st.session_state.skills}
219
- Product/Service: {st.session_state.product_service}
220
- Additional Information from File: {st.session_state.file_content}
221
-
222
- Please consider both the manual input and file content to create a comprehensive offer.
223
  """
224
- elif st.session_state.input_type == "manual_image":
225
- prompt = base_prompt + f"""
226
- Based on the following information and the image provided:
227
- Skills: {st.session_state.skills}
228
- Product/Service: {st.session_state.product_service}
229
 
230
- Please analyze both the text information and the visual elements in the image to create a comprehensive offer.
231
- """
232
- elif st.session_state.input_type == "file_image":
233
- prompt = base_prompt + f"""
234
- Based on the following information from the uploaded file and the image provided:
235
- File Content: {st.session_state.file_content}
236
-
237
- Please analyze both the file content and the visual elements in the image to create a comprehensive offer.
238
- """
239
- else:
240
- prompt = base_prompt + f"""
241
- Based on all the following information:
242
- Skills: {st.session_state.skills}
243
- Product/Service: {st.session_state.product_service}
244
- Additional Information from File: {st.session_state.file_content}
245
-
246
- Please analyze the text information, file content, and the visual elements in the image to create the most comprehensive offer.
247
- """
248
-
249
- prompt += f"""
250
- Formula Description:
251
- {offer_formulas[st.session_state.formula_type]["description"]}
252
-
253
- Examples of this formula:
254
- {chr(10).join(offer_formulas[st.session_state.formula_type]["examples"])}
255
-
256
- Please create a professional, engaging, and irresistible offer that:
257
- 1. Highlights the value proposition based on the skills/product/service provided
258
- 2. Addresses the specific pain points of the analyzed avatar
259
- 3. Creates urgency and desire
260
- 4. STRICTLY follows the structure format of the examples above
261
-
262
- IMPORTANT: Provide ONLY the final offer text. Do not include any explanations, labels, formatting instructions, brackets, or call to action at the end."""
263
-
264
  try:
265
  generation_config = genai.GenerationConfig(temperature=st.session_state.temperature)
266
 
267
  if "image" in st.session_state.input_type:
268
- response = model.generate_content([prompt, st.session_state.image_parts[0]], generation_config=generation_config)
269
  else:
270
- response = model.generate_content(prompt, generation_config=generation_config)
271
 
272
  st.session_state.offer_result = response.text
273
  st.session_state.generated = True # Mark as generated
@@ -295,4 +257,6 @@ with col2:
295
 
296
  # Footer
297
  st.markdown('---')
298
- st.markdown('Made with 鉂わ笍 by Jes煤s Cabrera')
 
 
 
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:
28
  st.session_state.submitted = False
 
53
  # Main input section in left column
54
  with col1:
55
  # Define the generate_offer function first
56
+ def handle_generate_button(): # Renamed to avoid conflict
57
  has_manual_input = bool(skills or product_service)
58
  has_file_input = bool(uploaded_file is not None and not is_image)
59
  has_image_input = bool(uploaded_file is not None and is_image)
 
104
  help='Describe tu producto o servicio')
105
 
106
  # Generate button moved here - right after product/service
107
+ st.button('Generar Oferta 馃帀', on_click=handle_generate_button) # Updated function name
108
 
109
  # Accordion for additional settings
110
  with st.expander('鈿欙笍 Configuraci贸n Avanzada'):
 
186
  with col2:
187
  if st.session_state.submitted and not st.session_state.generated:
188
  with st.spinner('Creando tu oferta perfecta...'):
189
+ # Use the create_offer_instruction function to generate the prompt
190
+ avatar_description = st.session_state.target_audience if hasattr(st.session_state, 'target_audience') and st.session_state.target_audience else 'General audience'
 
 
 
 
 
 
 
 
191
 
192
+ # Determine product name based on input type
193
+ if hasattr(st.session_state, 'product_service') and st.session_state.product_service:
194
+ product_name = st.session_state.product_service
195
+ else:
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"""
208
+ Additional information:
209
  Skills: {st.session_state.skills}
 
210
  """
211
+ instruction += additional_context
212
  elif st.session_state.input_type == "file":
213
+ additional_context = f"""
214
+ Additional information from file:
215
+ {st.session_state.file_content}
 
 
 
 
216
  """
217
+ instruction += additional_context
218
  elif st.session_state.input_type == "both":
219
+ additional_context = f"""
220
+ Additional information:
221
  Skills: {st.session_state.skills}
222
+ File content: {st.session_state.file_content}
 
 
 
223
  """
224
+ instruction += additional_context
 
 
 
 
225
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
226
  try:
227
  generation_config = genai.GenerationConfig(temperature=st.session_state.temperature)
228
 
229
  if "image" in st.session_state.input_type:
230
+ response = model.generate_content([instruction, st.session_state.image_parts[0]], generation_config=generation_config)
231
  else:
232
+ response = model.generate_content(instruction, generation_config=generation_config)
233
 
234
  st.session_state.offer_result = response.text
235
  st.session_state.generated = True # Mark as generated
 
257
 
258
  # Footer
259
  st.markdown('---')
260
+ st.markdown('Made with 鉂わ笍 by Jes煤s Cabrera')
261
+
262
+ # Remove the duplicate functions at the bottom