JeCabrera commited on
Commit
d8a23c9
·
verified ·
1 Parent(s): 5785f6b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -227
app.py CHANGED
@@ -1,229 +1,31 @@
1
- from dotenv import load_dotenv
2
- import streamlit as st
3
- import os
4
- import google.generativeai as genai
5
- from puv_formulas import puv_formulas
6
- from styles import apply_styles
7
- import PyPDF2
8
- import docx
9
- from PIL import Image
10
-
11
- # Cargar variables de entorno
12
- load_dotenv()
13
-
14
- # Configurar API de Google Gemini
15
- genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
16
-
17
- # Función para obtener la respuesta del modelo Gemini
18
- def get_gemini_response(product_service, target_audience, skills, formula_type, temperature, file_content="", image_parts=None):
19
- # Check if we have at least one source of information
20
- has_file_content = bool(file_content.strip())
21
- has_image = image_parts is not None
22
- has_text_input = target_audience or product_service or skills
23
-
24
- if not (has_file_content or has_image or has_text_input):
25
- return "Debes proporcionar al menos un tipo de información: público objetivo, producto/servicio, habilidades o un archivo de referencia."
26
-
27
- # If we only have file content but no other inputs, we can proceed
28
- if (has_file_content or has_image) and not has_text_input:
29
- # File-only mode
30
- business_info = "Analyze the provided reference material to extract business information.\n"
31
- else:
32
- # Regular mode with validation
33
- if not target_audience:
34
- return "El campo de público objetivo es obligatorio cuando no se proporciona un archivo de referencia completo."
35
-
36
- if not product_service and not skills:
37
- return "Debes proporcionar al menos tu producto/servicio o tus habilidades cuando no se proporciona un archivo de referencia completo."
38
-
39
- # Adjust prompt based on what's provided
40
- business_info = f"Target Audience: {target_audience}\n"
41
-
42
- if product_service:
43
- business_info += f"Product/Service: {product_service}\n"
44
-
45
- if skills:
46
- business_info += f"My Skills/Expertise: {skills}\n"
47
-
48
- formula = puv_formulas[formula_type]
49
-
50
- # Add file content if available
51
- reference_info = ""
52
- if file_content:
53
- reference_info = f"\nREFERENCE MATERIAL:\n{file_content}\n"
54
-
55
- model = genai.GenerativeModel('gemini-2.0-flash')
56
- full_prompt = f"""
57
- You are a UVP (Unique Value Proposition) expert. Analyze (internally only, do not output the analysis) the following information:
58
- BUSINESS INFORMATION:
59
- {business_info}
60
- Formula Type: {formula_type}
61
- {formula["description"]}
62
- {reference_info}
63
-
64
- EXAMPLE TO FOLLOW:
65
- {formula["examples"]}
66
-
67
- First, analyze (but don't output) these points:
68
- 1. TARGET AUDIENCE ANALYSIS - Pain Points:
69
- - What specific frustrations does this audience experience?
70
- - What are their biggest daily challenges?
71
- - What emotional problems do they face?
72
- - What have they tried before that didn't work?
73
- - What's stopping them from achieving their goals?
74
-
75
- 2. PRODUCT/SERVICE ANALYSIS - Benefits:
76
- - What tangible results do clients get?
77
- - What specific transformation does it offer?
78
- - What's the unique method or differentiator?
79
- - What competitive advantages does it have?
80
- - What emotional benefits does it provide?
81
-
82
- 3. SKILLS/EXPERTISE ANALYSIS - Credibility:
83
- - How do these skills directly address the audience's pain points?
84
- - What unique perspective do these skills bring to the solution?
85
- - How do these skills enhance the product/service delivery?
86
- - What credibility elements can be highlighted?
87
- - How do these skills differentiate from competitors?
88
-
89
- Based on your internal analysis of the target audience pain points and product benefits (do not include this analysis in the output), create THREE different UVPs in Spanish language following the formula structure provided.
90
- CRITICAL INSTRUCTIONS:
91
- - Each UVP must be specific and measurable
92
- - Focus on the transformation journey
93
- - Use natural, conversational language
94
- - Avoid generic phrases and buzzwords
95
- - Maximum 2 lines per UVP
96
- - DO NOT include any analysis in the output
97
- - ONLY output the three UVPs
98
-
99
- Output EXACTLY in this format (no additional text) in Spanish language:
100
- 1. [First UVP]
101
- 2. [Second UVP]
102
- 3. [Third UVP]
103
- """
104
-
105
- # Handle text-only or text+image requests
106
- if image_parts:
107
- response = model.generate_content([full_prompt, image_parts], generation_config={"temperature": temperature})
108
- else:
109
- response = model.generate_content([full_prompt], generation_config={"temperature": temperature})
110
-
111
- return response.parts[0].text if response and response.parts else "Error generating content."
112
-
113
- # Configurar la aplicación Streamlit
114
- st.set_page_config(page_title="UVP Generator", page_icon="💡", layout="wide")
115
-
116
- # Aplicar estilos
117
- st.markdown(apply_styles(), unsafe_allow_html=True)
118
-
119
- # Título de la app
120
- st.markdown("<h1>Generador de PUV</h1>", unsafe_allow_html=True)
121
- st.markdown("<h3>Crea Propuestas Únicas de Valor poderosas que atraigan a tus clientes ideales y comuniquen tu valor de manera efectiva.</h3>", unsafe_allow_html=True)
122
-
123
- # Sidebar manual
124
- with open("manual.md", "r", encoding="utf-8") as file:
125
- manual_content = file.read()
126
- st.sidebar.markdown(manual_content)
127
-
128
- # Crear dos columnas
129
- col1, col2 = st.columns([1, 1])
130
-
131
- # Columna izquierda para inputs
132
- with col1:
133
- product_service = st.text_area(
134
- "¿Cuál es tu producto o servicio?",
135
- placeholder="Ejemplo: Curso de copywriting con IA, Programa de coaching..."
136
- )
137
-
138
- skills = st.text_area(
139
- "Mis habilidades:",
140
- placeholder="Ejemplo: Experiencia en marketing digital, certificación en SEO..."
141
- )
142
-
143
- with st.expander("Opciones avanzadas"):
144
- target_audience = st.text_area(
145
- "¿Cuál es tu público objetivo?",
146
- placeholder="Ejemplo: Coaches que quieren atraer más clientes..."
147
- )
148
-
149
- # Añadir cargador de archivos
150
- uploaded_file = st.file_uploader("📄 Archivo o imagen de referencia",
151
- type=['txt', 'pdf', 'docx', 'jpg', 'jpeg', 'png'])
152
-
153
- file_content = ""
154
- is_image = False
155
- image_parts = None
156
-
157
- if uploaded_file is not None:
158
- file_type = uploaded_file.name.split('.')[-1].lower()
159
 
