Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -36,18 +36,32 @@ preguntas_retoricas = [
|
|
36 |
"¿Cuándo es una buena idea decirle a una chica que te gusta? Si no se lo dices en ese momento, despídete de conocerla íntimamente."
|
37 |
]
|
38 |
|
39 |
-
# Función para generar bullets
|
40 |
def generate_bullets(target_audience, product, call_to_action, number_of_bullets):
|
41 |
bullets = []
|
42 |
|
43 |
-
# Lista combinada de todas las categorías
|
44 |
all_categories = directos + misterios + leyendas + historias_personales + preguntas_retoricas
|
45 |
-
|
46 |
-
# Selecciona bullets aleatorios de la lista combinada
|
47 |
-
for _ in range(number_of_bullets):
|
48 |
-
bullet = random.choice(all_categories)
|
49 |
-
bullets.append(bullet)
|
50 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
51 |
return bullets
|
52 |
|
53 |
# Configurar la interfaz de usuario con Streamlit
|
@@ -138,7 +152,7 @@ with col1:
|
|
138 |
if submit:
|
139 |
if target_audience and product and call_to_action:
|
140 |
try:
|
141 |
-
#
|
142 |
generated_bullets = generate_bullets(target_audience, product, call_to_action, number_of_bullets)
|
143 |
col2.markdown(f"""
|
144 |
<div style="border: 1px solid #000000; padding: 5px; border-radius: 8px; background-color: #ffffff;">
|
|
|
36 |
"¿Cuándo es una buena idea decirle a una chica que te gusta? Si no se lo dices en ese momento, despídete de conocerla íntimamente."
|
37 |
]
|
38 |
|
39 |
+
# Función para generar bullets combinados o utilizando la API de Google
|
40 |
def generate_bullets(target_audience, product, call_to_action, number_of_bullets):
|
41 |
bullets = []
|
42 |
|
43 |
+
# Lista combinada de todas las categorías de bullets predefinidos
|
44 |
all_categories = directos + misterios + leyendas + historias_personales + preguntas_retoricas
|
|
|
|
|
|
|
|
|
|
|
45 |
|
46 |
+
# Generar bullets utilizando la API de Google Generative AI
|
47 |
+
prompt = f"""
|
48 |
+
Estoy creando bullets para una campaña de marketing dirigida a {target_audience}.
|
49 |
+
El producto es {product} y el objetivo es que los usuarios realicen la siguiente acción: {call_to_action}.
|
50 |
+
|
51 |
+
Por favor, genera {number_of_bullets} bullets persuasivos que resalten beneficios, problemas y curiosidades para la audiencia objetivo.
|
52 |
+
"""
|
53 |
+
|
54 |
+
try:
|
55 |
+
# Hacer la llamada a la API y generar bullets
|
56 |
+
response = genai.generate_text(prompt=prompt, max_tokens=150)
|
57 |
+
generated_bullets = response['candidates'][0]['output'].split('\n')[:number_of_bullets] # Tomar la cantidad de bullets solicitados
|
58 |
+
bullets.extend(generated_bullets)
|
59 |
+
except Exception as e:
|
60 |
+
# Si falla la API, genera bullets aleatorios de las categorías predefinidas
|
61 |
+
for _ in range(number_of_bullets):
|
62 |
+
bullet = random.choice(all_categories)
|
63 |
+
bullets.append(bullet)
|
64 |
+
|
65 |
return bullets
|
66 |
|
67 |
# Configurar la interfaz de usuario con Streamlit
|
|
|
152 |
if submit:
|
153 |
if target_audience and product and call_to_action:
|
154 |
try:
|
155 |
+
# Generar los bullets usando la API y la lista predefinida
|
156 |
generated_bullets = generate_bullets(target_audience, product, call_to_action, number_of_bullets)
|
157 |
col2.markdown(f"""
|
158 |
<div style="border: 1px solid #000000; padding: 5px; border-radius: 8px; background-color: #ffffff;">
|