JeCabrera's picture
Update app.py
9b6b4fd verified
raw
history blame
3.1 kB
# app.py
import gradio as gr
import anthropic
# Configura el cliente de la API de Claude (Anthropic)
client = anthropic.Anthropic(api_key="my_api_key") # Reemplaza "my_api_key" con tu clave de API
def generate_headlines(number_of_headlines, target_audience, product):
# Llama a la API de Claude para generar titulares
message = client.messages.create(
model="claude-3-5-sonnet-20240620",
max_tokens=1000,
temperature=0,
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
# Configura la interfaz de usuario con Gradio
def gradio_generate_headlines(number_of_headlines, target_audience, product):
return generate_headlines(number_of_headlines, target_audience, product)
# Define los colores de la interfaz según el logo de Anthropic (ejemplo)
logo_colors = {
"background": "#f8f8f8",
"primary": "#2c7be5",
"text_color": "#212529"
}
with gr.Blocks(css=".gradio-container { background-color: " + logo_colors["background"] + "; }") as demo:
gr.Markdown(
f"""
<h1 style="color: {logo_colors['primary']}; text-align: center;">Generador de Titulares</h1>
<p style="color: {logo_colors['text_color']}; text-align: center;">Usa el poder de Claude AI para crear titulares atractivos</p>
"""
)
with gr.Row():
with gr.Column():
number_of_headlines = gr.Number(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")
submit_btn = gr.Button("Generar Titulares", elem_id="submit-btn")
output = gr.Textbox(label="Titulares Generados", lines=10)
submit_btn.click(
fn=gradio_generate_headlines,
inputs=[number_of_headlines, target_audience, product],
outputs=output
)
# Lanza la interfaz
demo.launch()