|
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")) |
|
|
|
|
|
@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." |
|
|
|
|
|
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) |
|
|
|
|
|
col1, col2 = st.columns([1, 2]) |
|
|
|
|
|
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") |
|
|
|
|
|
creatividad = st.slider("Nivel de creatividad", min_value=0.0, max_value=2.0, value=1.0, step=0.1) |
|
|
|
|
|
submit = st.button("GENERAR PERFIL DE CLIENTE IDEAL") |
|
|
|
|
|
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) |
|
|
|
|
|
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.") |