Spaces:
Running
Running
File size: 5,496 Bytes
e00b344 d8717d2 e00b344 eb6729d e00b344 eb6729d e00b344 4110f31 eb6729d 4110f31 eb6729d 086f7bc 6dc4bab eb6729d 086f7bc 898737f eb6729d 898737f eb6729d 4110f31 eb6729d 4110f31 eb6729d 4110f31 de72557 4110f31 3c98a42 eb6729d 6497148 086f7bc 4110f31 086f7bc de72557 507ca0b 086f7bc eb6729d f802f3d dd547ea d603b99 e00b344 de72557 e00b344 086f7bc e00b344 de72557 b2af965 6dc4bab b2af965 e00b344 eb6729d |
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 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
from dotenv import load_dotenv
import streamlit as st
import os
import google.generativeai as genai
import random
# Cargar las variables de entorno
load_dotenv()
# Configurar la API de GenAI
genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
# Funci贸n para obtener una menci贸n del producto de manera probabil铆stica
def get_random_product_mention():
mentions = ["Indirecta", "Metaf贸rica"]
probabilities = [0.50, 0.50]
return random.choices(mentions, probabilities)[0]
# Crear la instrucci贸n de menci贸n basada en la opci贸n seleccionada
def get_mention_instruction(product_mention, product):
if product_mention == "Indirecta":
return f"Referencia sutilmente el producto '{product}' como una posible soluci贸n al problema del lector sin nombrarlo expl铆citamente."
elif product_mention == "Metaf贸rica":
return f"Introduce el producto '{product}' usando una met谩fora, conect谩ndolo simb贸licamente a la soluci贸n que necesita el lector."
return ""
# Funci贸n para generar los beneficios (bullets) basados en el enfoque
def generate_benefits(focus_points, product, target_audience, creativity, num_bullets):
product_mention = get_random_product_mention()
mention_instruction = get_mention_instruction(product_mention, product)
# Instrucci贸n del sistema para el modelo
system_instruction = (
"You are a world-class copywriter with expertise in crafting emotional and persuasive benefits that connect with the target audience. "
"Generate highly creative and engaging benefits that resonate with the audience's desires and challenges."
)
# Base del prompt
prompt_base = f"""
Eres un experto en copywriting y tu objetivo es crear {{num_bullets}} bullets persuasivos que conecten emocionalmente con la audiencia {{target_audience}}.
Cada bullet debe abordar sus problemas, deseos o situaciones, mostrando c贸mo se pueden mejorar o solucionar gracias a una soluci贸n espec铆fica.
La idea es resaltar el valor que aporta la soluci贸n, sin que suene como una venta forzada.
Adem谩s, menciona el producto utilizando el siguiente enfoque: {{mention_instruction}}.
Usa enfoques creativos para conectar los beneficios del producto con lo que realmente le importa a la audiencia.
Crea {{num_bullets}} bullets persuasivos que muestren c贸mo el producto puede transformar la situaci贸n de la audiencia.
"""
benefits = []
for point in focus_points[:num_bullets]:
specific_prompt = prompt_base.format(
num_bullets=num_bullets,
target_audience=target_audience,
mention_instruction=mention_instruction
) + f"\n\nEnfoque: {point}\n"
# Configuraci贸n del modelo y generaci贸n de contenido
response = genai.generate_text(
model="gemini-1.5-flash",
prompt=specific_prompt,
temperature=creativity,
top_p=0.65,
top_k=280,
max_output_tokens=2048,
)
if response and response.generations:
bullet = response.generations[0].text.strip()
benefits.append(bullet)
else:
benefits.append("No se pudo generar un beneficio para este enfoque.")
return benefits
# Configuraci贸n de Streamlit
st.set_page_config(page_title="Impact Bullet Generator", layout="wide")
# Leer el contenido del archivo manual.md
with open("manual.md", "r", encoding="utf-8") as file:
manual_content = file.read()
# Mostrar el contenido del manual en el sidebar
st.sidebar.markdown(manual_content)
# Centrar el t铆tulo y el subt铆tulo
st.markdown("<h1 style='text-align: center;'>Impact Bullet Generator</h1>", unsafe_allow_html=True)
st.markdown("<h4 style='text-align: center;'>Transforma los pensamientos de tu audiencia en beneficios persuasivos que inspiren a la acci贸n.</h4>", unsafe_allow_html=True)
# Crear columnas
col1, col2 = st.columns([1, 2])
# Columnas de entrada
with col1:
target_audience = st.text_input("P煤blico objetivo:", placeholder="Ejemplo: Estudiantes universitarios")
product = st.text_input("Producto relacionado:", placeholder="Ejemplo: Curso de productividad")
# Slider para la creatividad
creativity = st.slider("Creatividad (Temperatura)", min_value=0.0, max_value=1.0, value=0.7, step=0.1)
# Slider para el n煤mero de bullets
num_bullets = st.slider("N煤mero de Bullets", min_value=1, max_value=10, value=5, step=1)
focus_points = st.multiselect(
"Selecciona los enfoques que deseas utilizar:",
["Curiosidad", "CASI Imposible", "Autoridad y Credibilidad", "Contraste"],
default=[]
)
submit = st.button("Generar Beneficios")
# Mostrar los beneficios generados
with col2:
if submit:
if focus_points and product and target_audience:
benefits = generate_benefits(focus_points, product, target_audience, creativity, num_bullets)
formatted_benefits = '<br style="line-height: 2;">'.join(benefits)
st.markdown(f"""
<div style="border: 1px solid #000000; padding: 5px; border-radius: 8px; background-color: #ffffff;">
<h4>Mira los beneficios generados:</h4>
<p style="line-height: 2;">{formatted_benefits}</p>
</div>
""", unsafe_allow_html=True)
else:
st.error("Por favor, proporciona al menos un enfoque, un producto y un p煤blico objetivo para generar beneficios.")
|