Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -8,98 +8,78 @@ load_dotenv()
|
|
8 |
genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
|
9 |
|
10 |
# Funci贸n para obtener respuesta del modelo Gemini
|
11 |
-
def get_gemini_response(target_audience, product,
|
12 |
-
model = genai.GenerativeModel("gemini-1.5-flash")
|
13 |
|
14 |
-
# Crear
|
15 |
-
mention_instruction = ""
|
16 |
-
if product_mention == "Directa":
|
17 |
-
mention_instruction = f"Mention the product '{product}' directly in the text."
|
18 |
-
elif product_mention == "Indirecta":
|
19 |
-
mention_instruction = f"Ensure that subtle and realistic references to the product '{product}' are included without explicitly mentioning it."
|
20 |
-
elif product_mention == "Metaf贸rica":
|
21 |
-
mention_instruction = f"Refer to the product '{product}' through a metaphor without explicitly mentioning it."
|
22 |
-
|
23 |
-
# Instrucci贸n espec铆fica para el tipo de texto (siempre ser谩 "Historia")
|
24 |
-
format_instruction = "Ensure that the narrative is engaging and includes character development, a clear plot, and a resolution."
|
25 |
-
|
26 |
-
# Crear el prompt completo basado en los campos del frontend
|
27 |
full_prompt = f"""
|
28 |
-
You are a
|
29 |
-
|
30 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
31 |
response = model.generate_content([full_prompt])
|
32 |
|
33 |
-
# Comprobar si la respuesta es v谩lida y devolver el texto
|
34 |
if response and response.parts:
|
35 |
-
# Formatear la respuesta en p谩rrafos
|
36 |
text = response.parts[0].text
|
37 |
-
|
38 |
-
formatted_text = "\n\n".join(paragraphs) # Unir los p谩rrafos con dos saltos de l铆nea
|
39 |
-
return formatted_text
|
40 |
else:
|
41 |
raise ValueError("Lo sentimos, intenta con una combinaci贸n diferente de entradas.")
|
42 |
|
43 |
# Inicializar la aplicaci贸n Streamlit
|
44 |
-
st.set_page_config(page_title="
|
45 |
|
46 |
-
|
47 |
-
st.markdown("<
|
48 |
-
st.markdown("<h3 style='text-align: center;'>Teje historias inolvidables en segundos, guiado por la magia de la inteligencia artificial que da vida a tus ideas en relatos cautivadores.</h3>", unsafe_allow_html=True)
|
49 |
|
50 |
-
#
|
51 |
st.markdown("""
|
52 |
<style>
|
53 |
div.stButton > button {
|
54 |
-
background-color: #FFCC00;
|
55 |
-
color: black;
|
56 |
width: 90%;
|
57 |
height: 60px;
|
58 |
font-weight: bold;
|
59 |
-
font-size: 22px;
|
60 |
-
text-transform: uppercase;
|
61 |
-
border: 1px solid #000000;
|
62 |
border-radius: 8px;
|
63 |
display: block;
|
64 |
-
margin: 0 auto;
|
65 |
}
|
66 |
div.stButton > button:hover {
|
67 |
-
background-color: #FFD700;
|
68 |
-
color: black;
|
69 |
}
|
70 |
</style>
|
71 |
""", unsafe_allow_html=True)
|
72 |
|
73 |
-
#
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
# Entradas del usuario
|
78 |
-
target_audience = st.text_input("P煤blico objetivo:", placeholder="Especifica tu p煤blico aqu铆...")
|
79 |
-
product = st.text_input("Producto:", placeholder="Especifica el producto aqu铆...")
|
80 |
-
|
81 |
-
# Agrupar todas las opciones en una acorde贸n
|
82 |
-
with st.expander("Personaliza tu texto"):
|
83 |
-
# Variable para c贸mo se debe mencionar el producto
|
84 |
-
product_mention = st.selectbox("Menci贸n del producto:", ["Directa", "Indirecta", "Metaf贸rica"])
|
85 |
-
|
86 |
-
# Eliminar la opci贸n de tipo de texto y longitud del texto
|
87 |
-
mood = st.selectbox("Tono del Texto:", ["Emocional", "Triste", "Feliz", "Horror", "Comedia", "Rom谩ntico"])
|
88 |
|
89 |
-
|
90 |
-
|
|
|
|
|
91 |
|
92 |
-
|
93 |
-
|
94 |
|
95 |
-
#
|
96 |
if submit:
|
97 |
-
if target_audience and product
|
98 |
try:
|
99 |
-
response = get_gemini_response(target_audience, product,
|
100 |
-
|
101 |
-
|
102 |
except ValueError as e:
|
103 |
-
|
104 |
else:
|
105 |
-
|
|
|
8 |
genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
|
9 |
|
10 |
# Funci贸n para obtener respuesta del modelo Gemini
|
11 |
+
def get_gemini_response(target_audience, product, action, mood, length):
|
12 |
+
model = genai.GenerativeModel("gemini-1.5-flash")
|
13 |
|
14 |
+
# Crear el prompt para el modelo
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
full_prompt = f"""
|
16 |
+
You are a skilled copywriter and storyteller. Create a persuasive story in Spanish following the P.A.S.A. formula (Problema, Agitaci贸n, Soluci贸n, Acci贸n).
|
17 |
+
The story should have {length} words, with a {mood} tone. Here are the details:
|
18 |
+
1. Problema: Describe a specific problem that keeps the {target_audience} awake at night.
|
19 |
+
2. Agitaci贸n: Amplify the emotional and practical consequences of this problem.
|
20 |
+
3. Soluci贸n: Highlight how the product '{product}' solves this problem and improves their life.
|
21 |
+
4. Acci贸n: End with the call-to-action '{action}' to motivate the reader to take immediate steps.
|
22 |
+
|
23 |
+
Write a cohesive, engaging, and emotionally resonant narrative tailored to connect with the {target_audience}.
|
24 |
+
"""
|
25 |
response = model.generate_content([full_prompt])
|
26 |
|
|
|
27 |
if response and response.parts:
|
|
|
28 |
text = response.parts[0].text
|
29 |
+
return text.strip()
|
|
|
|
|
30 |
else:
|
31 |
raise ValueError("Lo sentimos, intenta con una combinaci贸n diferente de entradas.")
|
32 |
|
33 |
# Inicializar la aplicaci贸n Streamlit
|
34 |
+
st.set_page_config(page_title="Generador P.A.S.A.", page_icon=":pencil:", layout="wide")
|
35 |
|
36 |
+
st.markdown("<h1 style='text-align: center;'>Generador de Historias P.A.S.A.</h1>", unsafe_allow_html=True)
|
37 |
+
st.markdown("<h3 style='text-align: center;'>Crea historias persuasivas con inteligencia artificial, dise帽adas para conectar emocionalmente con tu audiencia.</h3>", unsafe_allow_html=True)
|
|
|
38 |
|
39 |
+
# CSS personalizado para el bot贸n
|
40 |
st.markdown("""
|
41 |
<style>
|
42 |
div.stButton > button {
|
43 |
+
background-color: #FFCC00;
|
44 |
+
color: black;
|
45 |
width: 90%;
|
46 |
height: 60px;
|
47 |
font-weight: bold;
|
48 |
+
font-size: 22px;
|
49 |
+
text-transform: uppercase;
|
50 |
+
border: 1px solid #000000;
|
51 |
border-radius: 8px;
|
52 |
display: block;
|
53 |
+
margin: 0 auto;
|
54 |
}
|
55 |
div.stButton > button:hover {
|
56 |
+
background-color: #FFD700;
|
57 |
+
color: black;
|
58 |
}
|
59 |
</style>
|
60 |
""", unsafe_allow_html=True)
|
61 |
|
62 |
+
# Entradas del usuario
|
63 |
+
target_audience = st.text_input("P煤blico objetivo", placeholder="驴A qui茅n est谩 dirigido tu mensaje?")
|
64 |
+
product = st.text_input("Producto/Servicio", placeholder="驴Qu茅 est谩s ofreciendo?")
|
65 |
+
action = st.text_area("Llamado a la acci贸n", "驴Qu茅 acci贸n espec铆fica debe tomar tu audiencia?")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
66 |
|
67 |
+
# Personalizaci贸n adicional
|
68 |
+
with st.expander("Personaliza tu historia"):
|
69 |
+
mood = st.selectbox("Tono de la historia:", ["Emocional", "Triste", "Feliz", "Horror", "Comedia", "Rom谩ntico"])
|
70 |
+
length = st.slider("Longitud de la historia (palabras):", min_value=50, max_value=500, value=200, step=10)
|
71 |
|
72 |
+
# Bot贸n para generar contenido
|
73 |
+
submit = st.button("Generar mi historia")
|
74 |
|
75 |
+
# Mostrar el contenido generado
|
76 |
if submit:
|
77 |
+
if target_audience and product and action:
|
78 |
try:
|
79 |
+
response = get_gemini_response(target_audience, product, action, mood, length)
|
80 |
+
st.subheader("Historia generada:")
|
81 |
+
st.write(response)
|
82 |
except ValueError as e:
|
83 |
+
st.error(f"Error: {str(e)}")
|
84 |
else:
|
85 |
+
st.error("Por favor, completa todos los campos requeridos (P煤blico objetivo, Producto y Acci贸n).")
|