JeCabrera commited on
Commit
eb6729d
verified
1 Parent(s): d8717d2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -51
app.py CHANGED
@@ -4,14 +4,16 @@ import os
4
  import google.generativeai as genai
5
  import random
6
 
 
7
  load_dotenv()
8
 
 
9
  genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
10
 
11
  # Funci贸n para obtener una menci贸n del producto de manera probabil铆stica
12
  def get_random_product_mention():
13
  mentions = ["Indirecta", "Metaf贸rica"]
14
- probabilities = [0.50, 0.50]
15
  return random.choices(mentions, probabilities)[0]
16
 
17
  # Crear la instrucci贸n de menci贸n basada en la opci贸n seleccionada
@@ -21,40 +23,28 @@ def get_mention_instruction(product_mention, product):
21
  elif product_mention == "Metaf贸rica":
22
  return f"Introduce el producto '{product}' usando una met谩fora, conect谩ndolo simb贸licamente a la soluci贸n que necesita el lector."
23
  return ""
24
-
25
  # Funci贸n para generar los beneficios (bullets) basados en el enfoque
26
  def generate_benefits(focus_points, product, target_audience, creativity, num_bullets):
27
- model = genai.GenerativeModel("gemini-1.5-flash")
 
28
 
29
  # Instrucci贸n del sistema para el modelo
30
  system_instruction = (
31
- "You are a world-class copywriter, with expertise in crafting hooks, headlines, and subject lines that immediately "
32
- "capture the reader's attention, prompting them to open the email or continue reading. Your skill lies in deeply understanding "
33
- "the emotions, desires, and challenges of a specific audience. You are also an expert in creating benefits that connect symptoms "
34
- "with problems, allowing you to design personalized strategies that resonate and motivate action. You know how to use proven "
35
- "structures to attract your target audience, generating interest and creating a powerful connection. Your task is to generate "
36
- "unusual, creative, and fascinating subject lines or headlines that spark curiosity and encourage the reader to engage further. "
37
- "Respond in Spanish and use a numbered list format. Important: Only answer with subject lines, never include explanations or categories."
38
  )
39
 
40
- # Modificaci贸n en el prompt para integrar menciones del producto
41
- prompt_base = f"""
42
  Eres un experto en copywriting y tu objetivo es crear {{num_bullets}} bullets persuasivos que conecten emocionalmente con la audiencia {{target_audience}}.
43
  Cada bullet debe abordar sus problemas, deseos o situaciones, mostrando c贸mo se pueden mejorar o solucionar gracias a una soluci贸n espec铆fica.
44
- Piensa en c贸mo puedes captar la atenci贸n de la audiencia con frases impactantes, como si estuvieras hablando directamente con ellos.
45
- La idea es resaltar el valor que aporta la soluci贸n, sin hacer que el producto suene como una venta forzada.
46
- Adem谩s, aseg煤rate de mencionar el producto utilizando el siguiente enfoque: {{mention_instruction}}.
47
- Los bullets deben ser claros, directos y generar curiosidad, invitando a la acci贸n de manera natural.
48
- Evita la jerga t茅cnica y mant茅n la simplicidad, enfoc谩ndote en c贸mo el producto se integra de manera natural en la vida de la audiencia para mejorarla.
49
  Usa enfoques creativos para conectar los beneficios del producto con lo que realmente le importa a la audiencia.
50
- Crea {{num_bullets}} bullets persuasivos que muestren c贸mo el producto puede resolver o transformar una situaci贸n para la audiencia.
51
  """
52
 
53
- # Generaci贸n del prompt espec铆fico con menci贸n
54
- def generate_benefits(focus_points, product, target_audience, creativity, num_bullets):
55
- product_mention = get_random_product_mention()
56
- mention_instruction = get_mention_instruction(product_mention, product)
57
-
58
  benefits = []
59
  for point in focus_points[:num_bullets]:
