JeCabrera commited on
Commit
b2fe2ad
·
verified ·
1 Parent(s): e299375

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +156 -117
app.py CHANGED
@@ -16,137 +16,141 @@ load_dotenv()
16
  genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
17
 
18
  # Función para obtener la respuesta del modelo Gemini
19
- def get_gemini_response(product_service, target_audience, main_benefit, tone_of_voice, temperature, file_content="", image_parts=None):
20
- # Check if we have at least one source of information
21
- has_file_content = bool(file_content.strip())
22
- has_image = image_parts is not None
23
- has_text_input = target_audience or product_service or main_benefit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
 
25
- if not (has_file_content or has_image or has_text_input):
26
- return "Debes proporcionar al menos un tipo de información: público objetivo, producto/servicio, beneficio principal o un archivo de referencia."
 
 
 
27
 
28
- # If we only have file content but no other inputs, we can proceed
29
- if (has_file_content or has_image) and not has_text_input:
30
- # File-only mode
31
- business_info = "Analyze the provided reference material to extract business information.\n"
32
- else:
33
- # Regular mode with validation
34
- if not target_audience:
35
- return "El campo de público objetivo es obligatorio cuando no se proporciona un archivo de referencia completo."
36
 
37
- if not product_service:
38
- return "Debes proporcionar tu producto/servicio cuando no se proporciona un archivo de referencia completo."
 
 
39
 
40
- if not main_benefit:
41
- return "Debes proporcionar el beneficio principal cuando no se proporciona un archivo de referencia completo."
42
 
43
- # Adjust prompt based on what's provided
44
- business_info = f"Target Audience: {target_audience}\n"
45
- business_info += f"Product/Service: {product_service}\n"
46
- business_info += f"Main Benefit: {main_benefit}\n"
47
 
48
- if tone_of_voice:
49
- business_info += f"Brand Tone of Voice: {tone_of_voice}\n"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
50
 
51
- # Add file content if available
52
- reference_info = ""
53
- if file_content:
54
- reference_info = f"\nREFERENCE MATERIAL:\n{file_content}\n"
55
 
56
- model = genai.GenerativeModel('gemini-2.0-flash')
57
- full_prompt = f"""
58
- You are a Creative Concept expert. Analyze (internally only, do not output the analysis) the following information:
59
- BUSINESS INFORMATION:
60
- {business_info}
61
- {reference_info}
62
-
63
- A Creative Idea is a set of pieces created to sell a brand, product, or service, united by the same idea that is transmitted through a creative concept.
64
-
65
- First, analyze (but don't output) these points:
66
- 1. TARGET AUDIENCE ANALYSIS:
67
- - What everyday concepts are they familiar with?
68
- - What TV shows, movies, or cultural references resonate with them?
69
- - What emotions and experiences are meaningful to them?
70
- - What mental images would be easy for them to recall?
71
-
72
- 2. PRODUCT/SERVICE ANALYSIS:
73
- - What is the main benefit or promise?
74
- - What makes it unique or different?
75
- - What transformation does it offer?
76
- - What process or journey does the customer go through?
77
-
78
- Based on your internal analysis, create THREE different Creative Concepts in Spanish language.
79
- Each concept should be a DIRECT ANALOGY or METAPHOR that connects your product/service to something completely different but familiar.
80
 
81
- Examples of good creative concepts:
82
- - "Escribir copy es como cocinar tu plato favorito porque necesitas los ingredientes correctos para que todos quieran probarlo"
83
- - "Tu negocio es como un equipo de fútbol: necesita buenos jugadores (productos) y una estrategia clara para ganar clientes"
84
- - "Tu curso es como Netflix: ofrece contenido que engancha y soluciones que la gente realmente quiere ver"
85
 
86
- For each concept, include:
87
 
88
- CONCEPT: A clear statement of the main benefit
89
- CREATIVITY: A direct analogy or metaphor connecting your product to something completely different but familiar
90
- HEADLINE EXAMPLE: A short, catchy headline that applies the creative concept
91
 
92
- CRITICAL INSTRUCTIONS:
93
- - Each concept MUST use a direct "X es como Y porque Z" structure
94
- - Use SIMPLE, EVERYDAY language that anyone can understand
95
- - Avoid technical jargon, complex words, or business terminology
96
- - Write as if you're explaining to a friend in a casual conversation
97
- - Use everyday objects, activities, movies, TV shows or cultural references everyone knows
98
- - Make the connection surprising but logical once explained
99
- - Focus on the main benefit
100
- - Create clear mental images
101
- - Be easy to remember
102
- - Use the brand's tone of voice if provided
103
- - Format with proper spacing between sections
104
 
105
- Output EXACTLY in this format (no additional text) in Spanish language:
 
106
 
107
- CONCEPTO CREATIVO 1:
108
-
109
- Concepto:
110
- [Main message/benefit in simple, conversational language]
111
-
112
- Creatividad:
113
- [Direct analogy using everyday language: "X es como Y porque Z"]
114
-
115
- Ejemplo de Titular:
116
- [Short headline example applying the creative concept]
117
-
118
-
119
- CONCEPTO CREATIVO 2:
120
-
121
- Concepto:
122
- [Main message/benefit]
123
-
124
- Creatividad:
125
- [Direct analogy: "X es como Y porque Z"]
126
-
127
- Ejemplo de Titular:
128
- [Short headline example applying the creative concept]
129
-
130
-
131
- CONCEPTO CREATIVO 3:
132
-
133
- Concepto:
134
- [Main message/benefit]
135
-
136
- Creatividad:
137
- [Direct analogy: "X es como Y porque Z"]
138
-
139
- Ejemplo de Titular:
140
- [Short headline example applying the creative concept]
141
- """
142
 
