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, temperature): # Llama a la API de Claude para generar titulares message = client.messages.create( model="claude-3-5-sonnet-20240620", max_tokens=1000, # Configurado a 1000 tokens temperature=temperature, # Usa el valor del slider aquí 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.", 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, temperature): return generate_headlines(number_of_headlines, target_audience, product, temperature) ifaces = gr.Interface( fn=gradio_generate_headlines, inputs=[ gr.Dropdown(choices=[str(i) for i in range(1, 11)], label="Número de Titulares", value="5"), gr.Textbox(label="Público Objetivo", placeholder="Ejemplo: Estudiantes Universitarios"), gr.Textbox(label="Producto", placeholder="Ejemplo: Curso de Inglés"), gr.Slider(minimum=0, maximum=1, value=0, step=0.1, label="Creatividad") ], outputs=gr.Textbox(label="Titulares Generados", lines=20, placeholder="Los titulares aparecerán aquí..."), title="Generador de Titulares", description="Usa el poder de Claude AI para crear titulares atractivos. Ajusta los parámetros para generar titulares que capturen la atención de tu audiencia." ) # Lanza la interfaz ifaces.launch()