#!/usr/bin/env python3 """ Startup script for PDF Comparison Tool """ import os import sys import subprocess import webbrowser import time from pathlib import Path def check_python_version(): """Check if Python version is compatible""" if sys.version_info < (3, 7): print("❌ Python 3.7 or higher is required") print(f"Current version: {sys.version}") return False print(f"✅ Python {sys.version.split()[0]} is compatible") return True def check_dependencies(): """Check if required dependencies are installed""" try: import flask import cv2 import numpy import PIL import pytesseract import pdf2image import pyzbar import spellchecker import nltk import skimage print("✅ All Python dependencies are installed") return True except ImportError as e: print(f"❌ Missing dependency: {e}") print("Please run: pip install -r requirements.txt") return False def check_tesseract(): """Check if Tesseract OCR is installed""" try: import pytesseract pytesseract.get_tesseract_version() print("✅ Tesseract OCR is available") return True except Exception as e: print(f"❌ Tesseract OCR not found: {e}") print("Please install Tesseract:") print(" macOS: brew install tesseract") print(" Ubuntu: sudo apt-get install tesseract-ocr") print(" Windows: Download from https://github.com/UB-Mannheim/tesseract/wiki") return False def create_directories(): """Create necessary directories""" directories = ['uploads', 'results', 'static/results'] for directory in directories: Path(directory).mkdir(parents=True, exist_ok=True) print("✅ Directories created") def start_application(): """Start the Flask application""" print("\n🚀 Starting PDF Comparison Tool...") print("📱 The application will be available at: http://localhost:5000") print("⏹️ Press Ctrl+C to stop the application") print("-" * 50) try: # Start the Flask app from app import app app.run(debug=True, host='0.0.0.0', port=5000) except KeyboardInterrupt: print("\n👋 Application stopped by user") except Exception as e: print(f"❌ Error starting application: {e}") return False return True def main(): """Main startup function""" print("=" * 50) print("📄 PDF Comparison Tool") print("=" * 50) # Check requirements if not check_python_version(): sys.exit(1) if not check_dependencies(): sys.exit(1) if not check_tesseract(): sys.exit(1) # Create directories create_directories() # Ask user if they want to open browser try: response = input("\n🌐 Open browser automatically? (y/n): ").lower().strip() if response in ['y', 'yes']: # Wait a moment for the server to start def open_browser(): time.sleep(2) webbrowser.open('http://localhost:5000') import threading browser_thread = threading.Thread(target=open_browser) browser_thread.daemon = True browser_thread.start() except KeyboardInterrupt: print("\n👋 Setup cancelled by user") sys.exit(0) # Start the application start_application() if __name__ == "__main__": main()