143
- # Handle text-only or text+image requests
144
- if image_parts:
145
- response = model.generate_content([full_prompt, image_parts], generation_config={"temperature": temperature})
146
- else:
147
- response = model.generate_content([full_prompt], generation_config={"temperature": temperature})
148
 
149
- return response.parts[0].text if response and response.parts else "Error generating content."
 
 
 
 
 
 
 
 
 
 
150
 
151
  # Configurar la aplicación Streamlit
152
  st.set_page_config(page_title="Generador de Ideas Creativas", page_icon="💡", layout="wide")
@@ -272,6 +276,16 @@ with col1:
272
  st.error(f"Error al procesar la imagen: {str(e)}")
273
  is_image = False
274
 
 
 
 
 
 
 
 
 
 
 
275
  temperature = st.slider(
276
  "Nivel de creatividad:",
277
  min_value=0.0,
@@ -295,7 +309,9 @@ with col2:
295
  tone_of_voice,
296
  temperature,
297
  file_content,
298
- image_parts
 
 
299
  )
300
 
301
  # Display the response if it exists in session state
@@ -322,4 +338,27 @@ with col2:
322
  data=download_content,
323
  file_name=f"conceptos_creativos_{timestamp}.txt",
324
  mime="text/plain"
325
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
  genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
17
 
18
  # Función para obtener la respuesta del modelo Gemini
