hookgenerator / app.py
JeCabrera's picture
Update app.py
2859ad6 verified
raw
history blame
2.98 kB
import gradio as gr
import anthropic
import os # Importa el módulo os para manejar variables de entorno
# Obtén la clave de API desde la variable de entorno
api_key = os.getenv("ANTHROPIC_API_KEY")
# Configura el cliente de Anthropic
client = anthropic.Anthropic(api_key=api_key)
# Define la función que genera los titulares
def generate_headlines(number_of_headlines, target_audience, product):
# Configura el mensaje para la API
system_message = (
"You are a world-class copywriter with expertise in creating compelling hooks, headlines, and subject lines. "
"Your talent lies in understanding the emotions, desires, and challenges of a specific audience, allowing you to craft "
"personalized marketing strategies that resonate and motivate action. Use proven structures to attract your target audience, "
"generating interest and achieving a powerful connection that drives desired results in advertising and content campaigns. "
"Respond in Markdown format."
)
user_message = (
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."
)
# Llama a la API de Claude
response = client.messages.create(
model="claude-3-5-sonnet-20240620",
max_tokens=1000,
temperature=0,
system=system_message,
messages=[
{
"role": "user",
"content": [
{
"type": "text",
"text": user_message
}
]
}
]
)
# Extrae y retorna el contenido de la respuesta
headlines = response.content
return headlines
# Configura la interfaz de usuario de Gradio
with gr.Blocks() as demo:
gr.Markdown(
"""
<div style="text-align: center; font-size: 32px; font-weight: bold; margin-bottom: 20px;">
Headline Generator
</div>
<div style="text-align: center;">
<p>Generate compelling headlines for your marketing needs.</p>
</div>
"""
)
number_of_headlines = gr.Slider(minimum=1, maximum=10, value=5, label="Number of Headlines")
target_audience = gr.Textbox(label="Target Audience", placeholder="e.g., tech enthusiasts, busy professionals")
product = gr.Textbox(label="Product", placeholder="e.g., new smartphone, productivity tool")
generate_button = gr.Button("Generate Headlines")
output = gr.Markdown()
generate_button.click(
generate_headlines,
inputs=[number_of_headlines, target_audience, product],
outputs=output
)
demo.launch()