From 38f0986aadebb7a6c79a4002b1fb7beecc068977 Mon Sep 17 00:00:00 2001 From: Lizandro Date: Tue, 11 Aug 2026 00:42:37 +0000 Subject: [PATCH] fix: probar OCR con imagen que tiene texto real, no pixel en blanco MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Un pixel 1x1 transparente siempre da "sin_texto_detectado" aunque el servicio funcione perfecto, mostrando un falso ❌. Ahora manda un PNG con texto renderizado y distingue 3 casos: conectado y leyo texto (✅), conectado pero no reconocio nada (⚠️, indica problema real del OCR), y no se pudo conectar (❌). Co-Authored-By: Claude Sonnet 5 --- .../Livewire/Chat/ShowConfiguracionChat.php | 27 ++++++++++++------- .../chat/show-configuracion-chat.blade.php | 2 +- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/app/Http/Livewire/Chat/ShowConfiguracionChat.php b/app/Http/Livewire/Chat/ShowConfiguracionChat.php index 077534c..3663c40 100755 --- a/app/Http/Livewire/Chat/ShowConfiguracionChat.php +++ b/app/Http/Livewire/Chat/ShowConfiguracionChat.php @@ -190,26 +190,35 @@ class ShowConfiguracionChat extends Component return; } - // 1x1 png transparente, solo para verificar que el servicio responde. - $pixel = base64_decode('iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNk+A8AAQUBAScY42YAAAAASUVORK5CYII='); + // PNG 240x80 con el texto "TEST OCR 123" renderizado, para que la prueba + // sea real: un pixel en blanco siempre da "sin_texto_detectado" aunque + // todo funcione bien. + $imagenPrueba = 'iVBORw0KGgoAAAANSUhEUgAAAPAAAABQCAIAAACoK28rAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAB6ElEQVR4nO3c3W6iUBhA0WHS939l5sLENPxpPRCd3bXuWgSPZVc/MXGa5/kPVPx99wLgTIImRdCkCJoUQZMiaFIETYqgSRE0KYImRdCkCJoUQZMiaFIETYqgSRE0KYImRdCkCJoUQZMiaFIETYqgSRE0KYImRdCkCJoUQZMiaFIETYqgSfka2Xmaps3fz/O8uen+5errrbdNBwf80WIWt18c9uC+nv/699vu69vvLWNzDZxuOuUvuz67e+f7yRsf7P5wAYt9934cudN7nZv/OetlHC+JE33EyDHP88jZXfTxvaF1OuMZ7b2MHCxj8QCPX44YMTRy/KcGm97LcXxcYdy1QW8OlLeX+w+ZKa9bxma1e7MKZ7k26L3Ttj7N03TONP+yc+997zn4/uz+9sdb9REz9Bvdp9sTJ9qHE4UZ+jq/MeifXjR84eCefd/lDUGvB+hBixy/J7Uu9fhS9+DCDi5Or9cg+itcex164eEHKwcHfHINB0dbbH35OvRrnwp9yJvgPG9NSPmNMzRhgiZF0KQImhRBkyJoUgRNiqBJETQpgiZF0KQImhRBkyJoUgRNiqBJETQpgiZF0KQImhRBkyJoUgRNiqBJETQpgiZF0KQImhRBkyJoUgRNiqBJETQpgiZF0KQImpR/3UrzkDoP+sMAAAAASUVORK5CYII='; try { $inicio = microtime(true); $response = Http::withToken($token) ->timeout(15) ->post("{$url}/extract", [ - 'image_base64' => base64_encode($pixel), + 'image_base64' => $imagenPrueba, 'mime_type' => 'image/png', ]); - $ms = (int) ((microtime(true) - $inicio) * 1000); + $ms = (int) ((microtime(true) - $inicio) * 1000); + $data = $response->json(); - if ($response->successful()) { - $this->ocrResult = "✅ Servicio OCR responde OK ({$ms}ms). " . - "Respuesta: " . substr($response->body(), 0, 200); - } else { - $this->ocrResult = "❌ El servicio respondió con error " . $response->status() . ": " . + if ($data === null) { + // No respondio JSON valido: la conexion en si fallo (ruta mal, host caido, etc). + $this->ocrResult = "❌ El servicio respondió HTTP " . $response->status() . " sin JSON válido: " . substr($response->body(), 0, 200); + } elseif ($data['success'] ?? false) { + $texto = $data['text'] ?? ''; + $this->ocrResult = "✅ Servicio OCR responde OK ({$ms}ms). Texto reconocido: \"" . substr($texto, 0, 150) . "\""; + } else { + // Respondio con JSON estructurado pero success=false: SI esta conectado, + // solo que no reconocio el texto de la imagen de prueba. + $this->ocrResult = "⚠️ El servicio conectó pero no reconoció el texto de prueba (HTTP {$response->status()}): " . + ($data['error'] ?? 'sin detalle'); } } catch (\Throwable $e) { $this->ocrResult = '❌ No se pudo conectar con el servicio OCR: ' . $e->getMessage(); diff --git a/resources/views/livewire/chat/show-configuracion-chat.blade.php b/resources/views/livewire/chat/show-configuracion-chat.blade.php index 33d0d50..00d5d0f 100755 --- a/resources/views/livewire/chat/show-configuracion-chat.blade.php +++ b/resources/views/livewire/chat/show-configuracion-chat.blade.php @@ -182,7 +182,7 @@ Probando... @if($ocrResult) -

+

{{ $ocrResult }}

@endif