File size: 3,964 Bytes
09b8bec
 
25d1401
 
09b8bec
 
25d1401
09b8bec
25d1401
09b8bec
 
25d1401
 
1ae38f4
09b8bec
 
 
 
25d1401
09b8bec
 
1ae38f4
 
 
09b8bec
 
1ae38f4
 
 
25d1401
09b8bec
1ae38f4
 
09b8bec
 
1ae38f4
 
 
 
 
 
 
 
 
 
 
 
09b8bec
 
 
 
 
1ae38f4
 
09b8bec
 
 
 
 
 
 
1ae38f4
09b8bec
1ae38f4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
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

# Cargar las variables de entorno
load_dotenv()

# Configurar la API de Google
genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))

# Función para generar el perfil de cliente ideal
@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, temperature):
    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
    )
    
    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."

# Configurar la interfaz de usuario con Streamlit
st.set_page_config(page_title="Generador de Cliente Ideal", page_icon="👤", layout="wide")

# Leer el contenido del archivo manual.md si existe
try:
    with open("manual.md", "r", encoding="utf-8") as file:
        manual_content = file.read()
    # Mostrar el contenido del manual en el sidebar
    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)}")

# Ocultar elementos de la interfaz
st.markdown(styles["main_layout"], unsafe_allow_html=True)

# Centrar el título y el subtítulo
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)

# Añadir CSS personalizado para el botón
st.markdown(styles["button"], unsafe_allow_html=True)

# Crear columnas
col1, col2 = st.columns([1, 2])  

# Columna de entrada
with col1:
    producto = st.text_input("¿Qué producto o servicio ofreces?", placeholder="Ejemplo: Curso de Inglés")
    habilidades = st.text_input("¿Cuáles son tus habilidades principales?", placeholder="Ejemplo: Enseñanza, comunicación, diseño de contenidos")
    
    # Nivel de creatividad con slider
    creatividad = st.slider("Nivel de creatividad", min_value=0.0, max_value=2.0, value=1.0, step=0.1)
    
    # Botón para generar
    submit = st.button("GENERAR PERFIL DE CLIENTE IDEAL")

# Columna de resultados
with col2:
    if submit:
        if producto and habilidades:
            with st.spinner('Generando perfil de cliente ideal...'):
                perfil_cliente = generate_buyer_persona(
                    producto,
                    habilidades,
                    creatividad
                )
                
                if not isinstance(perfil_cliente, str):
                    st.error("Error al generar el perfil de cliente ideal")
                else:
                    st.markdown(f"""
                        <div style="{styles['results_container']}">
                            <h3>Tu Cliente Ideal</h3>
                            {perfil_cliente}
                        </div>
                    """, unsafe_allow_html=True)
                    
                    # Opción para descargar
                    st.download_button(
                        label="Descargar Perfil",
                        data=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.")