JeCabrera commited on
Commit
363592e
verified
1 Parent(s): 3b8e656

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -28
app.py CHANGED
@@ -14,38 +14,33 @@ def get_gemini_response(target_audience, product, product_mention, mood, model_c
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"Menciona directamente el producto '{product}' en el texto."
18
  elif product_mention == "Indirecta":
19
- mention_instruction = f"Aseg煤rate de incluir referencias sutiles y realistas al producto '{product}' sin mencionarlo expl铆citamente."
20
  elif product_mention == "Metaf贸rica":
21
- mention_instruction = f"Refi茅rete al producto '{product}' a trav茅s de una met谩fora sin mencionarlo expl铆citamente."
22
 
23
- # Instrucci贸n espec铆fica para el tipo de texto
24
- format_instruction = "Aseg煤rate de que la narrativa sea atractiva e incluya desarrollo de personajes, una trama clara y una resoluci贸n."
25
 
26
- # Longitud del texto
27
  length = "Corto"
28
 
29
  # Crear el prompt completo basado en los campos del frontend
30
  full_prompt = f"""
31
- Eres un escritor creativo experto en la persuasi贸n. Escribe una {length} Historia en espa帽ol. El tono de la Historia debe ser {mood} y cuidadosamente elaborado para resonar emocionalmente con un {target_audience}. {mention_instruction} {format_instruction} Utiliza t茅cnicas persuasivas para guiar al lector hacia una comprensi贸n intuitiva de los beneficios del producto, enfoc谩ndote en crear una fuerte conexi贸n emocional con la audiencia.
32
  """
33
 
34
  response = model.generate_content([full_prompt])
35
 
36
  # Comprobar si la respuesta es v谩lida y devolver el texto
37
  if response and response.parts:
38
- generated_text = response.parts[0].text
39
- # Limitar a 250 tokens
40
- tokens = generated_text.split()
41
- if len(tokens) > 250:
42
- generated_text = ' '.join(tokens[:250]) # Truncar el texto a 250 tokens
43
- return generated_text
44
  else:
45
  raise ValueError("Lo sentimos, intenta con una combinaci贸n diferente de entradas.")
46
 
47
  # Inicializar la aplicaci贸n Streamlit
48
- st.set_page_config(page_title="Story Genius Maker", page_icon=":pencil:", layout="wide")
49
 
50
  # T铆tulo y subt铆tulo
51
  st.markdown("<h1 style='text-align: center;'>Story Genius Maker</h1>", unsafe_allow_html=True)
@@ -71,21 +66,11 @@ st.markdown("""
71
  background-color: #FFD700; /* Color al pasar el mouse */
72
  color: black; /* Texto sigue en negro */
73
  }
74
- .response-container {
75
- max-width: 800px; /* Limitar el ancho del contenedor de respuesta */
76
- margin: 0 auto; /* Centrar el contenedor */
77
- padding: 20px; /* Espaciado interno */
78
- border: 1px solid #ccc; /* Borde suave */
79
- border-radius: 10px; /* Bordes redondeados */
80
- background-color: #f9f9f9; /* Color de fondo claro */
81
- font-size: 16px; /* Tama帽o de texto */
82
- overflow-wrap: break-word; /* Permitir que el texto se ajuste */
83
- }
84
  </style>
85
  """, unsafe_allow_html=True)
86
 
87
  # Crear dos columnas para el dise帽o (40% y 60%)
88
- col1, col2 = st.columns([2, 3])
89
 
90
  with col1:
91
  # Entradas del usuario
@@ -97,7 +82,7 @@ with col1:
97
  # Variable para c贸mo se debe mencionar el producto
98
  product_mention = st.selectbox("Menci贸n del producto:", ["Directa", "Indirecta", "Metaf贸rica"])
99
 
100
- # Tono del texto
101
  mood = st.selectbox("Tono del Texto:", ["Emocional", "Triste", "Feliz", "Horror", "Comedia", "Rom谩ntico"])
102
 
103
  # Opci贸n para seleccionar el modelo
@@ -108,11 +93,11 @@ with col1:
108
 
109
  # Manejo del clic en el bot贸n
110
  if submit:
111
- if target_audience and product:
112
  try:
113
  response = get_gemini_response(target_audience, product, product_mention, mood, model_choice)
114
  col2.subheader("Contenido generado:")
115
- col2.markdown(f"<div class='response-container'>{response}</div>", unsafe_allow_html=True) # Usar el contenedor con estilo
116
  except ValueError as e:
117
  col2.error(f"Error: {str(e)}")
118
  else:
 
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
+ # 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
+ # Longitud del texto (siempre ser谩 "Corto")
27
  length = "Corto"
28
 
29
  # Crear el prompt completo basado en los campos del frontend
30
  full_prompt = f"""
31
+ You are a creative writer skilled in the art of persuasion. Write a {length} Historia in Spanish. The tone of the Historia should be {mood} and carefully crafted to emotionally resonate with a {target_audience}. {mention_instruction} {format_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.
32
  """
33
 
34
  response = model.generate_content([full_prompt])
35
 
36
  # Comprobar si la respuesta es v谩lida y devolver el texto
37
  if response and response.parts:
38
+ return response.parts[0].text
 
 
 
 
 
39
  else:
40
  raise ValueError("Lo sentimos, intenta con una combinaci贸n diferente de entradas.")
41
 
42
  # Inicializar la aplicaci贸n Streamlit
43
+ st.set_page_config(page_title="Story Genius Maker", page_icon=":pencil:", layout="wide") # Configurar el dise帽o en ancho
44
 
45
  # T铆tulo y subt铆tulo
46
  st.markdown("<h1 style='text-align: center;'>Story Genius Maker</h1>", unsafe_allow_html=True)
 
66
  background-color: #FFD700; /* Color al pasar el mouse */
67
  color: black; /* Texto sigue en negro */
68
  }
 
 
 
 
 
 
 
 
 
 
69
  </style>
70
  """, unsafe_allow_html=True)
71
 
72
  # Crear dos columnas para el dise帽o (40% y 60%)
73
+ col1, col2 = st.columns([2, 3]) # 2 + 3 = 5 partes en total
74
 
75
  with col1:
76
  # Entradas del usuario
 
82
  # Variable para c贸mo se debe mencionar el producto
83
  product_mention = st.selectbox("Menci贸n del producto:", ["Directa", "Indirecta", "Metaf贸rica"])
84
 
85
+ # Eliminar la opci贸n de tipo de texto y longitud del texto
86
  mood = st.selectbox("Tono del Texto:", ["Emocional", "Triste", "Feliz", "Horror", "Comedia", "Rom谩ntico"])
87
 
88
  # Opci贸n para seleccionar el modelo
 
93
 
94
  # Manejo del clic en el bot贸n
95
  if submit:
96
+ if target_audience and product: # Verificar que se haya proporcionado el p煤blico objetivo y el producto
97
  try:
98
  response = get_gemini_response(target_audience, product, product_mention, mood, model_choice)
99
  col2.subheader("Contenido generado:")
100
+ col2.write(response)
101
  except ValueError as e:
102
  col2.error(f"Error: {str(e)}")
103
  else: