Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -8,20 +8,21 @@ 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, text_type, length,
|
12 |
model = genai.GenerativeModel(model_choice)
|
13 |
|
14 |
-
# Crear
|
15 |
mention_instruction = ""
|
16 |
-
if product_mention == "
|
17 |
-
mention_instruction = f"
|
18 |
-
elif product_mention == "
|
19 |
mention_instruction = f"Ensure that subtle and realistic references to the product '{product}' are included without explicitly mentioning it."
|
20 |
-
elif product_mention == "
|
21 |
-
mention_instruction = f"Refer to the product '{product}' through a metaphor
|
22 |
|
|
|
23 |
full_prompt = f"""
|
24 |
-
|
25 |
"""
|
26 |
|
27 |
response = model.generate_content([full_prompt])
|
@@ -69,16 +70,18 @@ with col1:
|
|
69 |
# Entradas del usuario
|
70 |
target_audience = st.text_input("P煤blico objetivo:", placeholder="Especifica tu p煤blico aqu铆...")
|
71 |
product = st.text_input("Producto:", placeholder="Especifica el producto aqu铆...")
|
72 |
-
text_type = st.selectbox("Tipo de texto:", ["Historia", "Shayari", "Sher", "Poema", "Cita"])
|
73 |
-
length = st.selectbox("Longitud del texto:", ["Corto", "Largo"])
|
74 |
-
|
75 |
-
# Nueva opci贸n para c贸mo se debe mencionar el producto
|
76 |
-
product_mention = st.selectbox("Menci贸n del producto:", ["Direct", "Subtle", "Metaphor"])
|
77 |
-
|
78 |
-
mood = st.selectbox("Tono del Texto:", ["Emocional", "Triste", "Feliz", "Horror", "Comedia", "Rom谩ntico"])
|
79 |
|
80 |
-
#
|
81 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
82 |
|
83 |
# Bot贸n para generar contenido
|
84 |
submit = st.button("Escribir mi historia")
|
@@ -87,7 +90,7 @@ with col1:
|
|
87 |
if submit:
|
88 |
if target_audience and product: # Verificar que se haya proporcionado el p煤blico objetivo y el producto
|
89 |
try:
|
90 |
-
response = get_gemini_response(target_audience, product, text_type, length,
|
91 |
col2.subheader("Contenido generado:")
|
92 |
col2.write(response)
|
93 |
except ValueError as e:
|
|
|
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, product_mention, text_type, length, mood, model_choice):
|
12 |
model = genai.GenerativeModel(model_choice)
|
13 |
|
14 |
+
# Crear la instrucci贸n de menci贸n basada en la opci贸n seleccionada
|
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 |
+
# Crear el prompt completo basado en los campos del frontend
|
24 |
full_prompt = f"""
|
25 |
+
You are a creative writer skilled in the art of persuasion. Write a {length} {text_type} in Spanish. The tone of the {text_type} should be {mood} and carefully crafted to emotionally resonate with a {target_audience}. {mention_instruction} Use persuasive techniques to guide the reader towards an intuitive understanding of the product's benefits, focusing on creating a strong emotional connection with the audience.
|
26 |
"""
|
27 |
|
28 |
response = model.generate_content([full_prompt])
|
|
|
70 |
# Entradas del usuario
|
71 |
target_audience = st.text_input("P煤blico objetivo:", placeholder="Especifica tu p煤blico aqu铆...")
|
72 |
product = st.text_input("Producto:", placeholder="Especifica el producto aqu铆...")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
73 |
|
74 |
+
# Agrupar todas las opciones en una acorde贸n
|
75 |
+
with st.expander("Personaliza tu texto"):
|
76 |
+
# Variable para c贸mo se debe mencionar el producto
|
77 |
+
product_mention = st.selectbox("Menci贸n del producto:", ["Directa", "Indirecta", "Metaf贸rica"])
|
78 |
+
|
79 |
+
text_type = st.selectbox("Tipo de texto:", ["Historia", "Shayari", "Sher", "Poema", "Cita"])
|
80 |
+
length = st.selectbox("Longitud del texto:", ["Corto", "Largo"])
|
81 |
+
mood = st.selectbox("Tono del Texto:", ["Emocional", "Triste", "Feliz", "Horror", "Comedia", "Rom谩ntico"])
|
82 |
+
|
83 |
+
# Opci贸n para seleccionar el modelo
|
84 |
+
model_choice = st.selectbox("Selecciona el modelo:", ["gemini-1.5-flash", "gemini-1.5-pro"], index=0)
|
85 |
|
86 |
# Bot贸n para generar contenido
|
87 |
submit = st.button("Escribir mi historia")
|
|
|
90 |
if submit:
|
91 |
if target_audience and product: # Verificar que se haya proporcionado el p煤blico objetivo y el producto
|
92 |
try:
|
93 |
+
response = get_gemini_response(target_audience, product, product_mention, text_type, length, mood, model_choice)
|
94 |
col2.subheader("Contenido generado:")
|
95 |
col2.write(response)
|
96 |
except ValueError as e:
|