19
+ # In the get_gemini_response function parameters
20
+ def get_gemini_response(product_service, target_audience, main_benefit, tone_of_voice, temperature,
21
+ file_content="", image_parts=None, creative_approach="", contrast_level=3):
22
+ # Check if we have at least one source of information
23
+ has_file_content = bool(file_content.strip())
24
+ has_image = image_parts is not None
25
+ has_text_input = target_audience or product_service or main_benefit
26
+
27
+ if not (has_file_content or has_image or has_text_input):
28
+ return "Debes proporcionar al menos un tipo de información: público objetivo, producto/servicio, beneficio principal o un archivo de referencia."
29
+
30
+ # If we only have file content but no other inputs, we can proceed
31
+ if (has_file_content or has_image) and not has_text_input:
32
+ # File-only mode
33
+ business_info = "Analyze the provided reference material to extract business information.\n"
34
+ else:
35
+ # Regular mode with validation
36
+ if not target_audience:
37
+ return "El campo de público objetivo es obligatorio cuando no se proporciona un archivo de referencia completo."
38
+
39
+ if not product_service:
40
+ return "Debes proporcionar tu producto/servicio cuando no se proporciona un archivo de referencia completo."
41
+
42
+ if not main_benefit:
43
+ return "Debes proporcionar el beneficio principal cuando no se proporciona un archivo de referencia completo."
44
+
45
+ # Adjust prompt based on what's provided
46
+ business_info = f"Target Audience: {target_audience}\n"
47
+ business_info += f"Product/Service: {product_service}\n"
48
+ business_info += f"Main Benefit: {main_benefit}\n"
49
+
50
+ if tone_of_voice:
51
+ business_info += f"Brand Tone of Voice: {tone_of_voice}\n"
52
+
53
+ # Add file content if available
54
+ reference_info = ""
55
+ if file_content:
56
+ reference_info = f"\nREFERENCE MATERIAL:\n{file_content}\n"
57
+
58
+ model = genai.GenerativeModel('gemini-2.0-flash')
59
+ full_prompt = f"""
60
+ You are a Creative Concept expert. Analyze (internally only, do not output the analysis) the following information:
61
+ BUSINESS INFORMATION:
62
+ {business_info}
63
+ {reference_info}
64
+
65
+ A Creative Idea is a set of pieces created to sell a brand, product, or service, united by the same idea that is transmitted through a creative concept.
66
+
67
+ First, analyze (but don't output) these points:
68
+ 1. TARGET AUDIENCE ANALYSIS:
69
+ - What everyday concepts are they familiar with?
70
+ - What TV shows, movies, or cultural references resonate with them?
71
+ - What emotions and experiences are meaningful to them?
72
+ - What mental images would be easy for them to recall?
73
 
74
+ 2. PRODUCT/SERVICE ANALYSIS:
75
+ - What is the main benefit or promise?
76
+ - What makes it unique or different?
77
+ - What transformation does it offer?
78
+ - What process or journey does the customer go through?
79
 
80
+ Based on your internal analysis, create THREE different Creative Concepts in Spanish language.
81
+ Each concept should be a DIRECT ANALOGY or METAPHOR that connects your product/service to something completely different but familiar.
 
 
 
 
 
 
82
 
83
+ Examples of good creative concepts:
84
+ - "Escribir copy es como cocinar tu plato favorito porque necesitas los ingredientes correctos para que todos quieran probarlo"
85
+ - "Tu negocio es como un equipo de fútbol: necesita buenos jugadores (productos) y una estrategia clara para ganar clientes"
86
+ - "Tu curso es como Netflix: ofrece contenido que engancha y soluciones que la gente realmente quiere ver"
87
 
88
+ For each concept, include:
 
89
 
90
+ CONCEPT: A clear statement of the main benefit
91
+ CREATIVITY: A direct analogy or metaphor connecting your product to something completely different but familiar
92
+ HEADLINE EXAMPLE: A short, catchy headline that applies the creative concept
 
93
 
94
+ CRITICAL INSTRUCTIONS:
95
+ - Each concept MUST use a direct "X es como Y porque Z" structure
96
+ - Use SIMPLE, EVERYDAY language that anyone can understand
97
+ - Avoid technical jargon, complex words, or business terminology
98
+ - Write as if you're explaining to a friend in a casual conversation
99
+ - Use everyday objects, activities, movies, TV shows or cultural references everyone knows
100
+ - Make the connection SURPRISING and UNEXPECTED - connect things that normally wouldn't be connected
101
+ - Challenge conventional thinking by finding parallels between your product and something completely different
102
+ - Create analogies that make people say "I never thought of it that way!"
103
+ - Focus on the main benefit
104
+ - Create clear mental images
105
+ - Be easy to remember
106
+ - Use the brand's tone of voice if provided
107
+ - Format with proper spacing between sections
108
+
109
+ Output EXACTLY in this format (no additional text) in Spanish language:
110
+
111
+ CONCEPTO CREATIVO 1:
112
 
113
+ Concepto:
114
+ [Main message/benefit in simple, conversational language]
 
 
115
 
116
+ Creatividad:
117
+ [Direct analogy using everyday language: "X es como Y porque Z"]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
118
 
119
+ Ejemplo de Titular:
120
+ [Short headline example applying the creative concept]
 
 
121
 
 
122
 
123
+ CONCEPTO CREATIVO 2:
 
 
124
 
125
+ Concepto:
126
+ [Main message/benefit]
 
 
 
 
 
 
 
 
 
 
127
 
128
+ Creatividad:
129
+ [Direct analogy: "X es como Y porque Z"]
130
 
131
+ Ejemplo de Titular:
132
+ [Short headline example applying the creative concept]
133
+
134
+
135
+ CONCEPTO CREATIVO 3:
136
+
137
+ Concepto:
138
+ [Main message/benefit]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
139
 
140
+ Creatividad:
141
+ [Direct analogy: "X es como Y porque Z"]
 
 
 
142
 
143
+ Ejemplo de Titular:
144
+ [Short headline example applying the creative concept]
145
+ """
146
+
147
+ # Handle text-only or text+image requests
148
+ if image_parts:
149
+ response = model.generate_content([full_prompt, image_parts], generation_config={"temperature": temperature})
150
+ else:
151
+ response = model.generate_content([full_prompt], generation_config={"temperature": temperature})
152
+
153
+ return response.parts[0].text if response and response.parts else "Error generating content."
154
 
