Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,71 +1,104 @@
|
|
1 |
-
import gradio as gr
|
2 |
-
import google.generativeai as genai
|
3 |
-
import os
|
4 |
from dotenv import load_dotenv
|
5 |
-
|
6 |
-
import
|
|
|
|
|
7 |
|
8 |
-
# Cargar variables de entorno
|
9 |
load_dotenv()
|
10 |
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
def
|
15 |
-
|
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 |
-
|
44 |
-
"* Truco: 'Un sistema tonto para escribir copy sin tratar de convencer de que me compren.' "
|
45 |
-
"* El de la verdad: 'La verdad que nunca te han dicho en el colegio, la escuela, ni en tu casa de cómo vivir de la música.' "
|
46 |
-
"* Haciendo una pregunta: '¿Sabías que...' "
|
47 |
-
"* Cuando: '¿Cuándo es buena idea decirle a una chica que te gusta? Si no lo dices justo en ese momento, despídete de que la conozcas íntimamente.' "
|
48 |
-
],
|
49 |
-
},
|
50 |
-
]
|
51 |
-
)
|
52 |
-
|
53 |
-
response = chat_session.send_message("Genera los beneficios o bullets") # Enviar mensaje para obtener la respuesta
|
54 |
-
return to_markdown(response.text) # Usar to_markdown para formatear la respuesta
|
55 |
-
|
56 |
-
# Configurar la interfaz de usuario con Gradio
|
57 |
-
iface = gr.Interface(
|
58 |
-
fn=generate_bullets,
|
59 |
-
inputs=[
|
60 |
-
gr.Dropdown(choices=[str(i) for i in range(1, 11)], label="Número de Bullets", value="5"),
|
61 |
-
gr.Textbox(label="Público Objetivo", placeholder="Ejemplo: Estudiantes Universitarios"),
|
62 |
-
gr.Textbox(label="Producto", placeholder="Ejemplo: Curso de Inglés"),
|
63 |
-
gr.Slider(minimum=0, maximum=1, value=0, step=0.1, label="Creatividad")
|
64 |
-
],
|
65 |
-
outputs=gr.Markdown(label="Bullets Generados"),
|
66 |
-
title="Generador de Bullets",
|
67 |
-
description="Usa el poder de Gemini AI para crear bullets atractivos que conecten síntomas con problemas. Ajusta los parámetros para generar bullets que capturen la atención de tu audiencia."
|
68 |
-
)
|
69 |
-
|
70 |
-
# Lanza la interfaz
|
71 |
-
iface.launch()
|
|
|
|
|
|
|
|
|
1 |
from dotenv import load_dotenv
|
2 |
+
import streamlit as st
|
3 |
+
import os
|
4 |
+
import google.generativeai as genai
|
5 |
+
import random
|
6 |
|
|
|
7 |
load_dotenv()
|
8 |
|
9 |
+
genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
|
10 |
+
|
11 |
+
# Función para obtener una mención del producto de manera probabilística
|
12 |
+
def get_random_product_mention():
|
13 |
+
mentions = ["Directa", "Indirecta", "Metafórica"]
|
14 |
+
probabilities = [0.34, 0.33, 0.33]
|
15 |
+
return random.choices(mentions, probabilities)[0]
|
16 |
+
|
17 |
+
# Función para obtener una cantidad de bullets
|
18 |
+
def get_gemini_response_bullets(target_audience, product, num_bullets, creativity):
|
19 |
+
product_mention = get_random_product_mention()
|
20 |
+
model_choice = "gemini-1.5-flash"
|
21 |
+
|
22 |
+
model = genai.GenerativeModel(model_choice)
|
23 |
+
|
24 |
+
# Crear el prompt para generar bullets
|
25 |
+
full_prompt = f"""
|
26 |
+
You are a marketing expert specializing in writing persuasive and impactful benefit bullets for {target_audience}. Write {num_bullets} creative and engaging bullets that highlight the key benefits of {product}. Each bullet should emotionally resonate with the audience, creating a strong connection between the product's features and the problems it solves. The tone should be {creativity}, ensuring each benefit clearly addresses their needs and desires. Use {product_mention} mention.
|
27 |
+
"""
|
28 |
+
|
29 |
+
response = model.generate_content([full_prompt])
|
30 |
+
|
31 |
+
if response and response.parts:
|
32 |
+
return response.parts[0].text
|
33 |
+
else:
|
34 |
+
raise ValueError("Lo sentimos, intenta con una combinación diferente de entradas.")
|
35 |
+
|
36 |
+
# Inicializar la aplicación Streamlit
|
37 |
+
st.set_page_config(page_title="Generador de Bullets", layout="wide")
|
38 |
+
|
39 |
+
# Inicializar el estado de la expansión del acordeón
|
40 |
+
if "accordion_expanded" not in st.session_state:
|
41 |
+
st.session_state["accordion_expanded"] = False
|
42 |
+
|
43 |
+
def toggle_accordion():
|
44 |
+
st.session_state["accordion_expanded"] = not st.session_state["accordion_expanded"]
|
45 |
+
|
46 |
+
# Centrar el título y el subtítulo
|
47 |
+
st.markdown("<h1 style='text-align: center;'>Generador de Bullets</h1>", unsafe_allow_html=True)
|
48 |
+
st.markdown("<h4 style='text-align: center;'>Crea bullets efectivos que conecten emocionalmente con tu audiencia.</h4>", unsafe_allow_html=True)
|
49 |
+
|
50 |
+
# Añadir CSS personalizado para el botón
|
51 |
+
st.markdown("""
|
52 |
+
<style>
|
53 |
+
div.stButton > button {
|
54 |
+
background-color: #FFCC00;
|
55 |
+
color: black;
|
56 |
+
width: 90%;
|
57 |
+
height: 60px;
|
58 |
+
font-weight: bold;
|
59 |
+
font-size: 22px;
|
60 |
+
text-transform: uppercase;
|
61 |
+
border: 1px solid #000000;
|
62 |
+
border-radius: 8px;
|
63 |
+
display: block;
|
64 |
+
margin: 0 auto;
|
65 |
}
|
66 |
+
div.stButton > button:hover {
|
67 |
+
background-color: #FFD700;
|
68 |
+
color: black;
|
69 |
+
}
|
70 |
+
</style>
|
71 |
+
""", unsafe_allow_html=True)
|
72 |
+
|
73 |
+
# Crear dos columnas para el layout (40% y 60%)
|
74 |
+
col1, col2 = st.columns([2, 3])
|
75 |
+
|
76 |
+
with col1:
|
77 |
+
# Campos de entrada
|
78 |
+
target_audience = st.text_input("¿Quién es tu público objetivo?")
|
79 |
+
product = st.text_input("¿Qué producto tienes en mente?")
|
80 |
+
|
81 |
+
# Acordeón para personalizar los bullets
|
82 |
+
with st.expander("Personaliza tus bullets", expanded=st.session_state["accordion_expanded"]):
|
83 |
+
num_bullets = st.slider("Número de Bullets", min_value=1, max_value=15, value=5)
|
84 |
+
creativity = st.selectbox("Creatividad", ["Alta", "Media", "Baja"])
|
85 |
+
|
86 |
+
# Botón de enviar
|
87 |
+
submit = st.button("Generar Bullets", on_click=toggle_accordion)
|
88 |
|
89 |
+
# Mostrar los bullets generados
|
90 |
+
if submit:
|
91 |
+
if target_audience and product:
|
92 |
+
try:
|
93 |
+
# Obtener la respuesta del modelo
|
94 |
+
generated_bullets = get_gemini_response_bullets(target_audience, product, num_bullets, creativity)
|
95 |
+
col2.markdown("""
|
96 |
+
<div style="border: 1px solid #000000; padding: 5px; border-radius: 8px; background-color: #ffffff;">
|
97 |
+
<h4>Aquí están tus bullets:</h4>
|
98 |
+
<p>{}</p>
|
99 |
+
</div>
|
100 |
+
""".format(generated_bullets), unsafe_allow_html=True)
|
101 |
+
except ValueError as e:
|
102 |
+
col2.error(f"Error: {str(e)}")
|
103 |
+
else:
|
104 |
+
col2.error("Por favor, proporciona el público objetivo y el producto.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|