Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -130,11 +130,6 @@ col1, col2 = st.columns([1, 1])
|
|
130 |
|
131 |
# Columna izquierda para inputs
|
132 |
with col1:
|
133 |
-
target_audience = st.text_area(
|
134 |
-
"¿Cuál es tu público objetivo?",
|
135 |
-
placeholder="Ejemplo: Coaches que quieren atraer más clientes..."
|
136 |
-
)
|
137 |
-
|
138 |
product_service = st.text_area(
|
139 |
"¿Cuál es tu producto o servicio?",
|
140 |
placeholder="Ejemplo: Curso de copywriting con IA, Programa de coaching..."
|
@@ -145,59 +140,64 @@ with col1:
|
|
145 |
placeholder="Ejemplo: Experiencia en marketing digital, certificación en SEO..."
|
146 |
)
|
147 |
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
is_image = False
|
154 |
-
image_parts = None
|
155 |
-
|
156 |
-
if uploaded_file is not None:
|
157 |
-
file_type = uploaded_file.name.split('.')[-1].lower()
|
158 |
|
159 |
-
#
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
|
|
177 |
|
178 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
179 |
try:
|
180 |
-
|
181 |
-
|
|
|
|
|
|
|
|
|
|
|
182 |
except Exception as e:
|
183 |
-
st.error(f"Error al
|
184 |
-
|
185 |
|
186 |
-
# Manejar archivos de imagen
|
187 |
-
elif file_type in ['jpg', 'jpeg', 'png']:
|
188 |
-
try:
|
189 |
-
image = Image.open(uploaded_file)
|
190 |
-
image_bytes = uploaded_file.getvalue()
|
191 |
-
image_parts = {
|
192 |
-
"mime_type": uploaded_file.type,
|
193 |
-
"data": image_bytes
|
194 |
-
}
|
195 |
-
is_image = True
|
196 |
-
except Exception as e:
|
197 |
-
st.error(f"Error al procesar la imagen: {str(e)}")
|
198 |
-
is_image = False
|
199 |
-
|
200 |
-
with st.expander("Opciones avanzadas"):
|
201 |
formula_type = st.selectbox(
|
202 |
"Fórmula PUV:",
|
203 |
options=list(puv_formulas.keys())
|
@@ -215,14 +215,15 @@ with col1:
|
|
215 |
|
216 |
with col2:
|
217 |
if generate_button:
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
|
|
227 |
st.write("### Propuestas Únicas de Valor")
|
228 |
st.write(response)
|
|
|
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..."
|
|
|
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())
|
|
|
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)
|