Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -29,16 +29,57 @@ def get_model(temperature):
|
|
29 |
}
|
30 |
return genai.GenerativeModel('gemini-2.0-flash', generation_config=generation_config)
|
31 |
|
|
|
32 |
def generate_buyer_persona(product, skills, target_audience, temperature):
|
33 |
-
|
34 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
|
36 |
model = get_model(temperature)
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
42 |
|
43 |
# A帽adir instrucci贸n expl铆cita para respuesta en espa帽ol
|
44 |
instruction += "\n\nIMPORTANTE: La respuesta debe estar completamente en espa帽ol."
|
@@ -46,6 +87,62 @@ def generate_buyer_persona(product, skills, target_audience, temperature):
|
|
46 |
response = model.generate_content([instruction], generation_config={"temperature": temperature})
|
47 |
return response.parts[0].text if response and response.parts else "Error generando el perfil de cliente ideal."
|
48 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
49 |
# Modificar la funci贸n update_profile para que no use spinner
|
50 |
def update_profile():
|
51 |
# Solo actualizar la variable de sesi贸n
|
|
|
29 |
}
|
30 |
return genai.GenerativeModel('gemini-2.0-flash', generation_config=generation_config)
|
31 |
|
32 |
+
# Modificar la funci贸n generate_buyer_persona para manejar diferentes combinaciones
|
33 |
def generate_buyer_persona(product, skills, target_audience, temperature):
|
34 |
+
# Verificar qu茅 informaci贸n tenemos disponible
|
35 |
+
has_product = bool(product.strip())
|
36 |
+
has_skills = bool(skills.strip())
|
37 |
+
has_target = bool(target_audience.strip())
|
38 |
+
|
39 |
+
# Si no tenemos ni producto ni habilidades, no podemos generar un perfil
|
40 |
+
if not has_product and not has_skills:
|
41 |
+
return "Por favor, completa al menos uno de los campos: producto/servicio o habilidades."
|
42 |
|
43 |
model = get_model(temperature)
|
44 |
+
|
45 |
+
# Crear instrucci贸n adaptada a la informaci贸n disponible
|
46 |
+
if has_product and has_skills:
|
47 |
+
# Caso 1: Tenemos producto y habilidades
|
48 |
+
instruction = create_instruction(
|
49 |
+
product_service=product,
|
50 |
+
skills=skills,
|
51 |
+
target_audience=target_audience if has_target else ""
|
52 |
+
)
|
53 |
+
elif has_product:
|
54 |
+
# Caso 2: Solo tenemos producto
|
55 |
+
instruction = f"""
|
56 |
+
Crea un perfil detallado de cliente ideal para el siguiente producto/servicio: {product}.
|
57 |
+
{f'El p煤blico objetivo es: {target_audience}.' if has_target else 'Infiere el p煤blico objetivo m谩s adecuado.'}
|
58 |
+
|
59 |
+
Incluye:
|
60 |
+
- Demograf铆a (edad, g茅nero, ubicaci贸n, nivel educativo, ingresos)
|
61 |
+
- Psicograf铆a (valores, intereses, estilo de vida)
|
62 |
+
- Necesidades y deseos
|
63 |
+
- Puntos de dolor que el producto/servicio resuelve
|
64 |
+
- Objeciones comunes y c贸mo abordarlas
|
65 |
+
- Canales preferidos para recibir informaci贸n
|
66 |
+
"""
|
67 |
+
else:
|
68 |
+
# Caso 3: Solo tenemos habilidades
|
69 |
+
instruction = f"""
|
70 |
+
Crea un perfil detallado de cliente ideal para alguien con las siguientes habilidades: {skills}.
|
71 |
+
{f'El p煤blico objetivo es: {target_audience}.' if has_target else 'Infiere el p煤blico objetivo m谩s adecuado.'}
|
72 |
+
|
73 |
+
Sugiere productos o servicios que podr铆an ofrecerse con estas habilidades.
|
74 |
+
|
75 |
+
Incluye:
|
76 |
+
- Demograf铆a (edad, g茅nero, ubicaci贸n, nivel educativo, ingresos)
|
77 |
+
- Psicograf铆a (valores, intereses, estilo de vida)
|
78 |
+
- Necesidades y deseos
|
79 |
+
- Puntos de dolor que podr铆an resolverse con estas habilidades
|
80 |
+
- Objeciones comunes y c贸mo abordarlas
|
81 |
+
- Canales preferidos para recibir informaci贸n
|
82 |
+
"""
|
83 |
|
84 |
# A帽adir instrucci贸n expl铆cita para respuesta en espa帽ol
|
85 |
instruction += "\n\nIMPORTANTE: La respuesta debe estar completamente en espa帽ol."
|
|
|
87 |
response = model.generate_content([instruction], generation_config={"temperature": temperature})
|
88 |
return response.parts[0].text if response and response.parts else "Error generando el perfil de cliente ideal."
|
89 |
|
90 |
+
# Modificar la secci贸n de verificaci贸n en la columna de resultados
|
91 |
+
with col2:
|
92 |
+
# Verificar si se ha enviado el formulario
|
93 |
+
if 'submitted' in st.session_state and st.session_state.submitted:
|
94 |
+
# Verificar si tenemos al menos producto o habilidades
|
95 |
+
if st.session_state.producto or st.session_state.habilidades:
|
96 |
+
with st.spinner("Creando tu Cliente Ideal So帽ado..."):
|
97 |
+
# Generar el perfil del cliente
|
98 |
+
perfil_cliente = generate_buyer_persona(
|
99 |
+
st.session_state.producto,
|
100 |
+
st.session_state.habilidades,
|
101 |
+
st.session_state.publico_objetivo,
|
102 |
+
st.session_state.creatividad
|
103 |
+
)
|
104 |
+
# Guardar en session_state
|
105 |
+
st.session_state.perfil_cliente = perfil_cliente
|
106 |
+
# Resetear el estado de env铆o
|
107 |
+
st.session_state.submitted = False
|
108 |
+
|
109 |
+
# Mostrar resultados
|
110 |
+
if not isinstance(st.session_state.perfil_cliente, str):
|
111 |
+
st.error("Error al generar el perfil de cliente ideal")
|
112 |
+
else:
|
113 |
+
st.markdown(f"""
|
114 |
+
<div style="{styles['results_container']}">
|
115 |
+
<h3>Tu Cliente Ideal</h3>
|
116 |
+
{st.session_state.perfil_cliente}
|
117 |
+
</div>
|
118 |
+
""", unsafe_allow_html=True)
|
119 |
+
|
120 |
+
# Opci贸n para descargar
|
121 |
+
st.download_button(
|
122 |
+
label="Descargar Perfil",
|
123 |
+
data=st.session_state.perfil_cliente,
|
124 |
+
file_name="cliente_ideal.txt",
|
125 |
+
mime="text/markdown"
|
126 |
+
)
|
127 |
+
else:
|
128 |
+
st.warning("Por favor, completa al menos uno de los campos: producto/servicio o habilidades.")
|
129 |
+
# Mostrar resultados anteriores si existen
|
130 |
+
elif st.session_state.perfil_cliente:
|
131 |
+
st.markdown(f"""
|
132 |
+
<div style="{styles['results_container']}">
|
133 |
+
<h3>Tu Cliente Ideal</h3>
|
134 |
+
{st.session_state.perfil_cliente}
|
135 |
+
</div>
|
136 |
+
""", unsafe_allow_html=True)
|
137 |
+
|
138 |
+
# Opci贸n para descargar
|
139 |
+
st.download_button(
|
140 |
+
label="Descargar Perfil",
|
141 |
+
data=st.session_state.perfil_cliente,
|
142 |
+
file_name="cliente_ideal.md",
|
143 |
+
mime="text/markdown"
|
144 |
+
)
|
145 |
+
|
146 |
# Modificar la funci贸n update_profile para que no use spinner
|
147 |
def update_profile():
|
148 |
# Solo actualizar la variable de sesi贸n
|