Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -10,65 +10,53 @@ load_dotenv()
|
|
10 |
# Configurar la API de Google
|
11 |
genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
|
12 |
|
13 |
-
# Funci贸n que genera descripciones de menciones usando el producto como variable
|
14 |
-
def mention_descriptions(product):
|
15 |
-
return {
|
16 |
-
"Directa": f"Introduce el producto '{product}' como la soluci贸n clara al problema que enfrenta el lector.",
|
17 |
-
"Indirecta": f"Referencia el producto '{product}' como una posible soluci贸n sin nombrarlo expl铆citamente.",
|
18 |
-
"Metaf贸rica": f"Usa una met谩fora para conectar el producto '{product}' con la soluci贸n necesaria."
|
19 |
-
}
|
20 |
-
|
21 |
# Funci贸n para obtener una menci贸n del producto de manera probabil铆stica
|
22 |
def get_random_product_mention():
|
23 |
mentions = ["Directa", "Indirecta", "Metaf贸rica"]
|
24 |
-
probabilities = [0.
|
25 |
return random.choices(mentions, probabilities)[0]
|
26 |
|
27 |
# Crear la instrucci贸n de menci贸n basada en la opci贸n seleccionada
|
28 |
def get_mention_instruction(product_mention, product):
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
"
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
# Retornar la descripci贸n de la menci贸n seleccionada junto con ejemplos
|
50 |
-
return f"{mention_dict[product_mention]} Ejemplos: {', '.join(examples[product_mention])}"
|
51 |
|
52 |
-
# Funci贸n que obtiene una instrucci贸n aleatoria de menci贸n
|
53 |
-
def get_random_mention_instruction(product):
|
54 |
-
mention_type = get_random_product_mention() # Obtener tipo de menci贸n aleatoria
|
55 |
-
mention_instruction = get_mention_instruction(mention_type, product) # Obtener instrucci贸n con base en el producto y tipo de menci贸n
|
56 |
-
return mention_instruction
|
57 |
-
|
58 |
# Funci贸n para obtener una cantidad de bullets
|
59 |
-
def
|
60 |
product_mention = get_random_product_mention()
|
61 |
-
mention_instruction = get_mention_instruction(product_mention, product) #
|
62 |
model_choice = "gemini-1.5-flash" # Modelo por defecto
|
63 |
|
64 |
model = genai.GenerativeModel(model_choice)
|
65 |
|
66 |
# System Prompt - Instrucci贸n en ingl茅s para el modelo
|
67 |
-
system_instruction =
|
68 |
-
You are a world-class copywriter, expert in creating benefits that connect symptoms with problems
|
69 |
-
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.'.
|
70 |
-
|
71 |
-
|
|
|
|
|
|
|
|
|
|
|
72 |
* 'The bathroom cabinet is the best place to store medicine, right? Incorrect. It's the worst. The facts are on page 10.'
|
73 |
* 'The best verb tense that gives your clients the feeling they've already bought from you.'
|
74 |
* 'The story of...', 'The mysteries of...', 'The legend of...'
|
@@ -82,29 +70,16 @@ def generate_bullets(number_of_bullets, target_audience, product, temperature):
|
|
82 |
- Direct: Clearly highlight the product as the solution.
|
83 |
- Indirect: Subtly suggest the product without naming it.
|
84 |
- Metaphorical: Use a metaphor to connect the product to the solution.
|
85 |
-
"""
|
86 |
-
|
87 |
-
# Crear el prompt para generar bullets
|
88 |
-
full_prompt = f"""
|
89 |
-
Write {number_of_bullets} unusual, creative, and fascinating bullets that capturing readers' attention.
|
90 |
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:'
|
91 |
Please create the bullets now.
|
92 |
"""
|
93 |
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
return generated_bullets
|
101 |
-
except Exception as e:
|
102 |
-
raise ValueError(f"Tuvimos este error al generar los bullets: {str(e)}")
|
103 |
-
|
104 |
-
# Example usage
|
105 |
-
if __name__ == "__main__":
|
106 |
-
bullets = generate_bullets(5, "target audience", "product name", 0.7)
|
107 |
-
print(bullets)
|
108 |
|
109 |
# Inicializar la aplicaci贸n Streamlit
|
110 |
st.set_page_config(page_title="Generador de Bullets", layout="wide")
|
@@ -145,8 +120,8 @@ with col1:
|
|
145 |
product = st.text_input("驴Qu茅 producto tienes en mente?")
|
146 |
|
147 |
# Campos de personalizaci贸n sin acorde贸n
|
148 |
-
|
149 |
-
|
150 |
|
151 |
# Bot贸n de enviar
|
152 |
submit = st.button("Generar Bullets")
|
@@ -156,7 +131,7 @@ if submit:
|
|
156 |
if target_audience and product:
|
157 |
try:
|
158 |
# Obtener la respuesta del modelo
|
159 |
-
generated_bullets =
|
160 |
col2.markdown(f"""
|
161 |
<div style="border: 1px solid #000000; padding: 5px; border-radius: 8px; background-color: #ffffff;">
|
162 |
<h4>Observa la magia en acci贸n:</h4>
|
|
|
10 |
# Configurar la API de Google
|
11 |
genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
|
12 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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.34, 0.33, 0.33]
|
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 |
+
return f"""
|
23 |
+
Directly introduce the product '{product}' as the clear solution to the problem the reader is facing. Ensure that the product is presented in a way that highlights its key benefits and demonstrates how it directly addresses the issue at hand. The mention should feel natural and seamlessly integrated into the narrative.
|
24 |
+
"""
|
25 |
+
elif product_mention == "Indirecta":
|
26 |
+
return f"""
|
27 |
+
Subtly reference the product '{product}' as a potential solution to the reader's problem without naming it explicitly. Weave the product's core benefits into the description of how the reader can overcome the issue, creating an implicit connection between the solution and the product. Ensure the mention is subtle but clear enough to guide the reader towards the product.
|
28 |
+
"""
|
29 |
+
elif product_mention == "Metaf贸rica":
|
30 |
+
return f"""
|
31 |
+
Introduce the product '{product}' using a metaphor, connecting it symbolically to the solution the reader needs. The metaphor should relate to the problem being discussed and should creatively suggest how the product offers a resolution without explicitly stating its name. The metaphor should evoke the benefits of the product in a memorable and thought-provoking way.
|
32 |
+
"""
|
33 |
+
return ""
|
34 |
+
|
35 |
+
# System Prompt - Instrucci贸n en ingl茅s para el modelo
|
36 |
+
system_instruction = """
|
37 |
+
You are a world-class copywriter, expert in creating benefits that connect symptoms with problems. You deeply understand the emotions, desires, and challenges of a specific audience, allowing you to design personalized marketing strategies that resonate and motivate action. You know how to use proven structures to attract your target audience, generating interest and creating a powerful connection.
|
38 |
+
Generate unusual, creative, and fascinating bullets that capture readers' attention about the product. Respond in Spanish and use a numbered list format. Important: Only answer bullets, 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(este bullet es cursioso).'.
|
39 |
+
"""
|
|
|
|
|
|
|
40 |
|
|
|
|
|
|
|
|
|
|
|
|
|
41 |
# Funci贸n para obtener una cantidad de bullets
|
42 |
+
def get_gemini_response_bullets(target_audience, product, num_bullets, creativity):
|
43 |
product_mention = get_random_product_mention()
|
44 |
+
mention_instruction = get_mention_instruction(product_mention, product) # Define aqu铆
|
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 a specific audience, allowing you to design personalized marketing strategies that resonate and motivate action. You know how to use proven structures to attract your target audience, generating interest and creating a powerful connection.
|
52 |
+
Generate unusual, creative, and fascinating bullets that subtly hint at the product without direct mention, capturing readers' attention. 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.'.
|
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 |
- 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 |
+
response = model.generate_content([full_prompt])
|
78 |
+
|
79 |
+
if response and response.parts:
|
80 |
+
return response.parts[0].text
|
81 |
+
else:
|
82 |
+
raise ValueError("Lo sentimos, intenta con una combinaci贸n diferente de entradas.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
83 |
|
84 |
# Inicializar la aplicaci贸n Streamlit
|
85 |
st.set_page_config(page_title="Generador de Bullets", layout="wide")
|
|
|
120 |
product = st.text_input("驴Qu茅 producto tienes en mente?")
|
121 |
|
122 |
# Campos de personalizaci贸n sin acorde贸n
|
123 |
+
num_bullets = st.slider("N煤mero de Bullets", min_value=1, max_value=15, value=5)
|
124 |
+
creativity = st.selectbox("Creatividad", ["Alta", "Media", "Baja"])
|
125 |
|
126 |
# Bot贸n de enviar
|
127 |
submit = st.button("Generar Bullets")
|
|
|
131 |
if target_audience and product:
|
132 |
try:
|
133 |
# Obtener la respuesta del modelo
|
134 |
+
generated_bullets = get_gemini_response_bullets(target_audience, product, num_bullets, creativity)
|
135 |
col2.markdown(f"""
|
136 |
<div style="border: 1px solid #000000; padding: 5px; border-radius: 8px; background-color: #ffffff;">
|
137 |
<h4>Observa la magia en acci贸n:</h4>
|