File size: 4,313 Bytes
9b6b4fd
 
bf6e5b1
 
 
 
 
bbb926c
 
 
 
 
bf6e5b1
90557f1
9b6b4fd
bbb926c
 
9b6b4fd
 
 
bbb926c
9b6b4fd
 
 
 
 
 
bbb926c
9b6b4fd
 
 
 
90557f1
05072e0
 
 
 
90557f1
bbb926c
 
05072e0
 
 
 
 
bbb926c
 
 
 
 
 
 
 
d91b1eb
 
5dea26e
 
d91b1eb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9b6b4fd
bbb926c
 
 
9b6b4fd
 
 
bbb926c
d91b1eb
6c4d2de
bbb926c
 
d91b1eb
5dea26e
bbb926c
d91b1eb
bbb926c
 
 
9b6b4fd
 
 
bbb926c
 
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
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")

# Verifica si la clave de API está configurada
if not api_key:
    raise ValueError("Falta la clave de API de Anthropoid. Asegúrate de configurarla en los secretos del repositorio.")

# Configura el cliente de la API de Claude (Anthropic)
client = anthropic.Anthropic(api_key=api_key)

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."
                    }
                ]
            }
        ]
    )
    
    # Extrae el contenido de texto limpio
    content = message.content
    return content

# Configura la interfaz de usuario con Gradio
def gradio_generate_headlines(number_of_headlines, target_audience, product):
    # Obtiene el texto limpio de los titulares generados
    result = generate_headlines(number_of_headlines, target_audience, product)
    
    # Formatea el texto para que aparezca como Markdown
    return f"Estos son los {number_of_headlines} titulares atractivos diseñados específicamente para el público objetivo que describiste:\n\n{result}"

# 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"] + """; }
    .input-col, .result-col { display: flex; flex-direction: column; }
    .result-col { align-items: flex-end; }
    @media (max-width: 768px) {
        .gradio-column {
            width: 100% !important;
            margin-bottom: 20px;
        }
    }
    @media (min-width: 769px) {
        .gradio-row {
            display: flex;
            flex-wrap: wrap;
        }
        .gradio-column {
            flex: 1;
            padding: 10px;
        }
    }
    """) 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(scale=2, elem_id="input-col"):
            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")
        
        with gr.Column(scale=1, elem_id="result-col"):
            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()