Update app.py
Browse files
app.py
CHANGED
|
@@ -1,43 +1,122 @@
|
|
|
|
|
|
|
|
| 1 |
import os
|
| 2 |
-
import gradio as gr
|
| 3 |
import google.generativeai as genai
|
| 4 |
-
from
|
| 5 |
-
from
|
|
|
|
|
|
|
| 6 |
|
|
|
|
| 7 |
load_dotenv()
|
|
|
|
|
|
|
| 8 |
genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
|
| 9 |
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
"
|
| 15 |
-
"max_output_tokens": 2048,
|
| 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 |
|
|
|
|
|
|
|
|
|
| 1 |
+
from dotenv import load_dotenv
|
| 2 |
+
import streamlit as st
|
| 3 |
import os
|
|
|
|
| 4 |
import google.generativeai as genai
|
| 5 |
+
from bullet_formulas import bullet_formulas
|
| 6 |
+
from style import styles
|
| 7 |
+
from prompts import create_instruction
|
| 8 |
+
from angles import bullet_angles
|
| 9 |
|
| 10 |
+
# Cargar las variables de entorno
|
| 11 |
load_dotenv()
|
| 12 |
+
|
| 13 |
+
# Configurar la API de Google
|
| 14 |
genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
|
| 15 |
|
| 16 |
+
# Función para generar bullets de beneficios
|
| 17 |
+
@st.cache_resource
|
| 18 |
+
def get_model(temperature):
|
| 19 |
+
generation_config = {
|
| 20 |
+
"temperature": temperature,
|
|
|
|
| 21 |
}
|
| 22 |
+
return genai.GenerativeModel('gemini-2.0-flash', generation_config=generation_config)
|
| 23 |
+
|
| 24 |
+
# Update the generate_benefits function to include selected_angle
|
| 25 |
+
def generate_benefits(number_of_benefits, target_audience, product, temperature, selected_formula, selected_angle):
|
| 26 |
+
if not target_audience or not product:
|
| 27 |
+
return "Por favor, completa todos los campos requeridos."
|
| 28 |
+
|
| 29 |
+
model = get_model(temperature)
|
| 30 |
+
benefits_instruction = create_instruction(
|
| 31 |
+
number_of_benefits,
|
| 32 |
+
target_audience,
|
| 33 |
+
product,
|
| 34 |
+
selected_formula,
|
| 35 |
+
selected_angle
|
| 36 |
)
|
| 37 |
+
|
| 38 |
+
response = model.generate_content([benefits_instruction], generation_config={"temperature": temperature})
|
| 39 |
+
return response.parts[0].text if response and response.parts else "Error generating content."
|
| 40 |
+
|
| 41 |
+
# Configurar la interfaz de usuario con Streamlit
|
| 42 |
+
st.set_page_config(page_title="Bullet Benefits Generator", layout="wide")
|
| 43 |
+
|
| 44 |
+
# Leer el contenido del archivo manual.md
|
| 45 |
+
with open("manual.md", "r", encoding="utf-8") as file:
|
| 46 |
+
manual_content = file.read()
|
| 47 |
+
|
| 48 |
+
# Mostrar el contenido del manual en el sidebar
|
| 49 |
+
st.sidebar.markdown(manual_content)
|
| 50 |
+
|
| 51 |
+
# Ocultar elementos de la interfaz
|
| 52 |
+
st.markdown(styles["main_layout"], unsafe_allow_html=True)
|
| 53 |
+
|
| 54 |
+
# Centrar el título y el subtítulo
|
| 55 |
+
st.markdown("<h1 style='text-align: center;'>Bullet Benefits Generator</h1>", unsafe_allow_html=True)
|
| 56 |
+
st.markdown("<h4 style='text-align: center;'>Transforma características en beneficios irresistibles que conectan emocionalmente con tu audiencia.</h4>", unsafe_allow_html=True)
|
| 57 |
+
|
| 58 |
+
# Añadir CSS personalizado para el botón
|
| 59 |
+
st.markdown(styles["button"], unsafe_allow_html=True)
|
| 60 |
+
|
| 61 |
+
# Crear columnas
|
| 62 |
+
col1, col2 = st.columns([1, 2])
|
| 63 |
+
|
| 64 |
+
# Columnas de entrada
|
| 65 |
+
# Inside the column section
|
| 66 |
+
with col1:
|
| 67 |
+
target_audience = st.text_input("¿Quién es tu público objetivo?", placeholder="Ejemplo: Estudiantes Universitarios")
|
| 68 |
+
product = st.text_input("¿Qué producto tienes en mente?", placeholder="Ejemplo: Curso de Inglés")
|
| 69 |
+
number_of_benefits = st.selectbox("Número de Beneficios", options=[1, 2, 3, 4, 5, 6, 7, 8, 9, 10], index=4)
|
| 70 |
+
|
| 71 |
+
# Fix indentation - remove extra spaces
|
| 72 |
+
with st.expander("Opciones avanzadas"):
|
| 73 |
+
selected_formula_key = st.selectbox(
|
| 74 |
+
"Tipo de bullet", # Added label
|
| 75 |
+
options=list(bullet_formulas.keys()),
|
| 76 |
+
label_visibility="visible"
|
| 77 |
+
)
|
| 78 |
+
selected_formula = bullet_formulas[selected_formula_key]
|
| 79 |
+
|
| 80 |
+
selected_angle_key = st.selectbox(
|
| 81 |
+
"Ángulo del bullet", # Added label
|
| 82 |
+
options=list(bullet_angles.keys()),
|
| 83 |
+
label_visibility="visible"
|
| 84 |
+
)
|
| 85 |
+
selected_angle = bullet_angles[selected_angle_key]
|
| 86 |
+
|
| 87 |
+
temperature = st.slider(
|
| 88 |
+
"Nivel de creatividad", # Added label
|
| 89 |
+
min_value=0.0,
|
| 90 |
+
max_value=2.0,
|
| 91 |
+
value=1.0,
|
| 92 |
+
step=0.1,
|
| 93 |
+
label_visibility="visible"
|
| 94 |
+
)
|
| 95 |
+
|
| 96 |
+
submit = st.button("GENERAR LOS BULLETS POINTS")
|
| 97 |
|
| 98 |
+
# Mostrar los beneficios generados
|
| 99 |
+
# Update the submit section to include selected_angle
|
| 100 |
+
if submit:
|
| 101 |
+
if target_audience and product and selected_formula:
|
| 102 |
+
with st.spinner('Generando beneficios...'):
|
| 103 |
+
generated_benefits = generate_benefits(
|
| 104 |
+
number_of_benefits,
|
| 105 |
+
target_audience,
|
| 106 |
+
product,
|
| 107 |
+
temperature,
|
| 108 |
+
selected_formula,
|
| 109 |
+
selected_angle
|
| 110 |
+
)
|
| 111 |
+
if not isinstance(generated_benefits, str):
|
| 112 |
+
col2.error("Error al generar beneficios")
|
| 113 |
+
else:
|
| 114 |
+
col2.markdown(f"""
|
| 115 |
+
<div style="{styles['results_container']}">
|
| 116 |
+
<h3>Beneficios Generados:</h3>
|
| 117 |
+
<p>{generated_benefits}</p>
|
| 118 |
+
</div>
|
| 119 |
+
""", unsafe_allow_html=True)
|
| 120 |
|
| 121 |
+
else:
|
| 122 |
+
col2.warning("Por favor, completa todos los campos antes de generar beneficios.")
|