60
  specific_prompt = prompt_base.format(
@@ -63,20 +53,18 @@ def generate_benefits(focus_points, product, target_audience, creativity, num_bu
63
  mention_instruction=mention_instruction
64
  ) + f"\n\nEnfoque: {point}\n"
65
 
66
- response = genai.GenerativeModel(
67
- model_name="gemini-1.5-flash",
68
- generation_config={
69
- "temperature": creativity,
70
- "top_p": 0.65,
71
- "top_k": 280,
72
- "max_output_tokens": 2048,
73
- "response_mime_type": "text/plain",
74
- },
75
- system_instruction=system_instruction
76
- ).generate_content([specific_prompt])
77
-
78
- if response and response.parts:
79
- bullet = response.parts[0].text.strip()
80
  benefits.append(bullet)
81
  else:
82
  benefits.append("No se pudo generar un beneficio para este enfoque.")
@@ -84,7 +72,7 @@ def generate_benefits(focus_points, product, target_audience, creativity, num_bu
84
  return benefits
85
 
86
  # Configuraci贸n de Streamlit
87
- st.set_page_config(page_title="Quick Prompt", layout="wide")
88
 
89
  # Leer el contenido del archivo manual.md
90
  with open("manual.md", "r", encoding="utf-8") as file:
@@ -120,16 +108,17 @@ with col1:
120
  submit = st.button("Generar Beneficios")
121
 
122
  # Mostrar los beneficios generados
123
- if submit:
124
- if focus_points and product and target_audience:
125
- benefits = generate_benefits(focus_points, product, target_audience, creativity, num_bullets)
126
- formatted_benefits = '<br style="line-height: 2;">'.join(benefits)
127
-
128
- col2.markdown(f"""
129
- <div style="border: 1px solid #000000; padding: 5px; border-radius: 8px; background-color: #ffffff;">
130
- <h4>Mira los beneficios generados:</h4>
131
- <p style="line-height: 2;">{formatted_benefits}</p>
132
- </div>
133
- """, unsafe_allow_html=True)
134
- else:
135
- col2.error("Por favor, proporciona al menos un enfoque, un producto y un p煤blico objetivo para generar beneficios.")
 
 
4
  import google.generativeai as genai
5
  import random
6
 
7
+ # Cargar las variables de entorno
8
  load_dotenv()
9
 
10
+ # Configurar la API de GenAI
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 = ["Indirecta", "Metaf贸rica"]
16
+ probabilities = [0.50, 0.50]
17
  return random.choices(mentions, probabilities)[0]
18
 
19
  # Crear la instrucci贸n de menci贸n basada en la opci贸n seleccionada
 
23
  elif product_mention == "Metaf贸rica":
24
  return f"Introduce el producto '{product}' usando una met谩fora, conect谩ndolo simb贸licamente a la soluci贸n que necesita el lector."
25
  return ""
26
+
27
  # Funci贸n para generar los beneficios (bullets) basados en el enfoque
28
  def generate_benefits(focus_points, product, target_audience, creativity, num_bullets):
29
+ product_mention = get_random_product_mention()
30
+ mention_instruction = get_mention_instruction(product_mention, product)
31
 
32
  # Instrucci贸n del sistema para el modelo
33
  system_instruction = (
34
+ "You are a world-class copywriter with expertise in crafting emotional and persuasive benefits that connect with the target audience. "
35
+ "Generate highly creative and engaging benefits that resonate with the audience's desires and challenges."
 
 
 
 
 
36
  )
37
 
38
+ # Base del prompt
39
+ prompt_base = f"""
40
  Eres un experto en copywriting y tu objetivo es crear {{num_bullets}} bullets persuasivos que conecten emocionalmente con la audiencia {{target_audience}}.
41
  Cada bullet debe abordar sus problemas, deseos o situaciones, mostrando c贸mo se pueden mejorar o solucionar gracias a una soluci贸n espec铆fica.
42
+ La idea es resaltar el valor que aporta la soluci贸n, sin que suene como una venta forzada.
43
+ Adem谩s, menciona el producto utilizando el siguiente enfoque: {{mention_instruction}}.
 
 
 
44
  Usa enfoques creativos para conectar los beneficios del producto con lo que realmente le importa a la audiencia.
45
+ Crea {{num_bullets}} bullets persuasivos que muestren c贸mo el producto puede transformar la situaci贸n de la audiencia.
46
  """
47
 
 
 
 
 
 
48
  benefits = []
49
  for point in focus_points[:num_bullets]:
50
  specific_prompt = prompt_base.format(
 
53
  mention_instruction=mention_instruction
54
  ) + f"\n\nEnfoque: {point}\n"
55
 
56
+ # Configuraci贸n del modelo y generaci贸n de contenido
57
+ response = genai.generate_text(
58
+ model="gemini-1.5-flash",
59
+ prompt=specific_prompt,
60
+ temperature=creativity,
61
+ top_p=0.65,
62
+ top_k=280,
63
+ max_output_tokens=2048,
64
+ )
65
+
66
+ if response and response.generations:
67
+ bullet = response.generations[0].text.strip()
 
 
68
  benefits.append(bullet)
69
  else:
70
  benefits.append("No se pudo generar un beneficio para este enfoque.")
 
72
  return benefits
73
 
74
  # Configuraci贸n de Streamlit
75
+ st.set_page_config(page_title="Impact Bullet Generator", layout="wide")
76
 
77
  # Leer el contenido del archivo manual.md
78
  with open("manual.md", "r", encoding="utf-8") as file:
 
108
  submit = st.button("Generar Beneficios")
109
 
110
  # Mostrar los beneficios generados
111
+ with col2:
112
+ if submit:
113
+ if focus_points and product and target_audience:
114
+ benefits = generate_benefits(focus_points, product, target_audience, creativity, num_bullets)
115
+ formatted_benefits = '<br style="line-height: 2;">'.join(benefits)
116
+
117
+ st.markdown(f"""
118
+ <div style="border: 1px solid #000000; padding: 5px; border-radius: 8px; background-color: #ffffff;">
119
+ <h4>Mira los beneficios generados:</h4>
120
+ <p style="line-height: 2;">{formatted_benefits}</p>
121
+ </div>
122
+ """, unsafe_allow_html=True)
123
+ else:
124
+ st.error("Por favor, proporciona al menos un enfoque, un producto y un p煤blico objetivo para generar beneficios.")