Update app.py
Browse files
app.py
CHANGED
@@ -168,7 +168,19 @@ Inscr铆bete hoy y recibe un m贸dulo extra sobre c贸mo adaptar tu mensaje sin per
|
|
168 |
}
|
169 |
}
|
170 |
|
171 |
-
def generate_headline_for_story(model, story, formula_type, product, target_audience, mood):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
172 |
"""Funci贸n para generar un titular basado en la historia"""
|
173 |
|
174 |
system_prompt = """Eres un experto copywriter especializado en crear titulares persuasivos.
|
@@ -289,9 +301,12 @@ def generate_headline_for_story(model, story, formula_type, product, target_audi
|
|
289 |
return headline_text
|
290 |
return None
|
291 |
|
292 |
-
def generate_story(formula_type, target_audience, product, action, mood, length, story_topic=None):
|
293 |
"""Funci贸n unificada para generar historias"""
|
294 |
-
model = genai.GenerativeModel(
|
|
|
|
|
|
|
295 |
|
296 |
if formula_type not in story_formulas:
|
297 |
raise ValueError("F贸rmula no v谩lida")
|
@@ -651,6 +666,15 @@ with col1:
|
|
651 |
length = st.slider("Longitud de la historia (palabras):",
|
652 |
min_value=50, max_value=150, value=100, step=10)
|
653 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
654 |
# Campo story_topic fuera del expander pero dependiente de la f贸rmula seleccionada
|
655 |
story_topic = None
|
656 |
if selected_formula == "GHA":
|
@@ -667,17 +691,16 @@ with col2:
|
|
667 |
if submit:
|
668 |
if target_audience and product and action:
|
669 |
try:
|
670 |
-
# Verificar si es GHA y necesita story_topic
|
671 |
if selected_formula == "GHA":
|
672 |
if story_topic:
|
673 |
response = generate_story(selected_formula, target_audience, product,
|
674 |
-
action, mood, length, story_topic)
|
675 |
else:
|
676 |
st.error("Por favor, completa todos los campos requeridos para la f贸rmula G.H.A.")
|
677 |
response = ""
|
678 |
else:
|
679 |
response = generate_story(selected_formula, target_audience, product,
|
680 |
-
action, mood, length)
|
681 |
|
682 |
if response:
|
683 |
st.subheader("Historia generada:")
|
|
|
168 |
}
|
169 |
}
|
170 |
|
171 |
+
def generate_headline_for_story(model, story, formula_type, product, target_audience, mood, temperature):
|
172 |
+
generation_config = {
|
173 |
+
"temperature": temperature,
|
174 |
+
"top_p": 0.65,
|
175 |
+
"top_k": 360,
|
176 |
+
"max_output_tokens": 8196,
|
177 |
+
}
|
178 |
+
|
179 |
+
model = genai.GenerativeModel(
|
180 |
+
model_name="gemini-2.0-flash",
|
181 |
+
generation_config=generation_config
|
182 |
+
)
|
183 |
+
|
184 |
"""Funci贸n para generar un titular basado en la historia"""
|
185 |
|
186 |
system_prompt = """Eres un experto copywriter especializado en crear titulares persuasivos.
|
|
|
301 |
return headline_text
|
302 |
return None
|
303 |
|
304 |
+
def generate_story(formula_type, target_audience, product, action, mood, length, temperature, story_topic=None):
|
305 |
"""Funci贸n unificada para generar historias"""
|
306 |
+
model = genai.GenerativeModel(
|
307 |
+
model_name="gemini-2.0-flash",
|
308 |
+
generation_config=generation_config
|
309 |
+
)
|
310 |
|
311 |
if formula_type not in story_formulas:
|
312 |
raise ValueError("F贸rmula no v谩lida")
|
|
|
666 |
length = st.slider("Longitud de la historia (palabras):",
|
667 |
min_value=50, max_value=150, value=100, step=10)
|
668 |
|
669 |
+
temperature = st.slider(
|
670 |
+
"Nivel de creatividad:",
|
671 |
+
min_value=0.0,
|
672 |
+
max_value=2.0,
|
673 |
+
value=1.0,
|
674 |
+
step=0.1,
|
675 |
+
help="Valores m谩s altos generan historias m谩s creativas pero menos predecibles. Valores m谩s bajos producen historias m谩s consistentes."
|
676 |
+
)
|
677 |
+
|
678 |
# Campo story_topic fuera del expander pero dependiente de la f贸rmula seleccionada
|
679 |
story_topic = None
|
680 |
if selected_formula == "GHA":
|
|
|
691 |
if submit:
|
692 |
if target_audience and product and action:
|
693 |
try:
|
|
|
694 |
if selected_formula == "GHA":
|
695 |
if story_topic:
|
696 |
response = generate_story(selected_formula, target_audience, product,
|
697 |
+
action, mood, length, temperature, story_topic)
|
698 |
else:
|
699 |
st.error("Por favor, completa todos los campos requeridos para la f贸rmula G.H.A.")
|
700 |
response = ""
|
701 |
else:
|
702 |
response = generate_story(selected_formula, target_audience, product,
|
703 |
+
action, mood, length, temperature)
|
704 |
|
705 |
if response:
|
706 |
st.subheader("Historia generada:")
|