|
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")) |
|
|
|
system_prompt = """You are a world-class copywriter, with expertise in crafting hooks, headlines, and subject lines that immediately capture the reader's attention, prompting them to open the email or continue reading. |
|
FORMAT RULES: |
|
- Each headline must start with number and period |
|
- One headline per line |
|
- No explanations or categories |
|
- Add a line break between each headline |
|
- Avoid unnecessary : symbols |
|
- Each headline must be a complete and intriguing sentence |
|
IMPORTANT ANGLE INSTRUCTIONS: |
|
- The selected angle MUST be applied to EVERY headline |
|
- The angle modifies HOW the formula is expressed, not its structure |
|
- Think of the angle as a "tone overlay" on the formula |
|
- The formula provides the structure, the angle provides the style |
|
- Both must work together seamlessly |
|
FORMAT EXAMPLE: |
|
1. Titular 1. |
|
2. Titular 2. |
|
3. Titular 3. |
|
4. Titular 4. |
|
5. Titular 5. |
|
IMPORTANT: |
|
- Each headline must be unique and memorable |
|
- Avoid clich茅s and generalities |
|
- Maintain an intriguing but credible tone |
|
- Adapt speaking language from the audience |
|
- Focus on transformative benefits |
|
- Follow the selected angle style while maintaining formula structure""" |
|
|
|
story_formulas = { |
|
"PASA": { |
|
"description": """ |
|
La f贸rmula P.A.S.A. se estructura de manera natural y fluida: |
|
1. **Problema**: |
|
- Identificaci贸n del dolor espec铆fico |
|
- Situaci贸n actual problem谩tica |
|
- Frustraci贸n principal |
|
2. **Agitaci贸n**: |
|
- Consecuencias emocionales |
|
- Impacto en la vida diaria |
|
- Costos de no resolver |
|
3. **Soluci贸n**: |
|
- Presentaci贸n del producto/servicio |
|
- Beneficios clave |
|
- Transformaci贸n posible |
|
4. **Acci贸n**: |
|
- Siguiente paso claro |
|
- Motivaci贸n para actuar |
|
- Beneficio inmediato |
|
""" |
|
}, |
|
"ADP": { |
|
"description": """ |
|
La f贸rmula A.D.P. fluye naturalmente: |
|
1. **Antes**: |
|
- Estado actual |
|
- Frustraciones diarias |
|
- Situaci贸n problem谩tica |
|
2. **Despu茅s**: |
|
- Escenario ideal |
|
- Beneficios alcanzados |
|
- Nueva realidad |
|
3. **Puente**: |
|
- Conexi贸n soluci贸n-resultado |
|
- Transformaci贸n posible |
|
- Camino al cambio |
|
""" |
|
}, |
|
"GHA": { |
|
"description": """ |
|
La f贸rmula G.H.A. se desarrolla naturalmente: |
|
1. **Gancho**: |
|
- Apertura impactante |
|
- Elemento sorpresa |
|
- Conexi贸n inmediata |
|
2. **Historia**: |
|
- Narrativa envolvente |
|
- Desarrollo personal |
|
- Aprendizaje clave |
|
3. **Acci贸n**: |
|
- Conclusi贸n natural |
|
- Invitaci贸n clara |
|
- Motivaci贸n final |
|
""" |
|
} |
|
} |
|
|
|
def generate_story(formula_type, **kwargs): |
|
"""Funci贸n unificada para generar historias""" |
|
model = genai.GenerativeModel("gemini-1.5-flash") |
|
|
|
if formula_type not in story_formulas: |
|
raise ValueError("F贸rmula no v谩lida") |
|
|
|
formula_description = story_formulas[formula_type]["description"] |
|
|
|
prompt = f"""{system_prompt} |
|
|
|
Como experto copywriter, crea una historia persuasiva en espa帽ol de {kwargs['length']} palabras con un tono {kwargs['mood']}, siguiendo la estructura: |
|
|
|
{formula_description} |
|
|
|
P煤blico objetivo: {kwargs['target_audience']} |
|
Producto/Servicio: {kwargs['product']} |
|
Llamada a acci贸n: {kwargs['action']} |
|
""" |
|
|
|
if formula_type == "GHA" and 'story_topic' in kwargs: |
|
prompt += f"\nTema de la historia: {kwargs['story_topic']}" |
|
|
|
response = model.generate_content([prompt]) |
|
if response and response.parts: |
|
return response.parts[0].text.strip() |
|
raise ValueError("No se pudo generar la historia") |
|
|
|
|
|
st.set_page_config(page_title="Generador de Historias", 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) |
|
|
|
|
|
with st.expander("Selecciona la f贸rmula para generar tu historia"): |
|
formula = st.radio("Selecciona la f贸rmula para generar tu historia:", ["P.A.S.A.", "A.D.P.", "G.H.A."]) |
|
|
|
|
|
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"]) |
|
|
|
|
|
if formula == "G.H.A.": |
|
length = st.slider("Longitud de la historia (palabras):", min_value=50, max_value=200, value=150, step=10) |
|
else: |
|
length = st.slider("Longitud de la historia (palabras):", min_value=50, max_value=150, value=100, step=10) |
|
|
|
if formula == "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 formula == "P.A.S.A.": |
|
response = get_pasa_response(target_audience, product, action, mood, length) |
|
elif formula == "A.D.P.": |
|
response = get_adp_response(target_audience, product, action, mood, length) |
|
elif formula == "G.H.A.": |
|
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).") |
|
|