Spaces:
Running
Running
from dotenv import load_dotenv | |
import streamlit as st | |
import os | |
import google.generativeai as genai | |
from bullet_formulas import bullet_formulas | |
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 bullets de beneficios | |
def get_model(temperature): | |
generation_config = { | |
"temperature": temperature, | |
} | |
return genai.GenerativeModel('gemini-2.0-flash', generation_config=generation_config) | |
def generate_benefits(number_of_benefits, target_audience, product, temperature, selected_formula): | |
if not target_audience or not product: | |
return "Por favor, completa todos los campos requeridos." | |
model = get_model(temperature) | |
benefits_instruction = create_instruction(number_of_benefits, target_audience, product, selected_formula) | |
response = model.generate_content([benefits_instruction], generation_config={"temperature": temperature}) | |
return response.parts[0].text if response and response.parts else "Error generating content." | |
# Configurar la interfaz de usuario con Streamlit | |
st.set_page_config(page_title="Bullet Benefits Generator", layout="wide") | |
# Leer el contenido del archivo manual.md | |
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) | |
# 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;'>Bullet Benefits Generator</h1>", unsafe_allow_html=True) | |
st.markdown("<h4 style='text-align: center;'>Transforma características en beneficios irresistibles que conectan emocionalmente con tu audiencia.</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]) | |
# Columnas de entrada | |
with col1: | |
target_audience = st.text_input("¿Quién es tu público objetivo?", placeholder="Ejemplo: Estudiantes Universitarios") | |
product = st.text_input("¿Qué producto tienes en mente?", placeholder="Ejemplo: Curso de Inglés") | |
number_of_benefits = st.selectbox("Número de Beneficios", options=[1, 2, 3, 4, 5, 6, 7, 8, 9, 10], index=4) | |
# Crear un único acordeón para fórmula y creatividad | |
with st.expander("Personaliza tus beneficios"): | |
temperature = st.slider("Creatividad", min_value=0.0, max_value=2.0, value=1.0, step=0.1) | |
# Update the variable name in the UI section | |
selected_formula_key = st.selectbox( | |
"Selecciona una fórmula para tus beneficios", | |
options=list(bullet_formulas.keys()) | |
) | |
selected_formula = bullet_formulas[selected_formula_key] | |
# Botón de enviar | |
submit = st.button("Generar Beneficios") | |
# Mostrar los beneficios generados | |
# Update the submit section | |
if submit: | |
if target_audience and product and selected_formula: | |
with st.spinner('Generando beneficios...'): | |
generated_benefits = generate_benefits( | |
number_of_benefits, | |
target_audience, | |
product, | |
temperature, | |
selected_formula | |
) | |
if not isinstance(generated_benefits, str): | |
col2.error("Error al generar beneficios") | |
else: | |
col2.markdown(f""" | |
<div style="padding: 15px; border: 1px solid #ddd; border-radius: 8px;"> | |
<h3>Beneficios Generados:</h3> | |
<p>{generated_benefits}</p> | |
</div> | |
""", unsafe_allow_html=True) | |
else: | |
col2.warning("Por favor, completa todos los campos antes de generar beneficios.") |