|
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")) |
|
|
|
|
|
def get_gemini_response(target_audience, product, text_type, length, language, mood, model_choice): |
|
model = genai.GenerativeModel(model_choice) |
|
|
|
|
|
full_prompt = f""" |
|
Eres un escritor creativo famoso. Crea un {length} {text_type} en {language}. |
|
El {text_type} debe ser {mood}, dirigido a este público objetivo: {target_audience}, y relacionado con el producto: "{product}". |
|
Asegúrate de que contenga elementos realistas y emocionales. |
|
""" |
|
|
|
response = model.generate_content([full_prompt]) |
|
|
|
|
|
if response and response.parts: |
|
return response.parts[0].text |
|
else: |
|
raise ValueError("Lo sentimos, intenta con una combinación diferente de entradas.") |
|
|
|
|
|
st.set_page_config(page_title="Poetic Vision", page_icon=":pencil:", layout="wide") |
|
|
|
|
|
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) |
|
|
|
|
|
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) |
|
|
|
|
|
col1, col2 = st.columns([2, 3]) |
|
|
|
with col1: |
|
|
|
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"]) |
|
|
|
|
|
model_choice = st.selectbox("Selecciona el modelo:", ["gemini-1.5-flash", "gemini-1.5-pro"], index=0) |
|
|
|
|
|
submit = st.button("Escribir mi historia") |
|
|
|
|
|
if submit: |
|
if target_audience and product: |
|
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.") |
|
|