|
import gradio as gr |
|
import anthropic |
|
import os |
|
|
|
|
|
api_key = os.getenv("ANTHROPIC_API_KEY") |
|
|
|
|
|
if not api_key: |
|
raise ValueError("Falta la clave de API de Anthropoid. Asegúrate de configurarla en los secretos del repositorio.") |
|
|
|
|
|
client = anthropic.Anthropic(api_key=api_key) |
|
|
|
def generate_headlines(number_of_headlines, target_audience, product, temperature): |
|
|
|
message = client.messages.create( |
|
model="claude-3-5-sonnet-20240620", |
|
max_tokens=4000, |
|
temperature=temperature, |
|
system="You are a world-class copywriter, with experience in creating hooks, headlines, and subject lines that immediately capture attention. Your skill lies in deeply understanding the emotions, desires, and challenges of a specific audience, allowing you to design personalized marketing strategies that resonate and motivate action. You know how to use proven structures to attract your target audience, generating interest and achieving a powerful connection that drives desired results in advertising and content campaigns.\n\nAnswer in Spanish.", |
|
messages=[ |
|
{ |
|
"role": "user", |
|
"content": [ |
|
{ |
|
"type": "text", |
|
"text": f"Generate {number_of_headlines} attention-grabbing headlines designed for {target_audience} to generate interest in {product}. Each headline should be crafted to encourage a specific action, such as making a purchase, signing up, or downloading. Use a variety of formats (questions, bold statements, intriguing facts) to test different approaches." |
|
} |
|
] |
|
} |
|
] |
|
) |
|
return message.content |
|
|
|
|
|
def gradio_generate_headlines(number_of_headlines, target_audience, product, temperature): |
|
return generate_headlines(number_of_headlines, target_audience, product, temperature) |
|
|
|
with gr.Blocks(css=".gradio-container { background-color: #f8f8f8; }") as demo: |
|
gr.Markdown( |
|
""" |
|
<h1 style="color: #2c7be5; text-align: center;">Generador de Titulares</h1> |
|
<p style="color: #212529; text-align: center;">Usa el poder de Claude AI para crear titulares atractivos</p> |
|
""" |
|
) |
|
|
|
with gr.Row(): |
|
with gr.Column(): |
|
number_of_headlines = gr.Dropdown(choices=[str(i) for i in range(1, 11)], label="Número de Titulares", value="5") |
|
target_audience = gr.Textbox(label="Público Objetivo", placeholder="Ejemplo: Estudiantes Universitarios") |
|
product = gr.Textbox(label="Producto", placeholder="Ejemplo: Curso de Inglés") |
|
temperature = gr.Slider(minimum=0, maximum=1, value=0, step=0.1, label="Creatividad") |
|
submit_btn = gr.Button("Generar Titulares") |
|
|
|
with gr.Column(scale=2): |
|
output = gr.HTML( |
|
""" |
|
<div id="result-container" style="background-color: #ffffff; padding: 10px; border-radius: 8px; box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);"> |
|
<p id="result-text" style="font-size: 16px; color: #333333;">Los titulares aparecerán aquí...</p> |
|
</div> |
|
""", |
|
label="Titulares Generados" |
|
) |
|
|
|
submit_btn.click( |
|
fn=gradio_generate_headlines, |
|
inputs=[number_of_headlines, target_audience, product, temperature], |
|
outputs=output |
|
) |
|
|
|
|
|
demo.launch() |
|
|