|
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_pasa_response(target_audience, product, action, mood, length): |
|
model = genai.GenerativeModel("gemini-1.5-flash") |
|
full_prompt = f""" |
|
You are a skilled copywriter and storyteller. Create a persuasive story in Spanish following the P.A.S.A. formula (Problema, Agitaci贸n, Soluci贸n, Acci贸n). |
|
Do not explicitly label or explain each section (Problema, Agitaci贸n, Soluci贸n, Acci贸n). Instead, weave these elements naturally into a cohesive, flowing narrative that emotionally connects with the {target_audience}. |
|
The story should have {length} words, with a {mood} tone. Here are the details: |
|
1. Problema: Describe a specific problem that keeps the {target_audience} awake at night. |
|
2. Agitaci贸n: Amplify the emotional and practical consequences of this problem. |
|
3. Soluci贸n: Highlight how the product '{product}' solves this problem and improves their life. |
|
4. Acci贸n: Adapt the provided call-to-action '{action}' and craft it in a way that motivates the reader to take immediate steps, using compelling language that encourages them to act. |
|
Write a cohesive, engaging, and emotionally resonant narrative tailored to connect with the {target_audience}. |
|
""" |
|
response = model.generate_content([full_prompt]) |
|
if response and response.parts: |
|
text = response.parts[0].text |
|
return text.strip() |
|
else: |
|
raise ValueError("Lo sentimos, intenta con una combinaci贸n diferente de entradas.") |
|
|
|
|
|
def get_adp_response(target_audience, product, action, mood, length): |
|
model = genai.GenerativeModel("gemini-1.5-flash") |
|
full_prompt = f""" |
|
You are a skilled copywriter and storyteller. Create a creative and persuasive story in Spanish following the A.D.P. formula (Antes, Despu茅s, Puente). |
|
Do not explicitly label or explain each section (Antes, Despu茅s, Puente). Instead, weave these elements naturally into a cohesive, flowing narrative that emotionally connects with the {target_audience}. |
|
The story should always be written in the second person (using 't煤') and should have unexpected twists to engage the {target_audience}. |
|
The story should have {length} words, with a {mood} tone. Here are the details: |
|
|
|
1. Antes: Describe the current problem and frustrations that you {target_audience} are facing. Create an immersive situation where the reader can recognize themselves. |
|
2. Despu茅s: Paint a desired scenario where the problem of {target_audience} is solved and the benefits are clearly evident. Use a surprising twist to show how life can change. |
|
3. Puente: Introduce your solution '{product}' as the logical bridge between your frustration and the desired result. Make sure to emphasize the transformation you鈥檒l experience if you take action '{action}'. Conclude with a compelling call to action '{action}' inviting the reader to take immediate steps to improve their situation. |
|
Ensure that the story has a creative flow with unexpected turns and keeps the reader hooked, motivating them to act at the end. |
|
Write a cohesive, engaging, and emotionally resonant narrative tailored to connect deeply with you, the {target_audience}. |
|
""" |
|
response = model.generate_content([full_prompt]) |
|
if response and response.parts: |
|
text = response.parts[0].text |
|
return text.strip() |
|
else: |
|
raise ValueError("Lo sentimos, intenta con una combinaci贸n diferente de entradas.") |
|
|
|
|
|
def get_gha_response(target_audience, product, action, mood, length, story_topic): |
|
model = genai.GenerativeModel("gemini-1.5-flash") |
|
full_prompt = f""" |
|
You are a skilled copywriter and storyteller. Create a persuasive story in Spanish following the G.H.A. formula (Gancho, Historia, Acci贸n). |
|
Do not explicitly label or explain each section (Gancho, Historia, Acci贸n). Instead, weave these elements naturally into a cohesive, flowing narrative that emotionally connects with the {target_audience}. |
|
The story should have {length} words, with a {mood} tone. Here are the details: |
|
1. Gancho: Start with an attention-grabbing hook that immediately captures the {target_audience}'s interest. It can be a question, a surprising fact, or a statement that challenges their beliefs. |
|
2. Historia: Tell an engaging and emotional story about {story_topic}. This can be personal or fictional, but should always have a meaningful lesson or takeaway for the {target_audience}. |
|
3. Acci贸n: Conclude with a compelling call to action '{action}' inviting the reader to take immediate steps to improve their situation. Make the call-to-action compelling and clear, prompting immediate action. |
|
Write a cohesive, engaging, and emotionally resonant narrative tailored to connect with the {target_audience}. |
|
""" |
|
response = model.generate_content([full_prompt]) |
|
if response and response.parts: |
|
text = response.parts[0].text |
|
return text.strip() |
|
else: |
|
raise ValueError("Lo sentimos, intenta con una combinaci贸n diferente de entradas.") |
|
|
|
|
|
st.set_page_config(page_title="Generador de Historias", page_icon=":pencil:", layout="wide") |
|
|
|
st.markdown("<h1 style='text-align: center;'>Generador de Historias</h1>", unsafe_allow_html=True) |
|
st.markdown("<h3 style='text-align: center;'>Crea historias persuasivas con inteligencia artificial, dise帽adas para conectar emocionalmente con tu audiencia.</h3>", unsafe_allow_html=True) |
|
|
|
|
|
col1, col2 = st.columns([2, 3]) |
|
|
|
|
|
with col1: |
|
target_audience = st.text_input("P煤blico objetivo", placeholder="驴A qui茅n est谩 dirigido tu mensaje?") |
|
product = st.text_input("Producto/Servicio", placeholder="驴Qu茅 est谩s ofreciendo?") |
|
action = st.text_area("Llamado a la acci贸n", placeholder="驴Qu茅 acci贸n espec铆fica debe tomar tu audiencia?") |
|
|
|
|
|
with st.expander("Personaliza tu historia"): |
|
mood = st.selectbox("Tono de la historia:", ["Emocional", "Triste", "Feliz", "Horror", "Comedia", "Rom谩ntico"]) |
|
length = st.slider("Longitud de la historia (palabras):", min_value=50, max_value=150, value=100, step=10) |
|
|
|
|
|
with st.expander("P.A.S.A."): |
|
|
|
pass |
|
|
|
with st.expander("A.D.P."): |
|
|
|
pass |
|
|
|
with st.expander("G.H.A."): |
|
story_topic = st.text_area("De qu茅 quieres que trate la historia", placeholder="Explica si hay algo espec铆fico sobre lo que te gustar铆a contar (puede ser una vivencia personal, pel铆cula, cuento, personaje ficticio, etc.).") |
|
|
|
|
|
submit = st.button("Generar mi historia") |
|
|
|
|
|
with col2: |
|
if submit: |
|
if target_audience and product and action: |
|
try: |
|
if "P.A.S.A." in st.expander("P.A.S.A.").expanded: |
|
response = get_pasa_response(target_audience, product, action, mood, length) |
|
elif "A.D.P." in st.expander("A.D.P.").expanded: |
|
response = get_adp_response(target_audience, product, action, mood, length) |
|
elif "G.H.A." in st.expander("G.H.A.").expanded: |
|
if story_topic: |
|
response = get_gha_response(target_audience, product, action, mood, length, story_topic) |
|
else: |
|
st.error("Por favor, completa todos los campos requeridos para la f贸rmula G.H.A.") |
|
response = "" |
|
|
|
if response: |
|
st.subheader("Historia generada:") |
|
st.write(response) |
|
except ValueError as e: |
|
st.error(f"Error: {str(e)}") |
|
else: |
|
st.error("Por favor, completa todos los campos requeridos (P煤blico objetivo, Producto y Acci贸n).") |
|
|