Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -13,50 +13,55 @@ genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
|
|
13 |
# Funci贸n para obtener una menci贸n del producto de manera probabil铆stica
|
14 |
def get_random_product_mention():
|
15 |
mentions = ["Directa", "Indirecta", "Metaf贸rica"]
|
16 |
-
probabilities = [0.
|
17 |
return random.choices(mentions, probabilities)[0]
|
18 |
|
19 |
# Crear la instrucci贸n de menci贸n basada en la opci贸n seleccionada
|
20 |
def get_mention_instruction(product_mention, product):
|
21 |
if product_mention == "Directa":
|
22 |
-
|
23 |
-
|
24 |
-
|
|
|
|
|
|
|
|
|
25 |
elif product_mention == "Indirecta":
|
26 |
-
|
27 |
-
|
28 |
-
|
|
|
|
|
|
|
|
|
29 |
elif product_mention == "Metaf贸rica":
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
|
|
|
|
41 |
# Funci贸n para obtener una cantidad de bullets
|
42 |
-
def
|
43 |
product_mention = get_random_product_mention()
|
44 |
-
mention_instruction =
|
45 |
model_choice = "gemini-1.5-flash" # Modelo por defecto
|
46 |
|
47 |
model = genai.GenerativeModel(model_choice)
|
48 |
|
49 |
# System Prompt - Instrucci贸n en ingl茅s para el modelo
|
50 |
-
system_instruction = """
|
51 |
-
You are a world-class copywriter, expert in creating benefits that connect symptoms with problems. You deeply understand the emotions, desires, and challenges of
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
# Crear el prompt para generar bullets
|
56 |
-
full_prompt = f"""
|
57 |
-
{system_instruction}
|
58 |
-
Your task is to create {num_bullets} benefits or bullets that connect the symptom with the problem faced by {target_audience}, increasing their desire to acquire the {product}.
|
59 |
-
Infuse your responses with a creativity level of {creativity}. The bullets should be of the following types:
|
60 |
* 'The bathroom cabinet is the best place to store medicine, right? Incorrect. It's the worst. The facts are on page 10.'
|
61 |
* 'The best verb tense that gives your clients the feeling they've already bought from you.'
|
62 |
* 'The story of...', 'The mysteries of...', 'The legend of...'
|
@@ -70,16 +75,29 @@ def get_gemini_response_bullets(target_audience, product, num_bullets, creativit
|
|
70 |
- Direct: Clearly highlight the product as the solution.
|
71 |
- Indirect: Subtly suggest the product without naming it.
|
72 |
- Metaphorical: Use a metaphor to connect the product to the solution.
|
|
|
|
|
|
|
|
|
|
|
73 |
When responding, always include a headline that references the {target_audience} and the product in the following way: 'Aqu铆 tienes 5 bullets para Pap谩s solteros, que aumenten el deseo de adquirir el Aceite multigrado, usando la menci贸n indirecta:'
|
74 |
Please create the bullets now.
|
75 |
"""
|
76 |
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
83 |
|
84 |
# Inicializar la aplicaci贸n Streamlit
|
85 |
st.set_page_config(page_title="Generador de Bullets", layout="wide")
|
|
|
13 |
# Funci贸n para obtener una menci贸n del producto de manera probabil铆stica
|
14 |
def get_random_product_mention():
|
15 |
mentions = ["Directa", "Indirecta", "Metaf贸rica"]
|
16 |
+
probabilities = [0.25, 0.35, 0.40]
|
17 |
return random.choices(mentions, probabilities)[0]
|
18 |
|
19 |
# Crear la instrucci贸n de menci贸n basada en la opci贸n seleccionada
|
20 |
def get_mention_instruction(product_mention, product):
|
21 |
if product_mention == "Directa":
|
22 |
+
examples = [
|
23 |
+
f"Este curso de ingl茅s te proporcionar谩 las herramientas necesarias para abrir nuevas oportunidades laborales.",
|
24 |
+
f"Con este curso de ingl茅s, transforma tu carrera y tu vida familiar.",
|
25 |
+
f"No permitas que la falta de ingl茅s limite tu futuro; inscr铆bete y empieza a disfrutar de m谩s tiempo con tus peque帽os."
|
26 |
+
]
|
27 |
+
return f"Directly introduce the product '{product}' as the clear solution to the problem the reader is facing. Examples: {', '.join(examples)}"
|
28 |
+
|
29 |
elif product_mention == "Indirecta":
|
30 |
+
examples = [
|
31 |
+
f"Imagina tener la confianza hablando un idioma diferente para brillar en tus reuniones de trabajo.",
|
32 |
+
f"El mejor regalo que puedes darles a tus hijos es su crecimiento profesional dandoles herramientas como otros idiomas.",
|
33 |
+
f"Visualiza c贸mo tus peque帽os se sentir谩n orgullosos al verte alcanzar esa promoci贸n por hablar en otro idioma."
|
34 |
+
]
|
35 |
+
return f"Subtly reference the product '{product}' as a potential solution to the reader's problem without naming it explicitly. Examples: {', '.join(examples)}"
|
36 |
+
|
37 |
elif product_mention == "Metaf贸rica":
|
38 |
+
examples = [
|
39 |
+
f"Aprender ingl茅s es como lanzarse a la piscina: al principio puede dar miedo.",
|
40 |
+
f"El dominio del ingl茅s es tu br煤jula en el oc茅ano laboral.",
|
41 |
+
f"Dominar el ingl茅s es encender una luz en la oscuridad."
|
42 |
+
]
|
43 |
+
return f"Introduce the product '{product}' using a metaphor, symbolically connecting it to the solution the reader needs. Examples: {', '.join(examples)}"
|
44 |
+
|
45 |
+
# Function to get a random mention instruction
|
46 |
+
def get_random_mention_instruction():
|
47 |
+
mention_type = get_random_product_mention() # Get random mention type
|
48 |
+
examples = mention_types[mention_type] # Get examples based on mention type
|
49 |
+
return f"{examples[0]} Examples: {examples[1]}"
|
50 |
+
|
51 |
# Funci贸n para obtener una cantidad de bullets
|
52 |
+
def generate_bullets(number_of_bullets, target_audience, product, temperature):
|
53 |
product_mention = get_random_product_mention()
|
54 |
+
mention_instruction = get_random_mention_instruction() # Get mention instruction
|
55 |
model_choice = "gemini-1.5-flash" # Modelo por defecto
|
56 |
|
57 |
model = genai.GenerativeModel(model_choice)
|
58 |
|
59 |
# System Prompt - Instrucci贸n en ingl茅s para el modelo
|
60 |
+
system_instruction = f"""
|
61 |
+
You are a world-class copywriter, expert in creating benefits that connect symptoms with problems of {target_audience}. You deeply understand the emotions, desires, and challenges of {target_audience}, allowing you to design personalized copywriting that resonate and motivate action. You know how to use proven structures to attract your {target_audience}, generating interest and creating a powerful connection with {product}.
|
62 |
+
Respond in Spanish and use a numbered list format. 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.'.
|
63 |
+
Your task is to create benefits or bullets that connect the symptom with the problem faced by {target_audience}, increasing their desire to acquire the {product}.
|
64 |
+
Infuse your responses with a creativity level that aligns with the specified temperature of {creativity}, leveraging the imaginative capabilities of the Gemini 1.5 Flash model to produce innovative and boundary-pushing ideas. The bullets should be of the following types:
|
|
|
|
|
|
|
|
|
|
|
65 |
* 'The bathroom cabinet is the best place to store medicine, right? Incorrect. It's the worst. The facts are on page 10.'
|
66 |
* 'The best verb tense that gives your clients the feeling they've already bought from you.'
|
67 |
* 'The story of...', 'The mysteries of...', 'The legend of...'
|
|
|
75 |
- Direct: Clearly highlight the product as the solution.
|
76 |
- Indirect: Subtly suggest the product without naming it.
|
77 |
- Metaphorical: Use a metaphor to connect the product to the solution.
|
78 |
+
"""
|
79 |
+
|
80 |
+
# Crear el prompt para generar bullets
|
81 |
+
full_prompt = f"""
|
82 |
+
Write {num_bullets} unusual, creative, and fascinating bullets that capturing readers' attention.
|
83 |
When responding, always include a headline that references the {target_audience} and the product in the following way: 'Aqu铆 tienes 5 bullets para Pap谩s solteros, que aumenten el deseo de adquirir el Aceite multigrado, usando la menci贸n indirecta:'
|
84 |
Please create the bullets now.
|
85 |
"""
|
86 |
|
87 |
+
try:
|
88 |
+
response = model.generate_content([full_prompt])
|
89 |
+
|
90 |
+
# Extract text from the response
|
91 |
+
generated_bullets = response.candidates[0].content.parts[0].text.strip()
|
92 |
+
|
93 |
+
return generated_bullets
|
94 |
+
except Exception as e:
|
95 |
+
raise ValueError(f"Tuvimos este error al generar los bullets: {str(e)}")
|
96 |
+
|
97 |
+
# Example usage
|
98 |
+
if __name__ == "__main__":
|
99 |
+
bullets = generate_bullets(5, "target audience", "product name", 0.7)
|
100 |
+
print(bullets)
|
101 |
|
102 |
# Inicializar la aplicaci贸n Streamlit
|
103 |
st.set_page_config(page_title="Generador de Bullets", layout="wide")
|