# Script de Instalación Rápida de OCR # Para ejecutar: .\install_ocr.ps1 Write-Host "========================================" -ForegroundColor Cyan Write-Host "Instalación de OCR para MVE Micro Docs" -ForegroundColor Cyan Write-Host "========================================" -ForegroundColor Cyan Write-Host "" # Verificar si tesseract ya está instalado Write-Host "Verificando si Tesseract está instalado..." -ForegroundColor Yellow $tesseractInstalled = $false try { $version = tesseract --version 2>&1 if ($version -match "tesseract") { Write-Host "✓ Tesseract ya está instalado:" -ForegroundColor Green Write-Host $version[0] -ForegroundColor Gray $tesseractInstalled = $true } } catch { Write-Host "✗ Tesseract no está instalado" -ForegroundColor Red } if (-not $tesseractInstalled) { Write-Host "" Write-Host "Para instalar Tesseract OCR:" -ForegroundColor Yellow Write-Host "1. Visita: https://github.com/UB-Mannheim/tesseract/wiki" -ForegroundColor White Write-Host "2. Descarga tesseract-ocr-w64-setup-5.3.x.exe" -ForegroundColor White Write-Host "3. Durante la instalación, MARCA la opción 'Spanish language data'" -ForegroundColor White Write-Host "4. Agrega C:\Program Files\Tesseract-OCR al PATH del sistema" -ForegroundColor White Write-Host "5. Reinicia PowerShell y ejecuta este script nuevamente" -ForegroundColor White Write-Host "" $openBrowser = Read-Host "¿Abrir el sitio de descarga en el navegador? (S/N)" if ($openBrowser -eq "S" -or $openBrowser -eq "s") { Start-Process "https://github.com/UB-Mannheim/tesseract/wiki" } Write-Host "" Write-Host "Presiona cualquier tecla para continuar después de instalar Tesseract..." $null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown") exit } # Verificar idioma español Write-Host "" Write-Host "Verificando idioma español..." -ForegroundColor Yellow $languages = tesseract --list-langs 2>&1 if ($languages -match "spa") { Write-Host "✓ Paquete de idioma español (spa) instalado" -ForegroundColor Green } else { Write-Host "✗ Paquete de idioma español NO instalado" -ForegroundColor Red Write-Host "Reinstala Tesseract y marca 'Spanish language data' durante la instalación" -ForegroundColor Yellow } # Verificar poppler Write-Host "" Write-Host "Verificando poppler (requerido para convertir PDF a imágenes)..." -ForegroundColor Yellow $popplerInstalled = $false try { $pdfToText = Get-Command pdftoppm -ErrorAction SilentlyContinue if ($pdfToText) { Write-Host "✓ Poppler ya está instalado" -ForegroundColor Green $popplerInstalled = $true } } catch {} if (-not $popplerInstalled) { Write-Host "✗ Poppler no está instalado" -ForegroundColor Red Write-Host "" Write-Host "Para instalar Poppler:" -ForegroundColor Yellow Write-Host "1. Descarga: https://github.com/oschwartz10612/poppler-windows/releases/latest" -ForegroundColor White Write-Host "2. Extrae el ZIP a C:\poppler" -ForegroundColor White Write-Host "3. Agrega C:\poppler\Library\bin al PATH del sistema" -ForegroundColor White Write-Host "" $openBrowser = Read-Host "¿Abrir el sitio de descarga en el navegador? (S/N)" if ($openBrowser -eq "S" -or $openBrowser -eq "s") { Start-Process "https://github.com/oschwartz10612/poppler-windows/releases/latest" } } # Instalar dependencias Python Write-Host "" Write-Host "Instalando dependencias Python..." -ForegroundColor Yellow try { & pip install pytesseract Pillow pdf2image Write-Host "✓ Dependencias Python instaladas correctamente" -ForegroundColor Green } catch { Write-Host "✗ Error al instalar dependencias Python" -ForegroundColor Red Write-Host $_.Exception.Message -ForegroundColor Red } # Verificar archivo .env Write-Host "" Write-Host "Verificando configuración..." -ForegroundColor Yellow if (Test-Path ".env") { Write-Host "✓ Archivo .env existe" -ForegroundColor Green # Verificar si tiene las variables OCR $envContent = Get-Content ".env" -Raw if ($envContent -notmatch "OCR_ENABLED") { Write-Host "! Agregando variables OCR al archivo .env" -ForegroundColor Yellow $ocrConfig = @" # OCR Settings OCR_ENABLED=true OCR_LANGUAGE=spa OCR_DPI=300 OCR_TIMEOUT=300 "@ Add-Content ".env" $ocrConfig Write-Host "✓ Variables OCR agregadas" -ForegroundColor Green } else { Write-Host "✓ Variables OCR ya configuradas" -ForegroundColor Green } } else { Write-Host "! Archivo .env no existe, copiando desde .env.example" -ForegroundColor Yellow Copy-Item ".env.example" ".env" Write-Host "✓ Archivo .env creado - edítalo con tus credenciales" -ForegroundColor Green } # Resumen final Write-Host "" Write-Host "========================================" -ForegroundColor Cyan Write-Host "Resumen de Instalación" -ForegroundColor Cyan Write-Host "========================================" -ForegroundColor Cyan $allGood = $tesseractInstalled -and ($languages -match "spa") if ($allGood) { Write-Host "✓ ¡Todo listo para usar OCR!" -ForegroundColor Green Write-Host "" Write-Host "Para probar:" -ForegroundColor White Write-Host " python -c `"import pytesseract; print('OCR Ready!')`"" -ForegroundColor Gray Write-Host "" Write-Host "Inicia tu servidor:" -ForegroundColor White Write-Host " uvicorn app.main:app --reload" -ForegroundColor Gray } else { Write-Host "⚠ Instalación incompleta" -ForegroundColor Yellow Write-Host "" Write-Host "Componentes faltantes:" -ForegroundColor Yellow if (-not $tesseractInstalled) { Write-Host " - Tesseract OCR" -ForegroundColor Red } if ($languages -notmatch "spa") { Write-Host " - Paquete de idioma español" -ForegroundColor Red } if (-not $popplerInstalled) { Write-Host " - Poppler (opcional pero recomendado)" -ForegroundColor Yellow } Write-Host "" Write-Host "Consulta OCR_SETUP.md para instrucciones detalladas" -ForegroundColor White } Write-Host "" Write-Host "Presiona cualquier tecla para salir..." $null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")