Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,6 +2,7 @@ from dotenv import load_dotenv
|
|
| 2 |
import streamlit as st
|
| 3 |
import os
|
| 4 |
import google.generativeai as genai
|
|
|
|
| 5 |
|
| 6 |
# Cargar las variables de entorno
|
| 7 |
load_dotenv()
|
|
@@ -9,51 +10,80 @@ load_dotenv()
|
|
| 9 |
# Configurar la API de Google
|
| 10 |
genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
|
| 11 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
# Función para obtener una cantidad de bullets
|
| 13 |
def get_gemini_response_bullets(target_audience, product, num_bullets, temperature):
|
|
|
|
| 14 |
|
| 15 |
-
#
|
| 16 |
-
|
| 17 |
-
"temperature": temperature,
|
| 18 |
-
"top_p": 0.9, # Aumentar para permitir una mayor diversidad en las opciones generadas
|
| 19 |
-
"top_k": 90,
|
| 20 |
-
"max_output_tokens": 2048,
|
| 21 |
-
"response_mime_type": "text/plain",
|
| 22 |
-
}
|
| 23 |
|
|
|
|
| 24 |
model = genai.GenerativeModel(
|
| 25 |
-
model_name=
|
| 26 |
-
generation_config=
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
system_instruction=(
|
| 28 |
-
f"
|
| 29 |
-
"
|
| 30 |
-
f"
|
| 31 |
-
|
| 32 |
-
f"
|
| 33 |
-
f"Generando curiosidad y ganas de saber más sobre {product}. "
|
| 34 |
-
f"¡Haz que se sientan incluidos! Usa un tono amistoso y divertido. "
|
| 35 |
-
f"Por ejemplo, si están buscando {product}, dales un motivo irresistible para seguir leyendo. "
|
| 36 |
-
f"Incluye un encabezado atractivo que diga: 'Aquí tienes {num_bullets} razones por las que {target_audience} debería considerar {product}'."
|
| 37 |
)
|
| 38 |
)
|
| 39 |
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
)
|
| 45 |
|
| 46 |
-
#
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
# Retornar el resultado
|
| 54 |
-
return generated_bullets
|
| 55 |
-
except Exception as e:
|
| 56 |
-
raise ValueError(f"Error al generar los bullets: {str(e)}")
|
| 57 |
|
| 58 |
# Inicializar la aplicación Streamlit
|
| 59 |
st.set_page_config(page_title="Generador de Bullets", layout="wide")
|
|
|
|
| 2 |
import streamlit as st
|
| 3 |
import os
|
| 4 |
import google.generativeai as genai
|
| 5 |
+
import random
|
| 6 |
|
| 7 |
# Cargar las variables de entorno
|
| 8 |
load_dotenv()
|
|
|
|
| 10 |
# Configurar la API de Google
|
| 11 |
genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
|
| 12 |
|
| 13 |
+
# Diccionario de ejemplos de bullets
|
| 14 |
+
bullets_examples = {
|
| 15 |
+
"1": "El armario del baño es el mejor lugar para guardar medicamentos, ¿verdad? Incorrecto. Es el peor. Los hechos están en la página 10.",
|
| 16 |
+
"2": "El mejor tiempo verbal que le da a tus clientes la sensación de que ya te han comprado.",
|
| 17 |
+
"3": "La historia de un joven emprendedor que transformó su vida aplicando esta técnica simple pero poderosa.",
|
| 18 |
+
"4": "Los misterios de cómo algunas personas parecen tener éxito sin esfuerzo, mientras otras luchan. La clave está en esta pequeña diferencia.",
|
| 19 |
+
"5": "La leyenda de aquellos que dominaron la productividad con un solo hábito. ¿Te atreves a descubrirlo?",
|
| 20 |
+
"6": "Un sistema simple para escribir textos sin intentar convencerlos de comprar.",
|
| 21 |
+
"7": "La verdad que nunca te han contado en la escuela, o en casa, sobre cómo ganarte la vida con la música.",
|
| 22 |
+
"8": "La historia de un padre ocupado que, con solo 10 minutos al día, logró transformar su salud y bienestar.",
|
| 23 |
+
"9": "Los misterios de cómo una técnica sencilla te permite reducir el estrés al instante, sin necesidad de dejar tu trabajo o cambiar tu estilo de vida.",
|
| 24 |
+
"10": "¿Sabías que muchas personas están usando este método y han mejorado su bienestar en solo 7 días?",
|
| 25 |
+
"11": "¿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."
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
# Función para obtener una cantidad de bullets
|
| 29 |
def get_gemini_response_bullets(target_audience, product, num_bullets, temperature):
|
| 30 |
+
model_choice = "gemini-1.5-flash" # Modelo por defecto
|
| 31 |
|
| 32 |
+
# Seleccionar un bullet aleatorio de los ejemplos
|
| 33 |
+
selected_bullet = random.choice(list(bullets_examples.values()))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
|
| 35 |
+
# Configuración del modelo generativo y las instrucciones del sistema
|
| 36 |
model = genai.GenerativeModel(
|
| 37 |
+
model_name=model_choice,
|
| 38 |
+
generation_config={
|
| 39 |
+
"temperature": temperature,
|
| 40 |
+
"top_p": 0.85,
|
| 41 |
+
"top_k": 128,
|
| 42 |
+
"max_output_tokens": 2048,
|
| 43 |
+
"response_mime_type": "text/plain",
|
| 44 |
+
},
|
| 45 |
system_instruction=(
|
| 46 |
+
f"You are a world-class copywriter, expert in creating benefits that connect symptoms with problems of {target_audience}. "
|
| 47 |
+
f"You deeply understand the emotions, desires, and challenges of {target_audience}, allowing you to design personalized copywriting that resonate and motivate action. "
|
| 48 |
+
f"You know how to use proven structures to attract {target_audience}, generating interest and creating a powerful connection with {product}. "
|
| 49 |
+
"Generate unusual, creative, and fascinating bullets that capturing {target_audience}'s attention. Respond in Spanish and use a numbered list format. "
|
| 50 |
+
f"When responding, always include a heading referencing {target_audience} and the product as follows: 'Aquí hay {num_bullets} bullets para convencer a {target_audience}, de [beneficio de comprar, asistir, descargar, adquirir,] {product}' "
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
)
|
| 52 |
)
|
| 53 |
|
| 54 |
+
# Crear la instrucción para generar bullets
|
| 55 |
+
chat_session = model.start_chat(
|
| 56 |
+
history=[
|
| 57 |
+
{
|
| 58 |
+
"role": "user",
|
| 59 |
+
"parts": [
|
| 60 |
+
f"Tu tarea es escribir {num_bullets} bullets que denoten los beneficios del {product} y que tienen la cualidad de fascinar y por lo tanto, fomentan el deseo de adquirir, asistir, descargar o comprar el {product}."
|
| 61 |
+
f"Un buen bullet conecta los síntomas con los problemas enfrentados por {target_audience} de una manera natural, que no se note como manipuladora."
|
| 62 |
+
f"Escribe bullets creativos, en un estilo conversacional, que no sean aburridos, sino más bien divertidos. "
|
| 63 |
+
f"Sé sutil a la hora de crear los bullets para referirte a los beneficios del {product}. "
|
| 64 |
+
f"Usa este ejemplo como inspiración: {selected_bullet}." # Añadir bullet aleatorio
|
| 65 |
+
"1. **Connection**: Words that highlight the relationship between the product and the benefit for the user (e.g., 'Improve,' 'Transform').\n"
|
| 66 |
+
"2. **Benefit**: Explain how the user will benefit by attending, downloading, or purchasing the product.\n\n"
|
| 67 |
+
"Ensure each bullet follows the structure of 'Connection + connector + Benefit,' and avoid including explanations like 'Connection: Improve' or 'Benefit: Increase my happiness.'\n"
|
| 68 |
+
"Important: Only respond with bullets, never include explanations or categories, like this example: 'Attend the masterclass and discover techniques to boost your professional career.' (This bullet appeals to the desire for personal and professional growth.)\n"
|
| 69 |
+
"Use these guidelines to generate high-converting bullets in Spanish."
|
| 70 |
+
"Important: Never include explanations or categories, like this: 'La leyenda del padre soltero: Dice que nunca hay tiempo suficiente. El yoga te enseña a usar mejor el tiempo que tienes, incluso cuando te parece imposible.' "
|
| 71 |
+
"Bullets should vary, based on these examples to guide your task of creating bullets:\n\n"
|
| 72 |
+
f"* {selected_bullet} "
|
| 73 |
+
# Añadir más ejemplos si es necesario
|
| 74 |
+
"Por favor, crea los bullets ahora."
|
| 75 |
+
],
|
| 76 |
+
},
|
| 77 |
+
]
|
| 78 |
)
|
| 79 |
|
| 80 |
+
# Crear un mensaje para el modelo que incluye los bullets generados
|
| 81 |
+
response = model.generate_content(chat_session.history) # Aquí usamos el historial del chat
|
| 82 |
+
|
| 83 |
+
if response and response.parts:
|
| 84 |
+
return response.parts[0].text
|
| 85 |
+
else:
|
| 86 |
+
raise ValueError("Lo sentimos, intenta con una combinación diferente de entradas.")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 87 |
|
| 88 |
# Inicializar la aplicación Streamlit
|
| 89 |
st.set_page_config(page_title="Generador de Bullets", layout="wide")
|