155
  # Configurar la aplicación Streamlit
156
  st.set_page_config(page_title="Generador de Ideas Creativas", page_icon="💡", layout="wide")
 
276
  st.error(f"Error al procesar la imagen: {str(e)}")
277
  is_image = False
278
 
279
+ # Add contrast parameter
280
+ contrast_level = st.slider(
281
+ "Nivel de contraste:",
282
+ min_value=1,
283
+ max_value=5,
284
+ value=3,
285
+ step=1,
286
+ help="Valores más altos generan analogías entre conceptos más distantes y sorprendentes."
287
+ )
288
+
289
  temperature = st.slider(
290
  "Nivel de creatividad:",
291
  min_value=0.0,
 
309
  tone_of_voice,
310
  temperature,
311
  file_content,
312
+ image_parts,
313
+ st.session_state.get("selected_approach", ""),
314
+ contrast_level if 'contrast_level' in locals() else 3
315
  )
316
 
317
  # Display the response if it exists in session state
 
338
  data=download_content,
339
  file_name=f"conceptos_creativos_{timestamp}.txt",
340
  mime="text/plain"
341
+ )
342
+
343
+ with st.expander("Opciones avanzadas"):
344
+ # Add creative approach selector
345
+ creative_approaches = {
346
+ "Analogías Cotidianas": "Usa objetos y situaciones del día a día para explicar tu producto",
347
+ "Contrastes Extremos": "Compara tu producto con algo completamente opuesto para destacar beneficios",
348
+ "Mundos Ficticios": "Usa referencias de películas, series o libros populares",
349
+ "Absurdo Lógico": "Crea conexiones inesperadas pero que tienen sentido al explicarlas",
350
+ "Inversión de Roles": "Presenta tu producto como si fuera el cliente, o el problema como la solución"
351
+ }
352
+
353
+ selected_approach = st.selectbox(
354
+ "Enfoque creativo:",
355
+ options=list(creative_approaches.keys()),
356
+ index=0,
357
+ key="approach_selectbox"
358
+ )
359
+
360
+ # Display the description of the selected approach
361
+ st.info(creative_approaches[selected_approach])
362
+
363
+ # Store the selected approach
364
+ st.session_state.selected_approach = selected_approach