File size: 4,509 Bytes
8c83b25 57239cb 8c83b25 |
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 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
// 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." |