// VALIDACIÓN DE SEGURIDAD - Lovable debe implementar esto function validateHFOnly(endpoint) { const allowedDomains = [ 'api-inference.huggingface.co', 'huggingface.co' ]; const url = new URL(endpoint); if (!allowedDomains.includes(url.hostname)) { throw new Error('BLOQUEO: Intento de usar plataforma no autorizada'); } } // USO EN TODAS LAS LLAMADAS async function secureHFRequest(model, payload) { const endpoint = `/static-proxy?url=https%3A%2F%2Fapi-inference.huggingface.co%2Fmodels%2F%24%7Bmodel%7D%60%3B validateHFOnly(endpoint); // Bloquea si no es HF // Proceder con la solicitud... }// MODELOS PERMITIDOS - LISTA BLANCA const ALLOWED_MODELS = { chat: ['gpt2', 'gpt2-medium', 'gpt2-large', 'gpt2-xl'], image: [ 'black-forest-labs/FLUX.1-dev', 'black-forest-labs/FLUX.1-schnell', 'black-forest-labs/FLUX.1-schnell-4bit' ] };function isHuggingFaceEndpoint(url) { return url.includes('huggingface.co') && !url.includes('replicate') && !url.includes('openai') && !url.includes('stability'); "Error: Solo usamos Hugging Face.""Modelos actuales: FLUX.1-dev, FLUX.1-schnell, FLUX.1-schnell-4bit" Todos gratuitos con tu token de HF."Usuario: "Genera un paisaje" → GTP-FLUX-BAT detecta necesidad de imagen → SOLO consulta modelos HF de la lista blanca → Si falla FLUX.1-dev, intenta FLUX.1-schnell → Si falla FLUX.1-schnell, intenta FLUX.1-schnell-4bit → Si todos fallan: "Hugging Face no disponible, intenta más tarde" → NUNCA: "Usando DALL-E..." o "Conectando a Replicate...""Crear un chatbot llamado 'GTP-FLUX-BAT' que integre conversación natural con generación automática de imágenes usando EXCLUSIVAMENTE modelos gratuitos de Hugging Face. BLOQUEO ABSOLUTO: NO usar APIs de pago, NO usar Replicate, NO usar OpenAI, NO usar Stability AI directo, SOLO Hugging Face Inference API. ARQUITECTURA TÉCNICA: 1. **MOTOR DE CHAT (Hugging Face):** - Modelo: 'gpt2-large' de Hugging Face - Endpoint: /static-proxy?url=https%3A%2F%2Fapi-inference.huggingface.co%2Fmodels%2Fgpt2-large 2. **MOTORES DE IMAGEN (Hugging Face EXCLUSIVO):** - PRIMARIO: 'black-forest-labs/FLUX.1-dev' - SECUNDARIO: 'black-forest-labs/FLUX.1-schnell' - TERCIARIO: 'black-forest-labs/FLUX.1-schnell-4bit' - Endpoint: /static-proxy?url=https%3A%2F%2Fapi-inference.huggingface.co%2Fmodels%2F%5BMODELO%5D 3. **LÓGICA DE GENERACIÓN BLOQUEADA:** - SOLO usar Hugging Face Inference API - NUNCA redirigir a otras plataformas - Si un modelo falla, intentar el siguiente modelo de HF - MOSTRAR ERROR si todos los modelos de HF fallan CÓDIGO DE IMPLEMENTACIÓN: const HF_CHAT_MODEL = 'gpt2-large'; const HF_IMAGE_MODELS = [ 'black-forest-labs/FLUX.1-dev', 'black-forest-labs/FLUX.1-schnell', 'black-forest-labs/FLUX.1-schnell-4bit' ]; // SOLO Hugging Face - BLOQUEAR otras APIs async function generateImageHFOnly(prompt) { for (const model of HF_IMAGE_MODELS) { try { const response = await fetch( `/static-proxy?url=https%3A%2F%2Fapi-inference.huggingface.co%2Fmodels%2F%24%7Bmodel%7D%60%2C { method: 'POST', headers: { 'Authorization': `Bearer ${process.env.HF_TOKEN}`, 'Content-Type': 'application/json' }, body: JSON.stringify({ inputs: prompt, parameters: { num_inference_steps: 20, guidance_scale: 7.5, width: 1024, height: 1024 } }) } ); if (response.ok) { return await response.blob(); } } catch (error) { continue; // Intentar siguiente modelo de HF } } throw new Error('Todos los modelos de Hugging Face están temporalmente no disponibles'); } INTERFAZ Y FLUJO: - Chat conversacional natural - Detección automática de solicitudes de imágenes - Generación con modelos HF sin interacción del usuario - Mensajes de error específicos: 'Servicio Hugging Face no disponible' - Diseño unificado donde imágenes aparecen en la conversación VALIDACIÓN DE IMPLEMENTACIÓN: - Verificar que TODAS las llamadas sean a 'api-inference.huggingface.co' - Confirmar que los modelos sean EXACTAMENTE los especificados - Rechazar cualquier alternativa de pago o otras plataformas - Usar SOLO el token de Hugging Face para autenticación PALABRAS CLAVE BLOQUEADAS: NO 'replicate', NO 'openai', NO 'stabilityai', NO 'midjourney', NO 'dall-e', NO 'commercial API', SOLO 'huggingface', SOLO 'inference API' ESTE SISTEMA DEBE SER 100% GRATUITO USANDO EXCLUSIVAMENTE HUGGING FACE."