Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -4,8 +4,10 @@ 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
|
@@ -14,16 +16,26 @@ def get_random_product_mention():
|
|
14 |
probabilities = [0.34, 0.33, 0.33]
|
15 |
return random.choices(mentions, probabilities)[0]
|
16 |
|
|
|
|
|
|
|
|
|
|
|
17 |
# Funci贸n para obtener una cantidad de bullets
|
18 |
def get_gemini_response_bullets(target_audience, product, num_bullets, creativity):
|
19 |
product_mention = get_random_product_mention()
|
20 |
-
model_choice = "gemini-1.5-flash"
|
21 |
|
22 |
model = genai.GenerativeModel(model_choice)
|
23 |
|
24 |
-
# Crear el prompt para generar bullets
|
25 |
full_prompt = f"""
|
26 |
-
|
|
|
|
|
|
|
|
|
|
|
27 |
"""
|
28 |
|
29 |
response = model.generate_content([full_prompt])
|
@@ -92,12 +104,12 @@ if submit:
|
|
92 |
try:
|
93 |
# Obtener la respuesta del modelo
|
94 |
generated_bullets = get_gemini_response_bullets(target_audience, product, num_bullets, creativity)
|
95 |
-
col2.markdown("""
|
96 |
<div style="border: 1px solid #000000; padding: 5px; border-radius: 8px; background-color: #ffffff;">
|
97 |
<h4>Aqu铆 est谩n tus bullets:</h4>
|
98 |
-
<p>{}</p>
|
99 |
</div>
|
100 |
-
"""
|
101 |
except ValueError as e:
|
102 |
col2.error(f"Error: {str(e)}")
|
103 |
else:
|
|
|
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 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
|
|
|
16 |
probabilities = [0.34, 0.33, 0.33]
|
17 |
return random.choices(mentions, probabilities)[0]
|
18 |
|
19 |
+
# System Prompt - Instrucci贸n en ingl茅s para el modelo
|
20 |
+
system_instruction = """
|
21 |
+
You are a world-class copywriter with expertise in creating benefits that connect symptoms to problems. Your skill lies in deeply understanding 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 that drives desired results in advertising and content campaigns. Respond in Spanish, using numbered lists. Create unusual, creative, and fascinating bullets that capture readers' attention. Do not mention the product directly in the benefits or bullets.
|
22 |
+
"""
|
23 |
+
|
24 |
# Funci贸n para obtener una cantidad de bullets
|
25 |
def get_gemini_response_bullets(target_audience, product, num_bullets, creativity):
|
26 |
product_mention = get_random_product_mention()
|
27 |
+
model_choice = "gemini-1.5-flash" # Modelo por defecto
|
28 |
|
29 |
model = genai.GenerativeModel(model_choice)
|
30 |
|
31 |
+
# Crear el prompt para generar bullets con la instrucci贸n del sistema
|
32 |
full_prompt = f"""
|
33 |
+
{system_instruction}
|
34 |
+
Audience: {target_audience}
|
35 |
+
Product: {product}
|
36 |
+
Number of bullets: {num_bullets}
|
37 |
+
Creativity: {creativity}
|
38 |
+
Use {product_mention} mention.
|
39 |
"""
|
40 |
|
41 |
response = model.generate_content([full_prompt])
|
|
|
104 |
try:
|
105 |
# Obtener la respuesta del modelo
|
106 |
generated_bullets = get_gemini_response_bullets(target_audience, product, num_bullets, creativity)
|
107 |
+
col2.markdown(f"""
|
108 |
<div style="border: 1px solid #000000; padding: 5px; border-radius: 8px; background-color: #ffffff;">
|
109 |
<h4>Aqu铆 est谩n tus bullets:</h4>
|
110 |
+
<p>{generated_bullets}</p>
|
111 |
</div>
|
112 |
+
""", unsafe_allow_html=True)
|
113 |
except ValueError as e:
|
114 |
col2.error(f"Error: {str(e)}")
|
115 |
else:
|