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("

Generador de Perfil de Cliente Ideal

", unsafe_allow_html=True) st.markdown("

Crea un perfil detallado de tu cliente ideal basado en tu producto y habilidades.

", 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"""

Tu Cliente Ideal

{perfil_cliente}
""", 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.")