|
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, product_mention, mood, length): |
|
model = genai.GenerativeModel("gemini-1.5-flash") |
|
|
|
|
|
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." |
|
|
|
|
|
format_instruction = "Ensure that the narrative is engaging and includes character development, a clear plot, and a resolution." |
|
|
|
|
|
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]) |
|
|
|
|
|
if response and response.parts: |
|
|
|
text = response.parts[0].text |
|
paragraphs = text.split("\n") |
|
formatted_text = "\n\n".join(paragraphs) |
|
return formatted_text |
|
else: |
|
raise ValueError("Lo sentimos, intenta con una combinación diferente de entradas.") |
|
|
|
|
|
st.set_page_config(page_title="Story Genius Maker", page_icon=":pencil:", layout="wide") |
|
|
|
|
|
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) |
|
|
|
|
|
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í...") |
|
|
|
|
|
with st.expander("Personaliza tu texto"): |
|
|
|
product_mention = st.selectbox("Mención del producto:", ["Directa", "Indirecta", "Metafórica"]) |
|
|
|
|
|
mood = st.selectbox("Tono del Texto:", ["Emocional", "Triste", "Feliz", "Horror", "Comedia", "Romántico"]) |
|
|
|
|
|
length = st.slider("Longitud del texto (palabras):", min_value=50, max_value=500, value=200, step=10) |
|
|
|
|
|
submit = st.button("Escribir mi historia") |
|
|
|
|
|
if submit: |
|
if target_audience and product: |
|
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.") |
|
|