Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,3 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
def generate_bullets(number_of_bullets, target_audience, product, call_to_action, temperature):
|
2 |
# Configuración del modelo
|
3 |
generation_config = {
|
@@ -41,3 +54,64 @@ def generate_bullets(number_of_bullets, target_audience, product, call_to_action
|
|
41 |
raise ValueError("No se generaron bullets válidos.")
|
42 |
except Exception as e:
|
43 |
raise ValueError(f"Error al generar los bullets: {str(e)}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from dotenv import load_dotenv
|
2 |
+
import streamlit as st
|
3 |
+
import os
|
4 |
+
import google.generativeai as genai
|
5 |
+
import langchain
|
6 |
+
|
7 |
+
# Cargar las variables de entorno
|
8 |
+
load_dotenv()
|
9 |
+
|
10 |
+
# Configurar la API de Google
|
11 |
+
genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
|
12 |
+
|
13 |
+
# Generar el resultado utilizando el modelo con la instrucción de bullets específica
|
14 |
def generate_bullets(number_of_bullets, target_audience, product, call_to_action, temperature):
|
15 |
# Configuración del modelo
|
16 |
generation_config = {
|
|
|
54 |
raise ValueError("No se generaron bullets válidos.")
|
55 |
except Exception as e:
|
56 |
raise ValueError(f"Error al generar los bullets: {str(e)}")
|
57 |
+
|
58 |
+
# Configurar la interfaz de usuario con Streamlit
|
59 |
+
st.set_page_config(page_title="Impact Bullet Generator", layout="wide")
|
60 |
+
|
61 |
+
# Centrar el título y el subtítulo
|
62 |
+
st.markdown("<h1 style='text-align: center;'>Impact Bullet Generator</h1>", unsafe_allow_html=True)
|
63 |
+
st.markdown("<h4 style='text-align: center;'>Transforma los pensamientos de tu audiencia en balas persuasivas que inspiren a la acción.</h4>", unsafe_allow_html=True)
|
64 |
+
|
65 |
+
# Añadir CSS personalizado para el botón
|
66 |
+
st.markdown("""
|
67 |
+
<style>
|
68 |
+
div.stButton > button {
|
69 |
+
background-color: #FFCC00;
|
70 |
+
color: black;
|
71 |
+
width: 90%;
|
72 |
+
height: 60px;
|
73 |
+
font-weight: bold;
|
74 |
+
font-size: 22px;
|
75 |
+
text-transform: uppercase;
|
76 |
+
border: 1px solid #000000;
|
77 |
+
border-radius: 8px;
|
78 |
+
display: block;
|
79 |
+
margin: 0 auto;
|
80 |
+
}
|
81 |
+
div.stButton > button:hover {
|
82 |
+
background-color: #FFD700;
|
83 |
+
color: black;
|
84 |
+
}
|
85 |
+
</style>
|
86 |
+
""", unsafe_allow_html=True)
|
87 |
+
|
88 |
+
# Crear columnas
|
89 |
+
col1, col2 = st.columns([1, 2])
|
90 |
+
|
91 |
+
# Columnas de entrada
|
92 |
+
with col1:
|
93 |
+
target_audience = st.text_input("¿Quién es tu público objetivo?", placeholder="Ejemplo: Estudiantes Universitarios")
|
94 |
+
product = st.text_input("¿Qué producto tienes en mente?", placeholder="Ejemplo: Curso de Inglés")
|
95 |
+
call_to_action = st.text_input("¿Qué acción deseas que tomen?", placeholder="Ejemplo: Inscribirse al curso")
|
96 |
+
number_of_bullets = st.selectbox("Número de bullets", options=[1, 2, 3, 4, 5, 6, 7, 8, 9, 10], index=4)
|
97 |
+
temperature = st.slider("Creatividad", min_value=0.0, max_value=1.0, value=0.5, step=0.1)
|
98 |
+
|
99 |
+
# Botón de enviar
|
100 |
+
submit = st.button("Generar Beneficios")
|
101 |
+
|
102 |
+
# Mostrar los beneficios generados
|
103 |
+
if submit:
|
104 |
+
if target_audience and product and call_to_action:
|
105 |
+
try:
|
106 |
+
# Obtener la respuesta del modelo
|
107 |
+
generated_bullets = generate_bullets(number_of_bullets, target_audience, product, call_to_action, temperature)
|
108 |
+
col2.markdown(f"""
|
109 |
+
<div style="border: 1px solid #000000; padding: 5px; border-radius: 8px; background-color: #ffffff;">
|
110 |
+
<h4>Mira los bullets generados:</h4>
|
111 |
+
<p style="font-size: 22px;">{generated_bullets}</p>
|
112 |
+
</div>
|
113 |
+
""", unsafe_allow_html=True)
|
114 |
+
except Exception as e:
|
115 |
+
st.error(f"Error al generar los bullets: {str(e)}")
|
116 |
+
else:
|
117 |
+
st.error("Por favor, completa todos los campos.")
|