160
- # Manejar archivos de texto
161
- if file_type in ['txt', 'pdf', 'docx']:
162
- if file_type == 'txt':
163
- try:
164
- file_content = uploaded_file.read().decode('utf-8')
165
- except Exception as e:
166
- st.error(f"Error al leer el archivo TXT: {str(e)}")
167
- file_content = ""
168
-
169
- elif file_type == 'pdf':
170
- try:
171
- pdf_reader = PyPDF2.PdfReader(uploaded_file)
172
- file_content = ""
173
- for page in pdf_reader.pages:
174
- file_content += page.extract_text() + "\n"
175
- except Exception as e:
176
- st.error(f"Error al leer el archivo PDF: {str(e)}")
177
- file_content = ""
178
-
179
- elif file_type == 'docx':
180
- try:
181
- doc = docx.Document(uploaded_file)
182
- file_content = "\n".join([para.text for para in doc.paragraphs])
183
- except Exception as e:
184
- st.error(f"Error al leer el archivo DOCX: {str(e)}")
185
- file_content = ""
186
 
187
- # Manejar archivos de imagen
188
- elif file_type in ['jpg', 'jpeg', 'png']:
189
- try:
190
- image = Image.open(uploaded_file)
191
- image_bytes = uploaded_file.getvalue()
192
- image_parts = {
193
- "mime_type": uploaded_file.type,
194
- "data": image_bytes
195
- }
196
- is_image = True
197
- except Exception as e:
198
- st.error(f"Error al procesar la imagen: {str(e)}")
199
- is_image = False
200
-
201
- formula_type = st.selectbox(
202
- "Fórmula PUV:",
203
- options=list(puv_formulas.keys())
204
- )
205
- temperature = st.slider(
206
- "Nivel de creatividad:",
207
- min_value=0.0,
208
- max_value=2.0,
209
- value=1.0,
210
- step=0.1,
211
- help="Valores más altos generan propuestas más creativas pero menos predecibles."
212
- )
213
-
214
- generate_button = st.button("Generar PUV")
215
-
216
- with col2:
217
- if generate_button:
218
- with st.spinner("Creando tu PUV..."):
219
- response = get_gemini_response(
220
- product_service,
221
- target_audience,
222
- skills,
223
- formula_type,
224
- temperature,
225
- file_content,
226
- image_parts
227
- )
228
- st.write("### Propuestas Únicas de Valor")
229
- st.write(response)
 
1
+ "download_button": """
2
+ <style>
3
+ [data-testid="stDownloadButton"] {
4
+ text-align: center;
5
+ display: flex;
6
+ justify-content: center;
7
+ margin-top: 5px;
8
+ width: 90%;
9
+ margin-left: auto;
10
+ margin-right: auto;
11
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
 
13
+ [data-testid="stDownloadButton"] button {
14
+ width: 100%;
15
+ border-radius: 5px;
16
+ height: 3em;
17
+ background: linear-gradient(to right, #00D100, #009900);
18
+ color: white;
19
+ font-weight: bold;
20
+ transition: all 0.3s ease;
21
+ border: none;
22
+ text-transform: uppercase;
23
+ letter-spacing: 1px;
24
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25
 
26
+ [data-testid="stDownloadButton"] button:hover {
27
+ background: linear-gradient(to right, #00C000, #008800);
28
+ transform: translateY(-2px);
29
+ box-shadow: 0 4px 8px rgba(0,0,0,0.1);
30
+ }
31
+ </style>