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()