Spaces:
Sleeping
Sleeping
File size: 1,357 Bytes
bb07fca | 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 | import os
import sys
import subprocess
# Force installation of Tesseract at runtime
def install_tesseract():
print("Installing Tesseract OCR...")
try:
# Update repositories
subprocess.run(['apt-get', 'update'], check=True)
# Install Tesseract and dependencies
subprocess.run(['apt-get', 'install', '-y', 'tesseract-ocr', 'libtesseract-dev',
'tesseract-ocr-eng', 'poppler-utils'], check=True)
print("Tesseract OCR installation complete.")
return True
except Exception as e:
print(f"Error installing Tesseract: {str(e)}")
return False
# Check if Tesseract is installed
def is_tesseract_installed():
try:
result = subprocess.run(['tesseract', '--version'],
capture_output=True, text=True, check=True)
print(f"Tesseract is installed: {result.stdout.strip()}")
return True
except Exception:
return False
# Main entry point
if __name__ == "__main__":
# Check if Tesseract is installed
if not is_tesseract_installed():
# Try to install it
if install_tesseract():
print("Tesseract installed successfully.")
else:
print("Failed to install Tesseract. Continuing anyway...")
# Run the main app
import app
app.app.launch() |