| | from dotenv import load_dotenv |
| | import streamlit as st |
| | import os |
| | import google.generativeai as genai |
| | from style import styles |
| | from prompts import create_instruction |
| |
|
| | |
| | load_dotenv() |
| |
|
| | |
| | genai.configure(api_key=os.getenv("GOOGLE_API_KEY")) |
| |
|
| | |
| | if 'perfil_cliente' not in st.session_state: |
| | st.session_state.perfil_cliente = None |
| | if 'producto' not in st.session_state: |
| | st.session_state.producto = "" |
| | if 'habilidades' not in st.session_state: |
| | st.session_state.habilidades = "" |
| | if 'creatividad' not in st.session_state: |
| | st.session_state.creatividad = 1.0 |
| | if 'incluir_niveles_conciencia' not in st.session_state: |
| | st.session_state.incluir_niveles_conciencia = False |
| |
|
| | |
| | @st.cache_resource |
| | def get_model(temperature): |
| | generation_config = { |
| | "temperature": temperature, |
| | } |
| | return genai.GenerativeModel('gemini-2.0-flash', generation_config=generation_config) |
| |
|
| | def generate_buyer_persona(product, skills, target_audience, temperature, include_consciousness_levels=False): |
| | if not product or not skills: |
| | return "Por favor, completa los campos de producto y habilidades." |
| | |
| | model = get_model(temperature) |
| | instruction = create_instruction( |
| | product_service=product, |
| | skills=skills, |
| | target_audience=target_audience, |
| | include_consciousness_levels=include_consciousness_levels |
| | ) |
| | |
| | |
| | instruction += "\n\nIMPORTANTE: La respuesta debe estar completamente en español." |
| | |
| | response = model.generate_content([instruction], generation_config={"temperature": temperature}) |
| | return response.parts[0].text if response and response.parts else "Error generando el perfil de cliente ideal." |
| |
|
| | |
| | def update_profile(): |
| | |
| | st.session_state.submitted = True |
| |
|
| | |
| | st.set_page_config(page_title="Generador de Cliente Ideal", page_icon="👤", layout="wide") |
| |
|
| | |
| | try: |
| | with open("manual.md", "r", encoding="utf-8") as file: |
| | manual_content = file.read() |
| | |
| | st.sidebar.markdown(manual_content) |
| | except FileNotFoundError: |
| | st.sidebar.warning("Manual not found. Please create a manual.md file.") |
| | except Exception as e: |
| | st.sidebar.error(f"Error loading manual: {str(e)}") |
| |
|
| | |
| | st.markdown(styles["main_layout"], unsafe_allow_html=True) |
| |
|
| | |
| | st.markdown("<h1 style='text-align: center;'>Generador de Perfil de Cliente Ideal</h1>", unsafe_allow_html=True) |
| | st.markdown("<h4 style='text-align: center;'>Crea un perfil detallado de tu cliente ideal basado en tu producto y habilidades.</h4>", unsafe_allow_html=True) |
| |
|
| | |
| | st.markdown(styles["button"], unsafe_allow_html=True) |
| | |
| | st.markdown(styles["download_button"], unsafe_allow_html=True) |
| |
|
| | |
| | col1, col2 = st.columns([1, 2]) |
| |
|
| | |
| | with col1: |
| | producto = st.text_area("¿Qué producto o servicio ofreces?", |
| | value=st.session_state.producto, |
| | placeholder="Ejemplo: Curso de Inglés", |
| | key="producto_input", |
| | height=70) |
| | st.session_state.producto = producto |
| | |
| | habilidades = st.text_area("¿Cuáles son tus habilidades principales?", |
| | value=st.session_state.habilidades, |
| | placeholder="Ejemplo: Enseñanza, comunicación, diseño de contenidos", |
| | key="habilidades_input", |
| | height=70) |
| | st.session_state.habilidades = habilidades |
| | |
| | |
| | with st.expander("Personaliza Tu Cliente Ideal Soñado"): |
| | |
| | if 'publico_objetivo' not in st.session_state: |
| | st.session_state.publico_objetivo = "" |
| | |
| | publico_objetivo = st.text_area("¿Cuál es tu público objetivo? (opcional)", |
| | value=st.session_state.publico_objetivo, |
| | placeholder="Ejemplo: Profesionales entre 25-40 años interesados en desarrollo personal", |
| | key="publico_objetivo_input", |
| | height=70) |
| | st.session_state.publico_objetivo = publico_objetivo |
| | |
| | |
| | creatividad = st.slider("Nivel de creatividad", |
| | min_value=0.0, |
| | max_value=2.0, |
| | value=st.session_state.creatividad, |
| | step=0.1, |
| | key="creatividad_slider") |
| | st.session_state.creatividad = creatividad |
| | |
| | |
| | incluir_niveles = st.checkbox( |
| | "Incluir análisis de los 5 niveles de conciencia", |
| | value=st.session_state.incluir_niveles_conciencia, |
| | help="Analiza al cliente ideal desde los 5 niveles de conciencia de Eugene Schwartz" |
| | ) |
| | st.session_state.incluir_niveles_conciencia = incluir_niveles |
| | |
| | if incluir_niveles: |
| | st.info(""" |
| | **Los 5 niveles de conciencia:** |
| | 1. **Desconocido**: No sabe que tiene un problema |
| | 2. **Consciente del problema**: Reconoce el problema pero no sabe cómo resolverlo |
| | 3. **Consciente de la solución**: Conoce posibles soluciones pero no sabe cuál elegir |
| | 4. **Consciente del producto**: Conoce tu producto pero no está convencido |
| | 5. **Consciente de la compra**: Está listo para comprar pero necesita un incentivo final |
| | """) |
| | |
| | |
| | submit = st.button("GENERAR PERFIL DE CLIENTE IDEAL", on_click=update_profile) |
| |
|
| | |
| | with col2: |
| | |
| | if 'submitted' in st.session_state and st.session_state.submitted: |
| | if st.session_state.producto and st.session_state.habilidades: |
| | with st.spinner("Creando tu Cliente Ideal Soñado..."): |
| | |
| | perfil_cliente = generate_buyer_persona( |
| | st.session_state.producto, |
| | st.session_state.habilidades, |
| | st.session_state.publico_objetivo, |
| | st.session_state.creatividad, |
| | st.session_state.incluir_niveles_conciencia |
| | ) |
| | |
| | st.session_state.perfil_cliente = perfil_cliente |
| | |
| | st.session_state.submitted = False |
| | |
| | |
| | if not isinstance(st.session_state.perfil_cliente, str): |
| | st.error("Error al generar el perfil de cliente ideal") |
| | else: |
| | |
| | st.markdown(f""" |
| | <style> |
| | .results-box {{ |
| | padding: 15px; |
| | border: 1px solid #ddd; |
| | border-radius: 8px; |
| | margin-bottom: 20px; |
| | }} |
| | </style> |
| | """, unsafe_allow_html=True) |
| | |
| | |
| | with st.expander("", expanded=True): |
| | st.markdown("<h3>Tu Cliente Ideal</h3>", unsafe_allow_html=True) |
| | st.markdown(st.session_state.perfil_cliente) |
| | |
| | |
| | st.download_button( |
| | label="Descargar Perfil", |
| | data=st.session_state.perfil_cliente, |
| | file_name="cliente_ideal.md", |
| | mime="text/markdown" |
| | ) |
| | else: |
| | st.warning("Por favor, completa los campos de producto y habilidades antes de generar el perfil.") |
| | |
| | elif st.session_state.perfil_cliente: |
| | |
| | st.markdown(f""" |
| | <style> |
| | .results-box {{ |
| | padding: 15px; |
| | border: 1px solid #ddd; |
| | border-radius: 8px; |
| | margin-bottom: 20px; |
| | }} |
| | </style> |
| | """, unsafe_allow_html=True) |
| | |
| | |
| | with st.expander("", expanded=True): |
| | st.markdown("<h3>Tu Cliente Ideal</h3>", unsafe_allow_html=True) |
| | st.markdown(st.session_state.perfil_cliente) |
| | |
| | |
| | st.download_button( |
| | label="Descargar Perfil", |
| | data=st.session_state.perfil_cliente, |
| | file_name="cliente_ideal.md", |
| | mime="text/markdown" |
| | ) |