Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -10,26 +10,20 @@ 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
|
14 |
-
def
|
15 |
-
|
16 |
probabilities = [0.34, 0.33, 0.33]
|
17 |
-
return random.choices(
|
18 |
-
|
19 |
-
# Crear la instrucci贸n
|
20 |
-
def
|
21 |
-
if
|
22 |
-
return
|
23 |
-
|
24 |
-
""
|
25 |
-
elif
|
26 |
-
return
|
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,9 +33,9 @@ Generate unusual, creative, and fascinating bullets that capture readers' attent
|
|
39 |
"""
|
40 |
|
41 |
# Funci贸n para obtener una cantidad de bullets
|
42 |
-
def get_gemini_response_bullets(target_audience,
|
43 |
-
|
44 |
-
|
45 |
model_choice = "gemini-1.5-flash" # Modelo por defecto
|
46 |
|
47 |
model = genai.GenerativeModel(model_choice)
|
@@ -72,18 +66,11 @@ def get_gemini_response_bullets(target_audience, product, num_bullets, creativit
|
|
72 |
if response and response.parts:
|
73 |
return response.parts[0].text
|
74 |
else:
|
75 |
-
raise ValueError("Lo
|
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,7 +107,7 @@ with col1:
|
|
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=
|
124 |
creativity = st.selectbox("Creatividad", ["Alta", "Media", "Baja"])
|
125 |
|
126 |
# Bot贸n de enviar
|
@@ -128,13 +115,13 @@ with col1:
|
|
128 |
|
129 |
# Mostrar los bullets generados
|
130 |
if submit:
|
131 |
-
if target_audience
|
132 |
try:
|
133 |
# Obtener la respuesta del modelo
|
134 |
-
generated_bullets = get_gemini_response_bullets(target_audience,
|
135 |
col2.markdown(f"""
|
136 |
<div style="border: 1px solid #000000; padding: 5px; border-radius: 8px; background-color: #ffffff;">
|
137 |
-
<h4>
|
138 |
<p>{generated_bullets}</p>
|
139 |
</div>
|
140 |
""", 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 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 "Incorporate a clear and direct call to action that motivates the reader to act immediately. The call should be compelling and highlight the urgency of taking action."
|
23 |
+
elif action_call == "Sutil":
|
24 |
+
return "Suggest a call to action subtly, hinting at the benefits of acting without being too obvious. The reader should feel like they are making the decision on their own."
|
25 |
+
elif action_call == "Indirecto":
|
26 |
+
return "Present a call to action indirectly, creating a scenario where the reader can see the action as a natural solution to their problems without naming it explicitly."
|
|
|
|
|
|
|
|
|
|
|
|
|
27 |
return ""
|
28 |
|
29 |
# System Prompt - Instrucci贸n en ingl茅s para el modelo
|
|
|
33 |
"""
|
34 |
|
35 |
# Funci贸n para obtener una cantidad de bullets
|
36 |
+
def get_gemini_response_bullets(target_audience, num_bullets, creativity):
|
37 |
+
action_call = get_random_call_to_action() # Obtener la llamada a la acci贸n aleatoria
|
38 |
+
call_to_action_instruction = get_call_to_action_instruction(action_call) # Definir la instrucci贸n aqu铆
|
39 |
model_choice = "gemini-1.5-flash" # Modelo por defecto
|
40 |
|
41 |
model = genai.GenerativeModel(model_choice)
|
|
|
66 |
if response and response.parts:
|
67 |
return response.parts[0].text
|
68 |
else:
|
69 |
+
raise ValueError("Lo siento, intenta con una combinaci贸n diferente de valores.")
|
70 |
|
71 |
# Inicializar la aplicaci贸n Streamlit
|
72 |
st.set_page_config(page_title="Generador de Bullets", layout="wide")
|
73 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
74 |
# Centrar el t铆tulo y el subt铆tulo
|
75 |
st.markdown("<h1 style='text-align: center;'>Generador de Bullets</h1>", unsafe_allow_html=True)
|
76 |
st.markdown("<h4 style='text-align: center;'>Crea bullets efectivos que conecten emocionalmente con tu audiencia.</h4>", unsafe_allow_html=True)
|
|
|
107 |
product = st.text_input("驴Qu茅 producto tienes en mente?")
|
108 |
|
109 |
# Campos de personalizaci贸n sin acorde贸n
|
110 |
+
num_bullets = st.slider("N煤mero de Bullets", min_value=1, max_value=10, value=5)
|
111 |
creativity = st.selectbox("Creatividad", ["Alta", "Media", "Baja"])
|
112 |
|
113 |
# Bot贸n de enviar
|
|
|
115 |
|
116 |
# Mostrar los bullets generados
|
117 |
if submit:
|
118 |
+
if target_audience:
|
119 |
try:
|
120 |
# Obtener la respuesta del modelo
|
121 |
+
generated_bullets = get_gemini_response_bullets(target_audience, num_bullets, creativity) # Sin menci贸n del producto
|
122 |
col2.markdown(f"""
|
123 |
<div style="border: 1px solid #000000; padding: 5px; border-radius: 8px; background-color: #ffffff;">
|
124 |
+
<h4>Mira la magia:</h4>
|
125 |
<p>{generated_bullets}</p>
|
126 |
</div>
|
127 |
""", unsafe_allow_html=True)
|