Spaces:
Sleeping
Sleeping
File size: 5,115 Bytes
91a0d7e a8fd769 d51e47b a8fd769 d51e47b 1ff0df4 dc809d3 a8fd769 2610857 ff0dac9 2610857 363592e 2610857 363592e 2610857 363592e ff0dac9 363592e 37d737e 2610857 1ff0df4 ff360f5 1ff0df4 a8fd769 1ff0df4 a8fd769 ff360f5 a8fd769 1ff0df4 d51e47b 1ff0df4 363592e d51e47b 07d65ad b6c3725 07d65ad bef3dc5 1ff0df4 a8fd769 1ff0df4 363592e a8fd769 1ff0df4 2610857 363592e 2610857 dc809d3 85eb710 a8fd769 1ff0df4 a8fd769 60ce54c 1ff0df4 a8fd769 363592e a8fd769 dc809d3 a8fd769 363592e 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 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
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, product_mention, mood, length):
model = genai.GenerativeModel("gemini-1.5-flash") # Modelo predeterminado
# Crear la instrucci贸n de menci贸n basada en la opci贸n seleccionada
mention_instruction = ""
if product_mention == "Directa":
mention_instruction = f"Mention the product '{product}' directly in the text."
elif product_mention == "Indirecta":
mention_instruction = f"Ensure that subtle and realistic references to the product '{product}' are included without explicitly mentioning it."
elif product_mention == "Metaf贸rica":
mention_instruction = f"Refer to the product '{product}' through a metaphor without explicitly mentioning it."
# Instrucci贸n espec铆fica para el tipo de texto (siempre ser谩 "Historia")
format_instruction = "Ensure that the narrative is engaging and includes character development, a clear plot, and a resolution."
# 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 story of {length} words in Spanish. The tone of the story 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.
"""
response = model.generate_content([full_prompt])
# Comprobar si la respuesta es v谩lida y devolver el texto
if response and response.parts:
# Formatear la respuesta en p谩rrafos
text = response.parts[0].text
paragraphs = text.split("\n") # Suponiendo que los p谩rrafos est谩n separados por saltos de l铆nea
formatted_text = "\n\n".join(paragraphs) # Unir los p谩rrafos con dos saltos de l铆nea
return formatted_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="Story Genius Maker", page_icon=":pencil:", layout="wide") # Configurar el dise帽o en ancho
# T铆tulo y subt铆tulo
st.markdown("<h1 style='text-align: center;'>Story Genius Maker</h1>", unsafe_allow_html=True)
st.markdown("<h3 style='text-align: center;'>Teje historias inolvidables en segundos, guiado por la magia de la inteligencia artificial que da vida a tus ideas en relatos cautivadores.</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铆...")
# Agrupar todas las opciones en una acorde贸n
with st.expander("Personaliza tu texto"):
# Variable para c贸mo se debe mencionar el producto
product_mention = st.selectbox("Menci贸n del producto:", ["Directa", "Indirecta", "Metaf贸rica"])
# Eliminar la opci贸n de tipo de texto y longitud del texto
mood = st.selectbox("Tono del Texto:", ["Emocional", "Triste", "Feliz", "Horror", "Comedia", "Rom谩ntico"])
# Slider para seleccionar la longitud del texto
length = st.slider("Longitud del texto (palabras):", min_value=50, max_value=500, value=200, step=10)
# 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, product_mention, mood, length)
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.")
|