File size: 2,981 Bytes
9b6b4fd
 
bf6e5b1
 
 
 
 
2859ad6
bf6e5b1
90557f1
2859ad6
9b6b4fd
2859ad6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9b6b4fd
 
 
2859ad6
9b6b4fd
 
 
 
 
 
2859ad6
9b6b4fd
 
 
 
90557f1
2859ad6
 
 
 
90557f1
2859ad6
 
9b6b4fd
2859ad6
 
 
 
 
 
 
9b6b4fd
 
 
2859ad6
 
 
 
 
9b6b4fd
2859ad6
 
9b6b4fd
 
 
2859ad6
9b6b4fd
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
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()