Spaces:
Sleeping
Sleeping
File size: 3,911 Bytes
91a0d7e a8fd769 d51e47b a8fd769 d51e47b 1ff0df4 a8fd769 1ff0df4 252dc1f 1ff0df4 a8fd769 1ff0df4 a8fd769 1ff0df4 d51e47b 1ff0df4 d51e47b 1ff0df4 a8fd769 bef3dc5 1ff0df4 a8fd769 1ff0df4 a8fd769 1ff0df4 a8fd769 1ff0df4 a8fd769 60ce54c 1ff0df4 a8fd769 1ff0df4 a8fd769 1ff0df4 a8fd769 1ff0df4 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
from dotenv import load_dotenv
import streamlit as st
import os
import google.generativeai as genai
load_dotenv()
genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
# Función para obtener respuesta del modelo Gemini
def get_gemini_response(target_audience, product, text_type, length, language, mood, model_choice):
model = genai.GenerativeModel(model_choice)
# Crear el prompt completo basado en los campos del frontend
full_prompt = f"""
You are a creative writer skilled in the art of persuasion. Write a {length} {text_type} in {language}. The tone of the {text_type} should be {mood} and carefully crafted to emotionally resonate with a {target_audience}. Ensure that subtle and realistic references to the product '{product}' are included without explicitly mentioning it. 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.
"""
response = model.generate_content([full_prompt])
# Comprobar si la respuesta es válida y devolver el texto
if response and response.parts:
return response.parts[0].text
else:
raise ValueError("Lo sentimos, intenta con una combinación diferente de entradas.")
# Inicializar la aplicación Streamlit
st.set_page_config(page_title="Poetic Vision", page_icon=":pencil:", layout="wide") # Configurar el diseño en ancho
# Componentes principales de la UI
st.markdown("<h1 style='text-align: center;'>VisionTales</h1>", unsafe_allow_html=True)
st.markdown("<h3 style='text-align: center;'>Convierte tus ideas en historias inolvidables.</h3>", unsafe_allow_html=True)
# Añadir CSS personalizado para el botón
st.markdown("""
<style>
div.stButton > button {
background-color: #FFCC00; /* Color llamativo */
color: black; /* Texto en negro */
width: 90%;
height: 60px;
font-weight: bold;
font-size: 22px; /* Tamaño más grande */
text-transform: uppercase; /* Texto en mayúsculas */
border: 1px solid #000000; /* Borde negro de 1px */
border-radius: 8px;
display: block;
margin: 0 auto; /* Centramos el botón */
}
div.stButton > button:hover {
background-color: #FFD700; /* Color al pasar el mouse */
color: black; /* Texto sigue en negro */
}
</style>
""", unsafe_allow_html=True)
# Crear dos columnas para el diseño (40% y 60%)
col1, col2 = st.columns([2, 3]) # 2 + 3 = 5 partes en total
with col1:
# Entradas del usuario
target_audience = st.text_input("Público objetivo:", placeholder="Especifica tu público aquí...")
product = st.text_input("Producto:", placeholder="Especifica el producto aquí...")
text_type = st.selectbox("Tipo de texto:", ["Historia", "Shayari", "Sher", "Poema", "Cita"])
length = st.selectbox("Longitud del texto:", ["Corto", "Largo"])
language = st.selectbox("Idioma del texto:", ["Español", "Inglés"])
mood = st.selectbox("Tono del Texto:", ["Emocional", "Triste", "Feliz", "Horror", "Comedia", "Romántico"])
# Opción para seleccionar el modelo
model_choice = st.selectbox("Selecciona el modelo:", ["gemini-1.5-flash", "gemini-1.5-pro"], index=0)
# Botón para generar contenido
submit = st.button("Escribir mi historia")
# Manejo del clic en el botón
if submit:
if target_audience and product: # Verificar que se haya proporcionado el público objetivo y el producto
try:
response = get_gemini_response(target_audience, product, text_type, length, language, mood, model_choice)
col2.subheader("Contenido generado:")
col2.write(response)
except ValueError as e:
col2.error(f"Error: {str(e)}")
else:
col2.error("Por favor, proporciona el público objetivo y el producto.")
|