JeCabrera commited on
Commit
f44f10b
verified
1 Parent(s): ae5ef0d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +41 -26
app.py CHANGED
@@ -10,20 +10,26 @@ load_dotenv()
10
  # Configurar la API de Google
11
  genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
12
 
13
- # Funci贸n para obtener una llamada a la acci贸n de manera probabil铆stica
14
- def get_random_call_to_action():
15
- actions = ["Directo", "Sutil", "Indirecto"]
16
  probabilities = [0.34, 0.33, 0.33]
17
- return random.choices(actions, probabilities)[0]
18
-
19
- # Crear la instrucci贸n para la llamada a la acci贸n seg煤n la opci贸n seleccionada
20
- def get_call_to_action_instruction(action_call):
21
- if action_call == "Directo":
22
- return "Incorpora una llamada a la acci贸n clara y directa que motive al lector a actuar de inmediato. La llamada debe ser convincente y destacar la urgencia de tomar acci贸n."
23
- elif action_call == "Sutil":
24
- return "Sugiere una llamada a la acci贸n de manera sutil, insinuando los beneficios de actuar sin ser demasiado obvio. El lector debe sentir que est谩 tomando la decisi贸n por su cuenta."
25
- elif action_call == "Indirecto":
26
- return "Presenta una llamada a la acci贸n de forma indirecta, creando un escenario donde el lector pueda ver la acci贸n como una soluci贸n natural a sus problemas sin nombrarla expl铆citamente."
 
 
 
 
 
 
27
  return ""
28
 
29
  # System Prompt - Instrucci贸n en ingl茅s para el modelo
@@ -33,12 +39,19 @@ Generate unusual, creative, and fascinating bullets that capture readers' attent
33
  """
34
 
35
  # Funci贸n para obtener una cantidad de bullets
36
- def get_gemini_response_bullets(target_audience, num_bullets, creativity, action_call):
37
- call_to_action_instruction = get_call_to_action_instruction(action_call) # Definir la instrucci贸n aqu铆
 
38
  model_choice = "gemini-1.5-flash" # Modelo por defecto
39
 
40
  model = genai.GenerativeModel(model_choice)
41
 
 
 
 
 
 
 
42
  # Crear el prompt para generar bullets
43
  full_prompt = f"""
44
  {system_instruction}
@@ -51,9 +64,7 @@ def get_gemini_response_bullets(target_audience, num_bullets, creativity, action
51
  * The Truth: 'The truth that you've never been told in school, or at home, about how to make a living from music.'
52
  * Asking a Question: 'Did you know that...'
53
  * When: 'When is it a good idea to tell a girl you like her? If you don't say it at that moment, say goodbye to getting to know her intimately.'
54
- Use the following mention instructions to guide your writing: {call_to_action_instruction}
55
- Additionally, subtly mention the product '{product}' in the bullets without making it the focus. The connection between the action and the product should feel organic and seamless.
56
- Please create the bullets now.
57
  """
58
 
59
  response = model.generate_content([full_prompt])
@@ -61,11 +72,18 @@ def get_gemini_response_bullets(target_audience, num_bullets, creativity, action
61
  if response and response.parts:
62
  return response.parts[0].text
63
  else:
64
- raise ValueError("Lo siento, intenta con una combinaci贸n diferente de valores.")
65
 
66
  # Inicializar la aplicaci贸n Streamlit
67
  st.set_page_config(page_title="Generador de Bullets", layout="wide")
68
 
 
 
 
 
 
 
 
69
  # Centrar el t铆tulo y el subt铆tulo
70
  st.markdown("<h1 style='text-align: center;'>Generador de Bullets</h1>", unsafe_allow_html=True)
71
  st.markdown("<h4 style='text-align: center;'>Crea bullets efectivos que conecten emocionalmente con tu audiencia.</h4>", unsafe_allow_html=True)
@@ -102,24 +120,21 @@ with col1:
102
  product = st.text_input("驴Qu茅 producto tienes en mente?")
103
 
104
  # Campos de personalizaci贸n sin acorde贸n
105
- num_bullets = st.slider("N煤mero de Bullets", min_value=1, max_value=10, value=5)
106
  creativity = st.selectbox("Creatividad", ["Alta", "Media", "Baja"])
107
 
108
- # Campo para la llamada a la acci贸n
109
- action_call = st.text_input("驴Qu茅 CTA quieres?")
110
-
111
  # Bot贸n de enviar
112
  submit = st.button("Generar Bullets")
113
 
114
  # Mostrar los bullets generados
115
  if submit:
116
- if target_audience:
117
  try:
118
  # Obtener la respuesta del modelo
119
- generated_bullets = get_gemini_response_bullets(target_audience, num_bullets, creativity, action_call)
120
  col2.markdown(f"""
121
  <div style="border: 1px solid #000000; padding: 5px; border-radius: 8px; background-color: #ffffff;">
122
- <h4>Mira la magia:</h4>
123
  <p>{generated_bullets}</p>
124
  </div>
125
  """, unsafe_allow_html=True)
 
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
 
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}
 
64
  * The Truth: 'The truth that you've never been told in school, or at home, about how to make a living from music.'
65
  * Asking a Question: 'Did you know that...'
66
  * When: 'When is it a good idea to tell a girl you like her? If you don't say it at that moment, say goodbye to getting to know her intimately.'
67
+ Using {mention_instruction} when you want to mention {product}.
 
 
68
  """
69
 
70
  response = model.generate_content([full_prompt])
 
72
  if response and response.parts:
73
  return response.parts[0].text
74
  else:
75
+ raise ValueError("Lo sentimos, intenta con una combinaci贸n diferente de entradas.")
76
 
77
  # Inicializar la aplicaci贸n Streamlit
78
  st.set_page_config(page_title="Generador de Bullets", layout="wide")
79
 
80
+ # Inicializar el estado de la expansi贸n del acorde贸n
81
+ if "accordion_expanded" not in st.session_state:
82
+ st.session_state["accordion_expanded"] = False
83
+
84
+ def toggle_accordion():
85
+ st.session_state["accordion_expanded"] = not st.session_state["accordion_expanded"]
86
+
87
  # Centrar el t铆tulo y el subt铆tulo
88
  st.markdown("<h1 style='text-align: center;'>Generador de Bullets</h1>", unsafe_allow_html=True)
89
  st.markdown("<h4 style='text-align: center;'>Crea bullets efectivos que conecten emocionalmente con tu audiencia.</h4>", unsafe_allow_html=True)
 
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")
128
 
129
  # Mostrar los bullets generados
130
  if submit:
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>Aqu铆 est谩n tus bullets:</h4>
138
  <p>{generated_bullets}</p>
139
  </div>
140
  """, unsafe_allow_html=True)