#!/usr/bin/env python3 """ Local runner for DOCX to PDF converter with Arabic support Run this script to test the converter locally before deploying to Hugging Face Spaces """ import subprocess import sys import os from pathlib import Path def check_system_requirements(): """Check if all system requirements are installed""" print("šŸ” Checking system requirements...") requirements = { "LibreOffice": ["libreoffice", "--version"], "Font Cache": ["fc-cache", "--version"], "Font List": ["fc-list", "--help"] } missing = [] for name, cmd in requirements.items(): try: result = subprocess.run(cmd, capture_output=True, timeout=5) if result.returncode == 0: print(f"āœ… {name}: Available") else: print(f"āŒ {name}: Not working properly") missing.append(name) except (subprocess.TimeoutExpired, FileNotFoundError): print(f"āŒ {name}: Not found") missing.append(name) if missing: print(f"\nāš ļø Missing requirements: {', '.join(missing)}") print("\nTo install on Ubuntu/Debian:") print("sudo apt-get update") print("sudo apt-get install libreoffice libreoffice-writer fonts-liberation fonts-dejavu fonts-noto fontconfig") return False print("āœ… All system requirements are available") return True def install_python_requirements(): """Install Python requirements""" print("\nšŸ“¦ Installing Python requirements...") try: subprocess.run([sys.executable, "-m", "pip", "install", "-r", "requirements.txt"], check=True) print("āœ… Python requirements installed successfully") return True except subprocess.CalledProcessError as e: print(f"āŒ Failed to install Python requirements: {e}") return False def setup_arabic_fonts(): """Setup Arabic fonts if the script exists""" script_path = Path("arabic_fonts_setup.sh") if script_path.exists(): print("\nšŸ”¤ Setting up Arabic fonts...") try: # Make script executable os.chmod(script_path, 0o755) subprocess.run(["bash", str(script_path)], check=True) print("āœ… Arabic fonts setup completed") return True except subprocess.CalledProcessError as e: print(f"āš ļø Arabic fonts setup failed: {e}") print("Continuing without additional Arabic fonts...") return False else: print("āš ļø Arabic fonts setup script not found, skipping...") return False def run_app(): """Run the main application""" print("\nšŸš€ Starting DOCX to PDF converter...") print("The application will be available at: http://localhost:7860") print("Press Ctrl+C to stop the application") try: subprocess.run([sys.executable, "app.py"], check=True) except KeyboardInterrupt: print("\nšŸ‘‹ Application stopped by user") except subprocess.CalledProcessError as e: print(f"āŒ Application failed to start: {e}") def main(): """Main function""" print("šŸ”§ DOCX to PDF Converter - Local Setup") print("=" * 50) # Check system requirements if not check_system_requirements(): print("\nāŒ System requirements not met. Please install missing components.") return 1 # Install Python requirements if not install_python_requirements(): print("\nāŒ Failed to install Python requirements.") return 1 # Setup Arabic fonts (optional) setup_arabic_fonts() # Run the application run_app() return 0 if __name__ == "__main__": sys.exit(main())