JeCabrera commited on
Commit
5d758ad
verified
1 Parent(s): 609f402

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -64
app.py CHANGED
@@ -2,13 +2,24 @@ from dotenv import load_dotenv
2
  import streamlit as st
3
  import os
4
  import google.generativeai as genai
 
5
 
6
  load_dotenv()
7
 
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
@@ -48,7 +59,7 @@ def get_gemini_response(target_audience, product, product_mention, text_type, le
48
  # Crear el prompt completo basado en los campos del frontend
49
  full_prompt = f"""
50
  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} {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.
51
- Create an opening paragraph for a {text_type.lower()} that makes {target_audience} aware they have a problem by explaining it with real-life situations, using a natural or conversational tone. The goal of this paragraph is to make them want to keep reading and find out what {product} is about. Use persuasion effectively in every word, mastering advanced techniques like using powerful headlines and intriguing openings.
52
 
53
  To write this opening paragraph, use one or more of these Copywriting Techniques, choosing the most appropriate ones:
54
 
@@ -69,67 +80,26 @@ def get_gemini_response(target_audience, product, product_mention, text_type, le
69
  raise ValueError("Lo sentimos, intenta con una combinaci贸n diferente de entradas.")
70
 
71
  # Inicializar la aplicaci贸n Streamlit
72
- st.set_page_config(page_title="Poetic Vision", page_icon=":pencil:", layout="wide") # Configurar el dise帽o en ancho
 
73
 
74
- # Componentes principales de la UI
75
- st.markdown("<h1 style='text-align: center;'>VisionTales</h1>", unsafe_allow_html=True)
76
- st.markdown("<h3 style='text-align: center;'>Convierte tus ideas en historias inolvidables.</h3>", unsafe_allow_html=True)
 
 
 
 
 
77
 
78
- # A帽adir CSS personalizado para el bot贸n
79
- st.markdown("""
80
- <style>
81
- div.stButton > button {
82
- background-color: #FFCC00; /* Color llamativo */
83
- color: black; /* Texto en negro */
84
- width: 90%;
85
- height: 60px;
86
- font-weight: bold;
87
- font-size: 22px; /* Tama帽o m谩s grande */
88
- text-transform: uppercase; /* Texto en may煤sculas */
89
- border: 1px solid #000000; /* Borde negro de 1px */
90
- border-radius: 8px;
91
- display: block;
92
- margin: 0 auto; /* Centramos el bot贸n */
93
- }
94
- div.stButton > button:hover {
95
- background-color: #FFD700; /* Color al pasar el mouse */
96
- color: black; /* Texto sigue en negro */
97
- }
98
- </style>
99
- """, unsafe_allow_html=True)
100
 
101
- # Crear dos columnas para el dise帽o (40% y 60%)
102
- col1, col2 = st.columns([2, 3]) # 2 + 3 = 5 partes en total
103
-
104
- with col1:
105
- # Entradas del usuario
106
- target_audience = st.text_input("P煤blico objetivo:", placeholder="Especifica tu p煤blico aqu铆...")
107
- product = st.text_input("Producto:", placeholder="Especifica el producto aqu铆...")
108
-
109
- # Agrupar todas las opciones en una acorde贸n
110
- with st.expander("Personaliza tu texto"):
111
- # Variable para c贸mo se debe mencionar el producto
112
- product_mention = st.selectbox("Menci贸n del producto:", ["Directa", "Indirecta", "Metaf贸rica"])
113
-
114
- # Opciones actualizadas para el tipo de texto
115
- text_type = st.selectbox("Tipo de texto:", ["Historia", "Carta de venta", "Correo", "Landing page"])
116
- length = st.selectbox("Longitud del texto:", ["Corto", "Largo"])
117
- mood = st.selectbox("Tono del Texto:", ["Emocional", "Triste", "Feliz", "Horror", "Comedia", "Rom谩ntico"])
118
-
119
- # Opci贸n para seleccionar el modelo
120
- model_choice = st.selectbox("Selecciona el modelo:", ["gemini-1.5-flash", "gemini-1.5-pro"], index=0)
121
-
122
- # Bot贸n para generar contenido
123
- submit = st.button("Escribir mi historia")
124
-
125
- # Manejo del clic en el bot贸n
126
- if submit:
127
- if target_audience and product: # Verificar que se haya proporcionado el p煤blico objetivo y el producto
128
- try:
129
- response = get_gemini_response(target_audience, product, product_mention, text_type, length, mood, model_choice)
130
- col2.subheader("Contenido generado:")
131
- col2.write(response)
132
- except ValueError as e:
133
- col2.error(f"Error: {str(e)}")
134
- else:
135
- col2.error("Por favor, proporciona el p煤blico objetivo y el producto.")
 
2
  import streamlit as st
3
  import os
4
  import google.generativeai as genai
5
+ import random # Nueva importaci贸n para la selecci贸n aleatoria de menci贸n
6
 
7
  load_dotenv()
8
 
9
  genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
10
 
11
+ # Funci贸n para obtener una menci贸n del producto de manera probabil铆stica
12
+ def get_random_product_mention():
13
+ # Definir las opciones de menci贸n y sus probabilidades
14
+ mentions = ["Directa", "Indirecta", "Metaf贸rica"]
15
+ probabilities = [0.34, 0.33, 0.33] # Probabilidades de cada menci贸n (ajusta seg煤n desees)
16
+
17
+ # Elegir una opci贸n al azar bas谩ndose en las probabilidades
18
+ return random.choices(mentions, probabilities)[0]
19
+
20
+ def get_gemini_response(target_audience, product, text_type, length, mood, model_choice):
21
+ # Generar la menci贸n aleatoria
22
+ product_mention = get_random_product_mention() # Llamada correcta a la funci贸n
23
  model = genai.GenerativeModel(model_choice)
24
 
25
  # Crear la instrucci贸n de menci贸n basada en la opci贸n seleccionada
 
59
  # Crear el prompt completo basado en los campos del frontend
60
  full_prompt = f"""
61
  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} {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.
62
+ Create an opening paragraph for a {text_type} that makes {target_audience} aware they have a problem by explaining it with real-life situations, using a natural or conversational tone. The goal of this paragraph is to make them want to keep reading and find out what {product} is about. Use persuasion effectively in every word, mastering advanced techniques like using powerful headlines and intriguing openings.
63
 
64
  To write this opening paragraph, use one or more of these Copywriting Techniques, choosing the most appropriate ones:
65
 
 
80
  raise ValueError("Lo sentimos, intenta con una combinaci贸n diferente de entradas.")
81
 
82
  # Inicializar la aplicaci贸n Streamlit
83
+ st.set_page_config(page_title="VisionTales", layout="wide")
84
+ st.title("VisionTales: Crea historias inolvidables con IA")
85
 
86
+ with st.sidebar:
87
+ st.header("Personaliza tu texto")
88
+ target_audience = st.text_input("驴Qui茅n es tu p煤blico objetivo?")
89
+ product = st.text_input("Nombre del producto:")
90
+ text_type = st.selectbox("Tipo de texto:", ["Historia", "Carta de venta", "Correo", "Landing page"])
91
+ length = st.slider("Longitud del texto:", 50, 1000, 300)
92
+ mood = st.selectbox("Estado de 谩nimo:", ["Feliz", "Triste", "Motivador", "Reflexivo"])
93
+ model_choice = st.selectbox("Selecciona el modelo:", ["gemini-1.5-flash", "gemini-1.5-pro"])
94
 
95
+ # Bot贸n para generar el texto
96
+ if st.button("Generar texto"):
97
+ try:
98
+ generated_text = get_gemini_response(target_audience, product, text_type, length, mood, model_choice)
99
+ st.subheader("Texto Generado:")
100
+ st.write(generated_text)
101
+ except Exception as e:
102
+ st.error(f"Error: {e}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
103
 
104
+ st.markdown("---")
105
+ st.write("Este generador de texto est谩 dise帽ado para ayudarte a crear contenido atractivo y efectivo con la ayuda de la inteligencia artificial.")