#!/usr/bin/env python3 """ Setup script for Document Translator """ import os import sys import subprocess from pathlib import Path def install_requirements(): """Install Python requirements""" print("📦 Installing Python requirements...") try: subprocess.check_call([sys.executable, "-m", "pip", "install", "-r", "requirements.txt"]) print("✅ Requirements installed successfully") except subprocess.CalledProcessError as e: print(f"❌ Failed to install requirements: {e}") return False return True def check_libreoffice(): """Check if LibreOffice is installed""" print("🔍 Checking LibreOffice installation...") try: result = subprocess.run(["libreoffice", "--version"], capture_output=True, text=True, timeout=10) if result.returncode == 0: print(f"✅ LibreOffice found: {result.stdout.strip()}") return True else: print("❌ LibreOffice not working properly") return False except FileNotFoundError: print("❌ LibreOffice not found") print("Please install LibreOffice:") print(" - Windows: Download from https://www.libreoffice.org/") print(" - macOS: brew install --cask libreoffice") print(" - Ubuntu/Debian: sudo apt-get install libreoffice") return False except Exception as e: print(f"❌ Error checking LibreOffice: {e}") return False def check_api_key(): """Check if OpenRouter API key is set""" print("🔑 Checking OpenRouter API key...") api_key = os.getenv('OPENROUTER_API_KEY') if api_key: print(f"✅ API key found (length: {len(api_key)})") return True else: print("⚠️ OpenRouter API key not found") print("Please set it: export OPENROUTER_API_KEY='your_key_here'") return False def create_directories(): """Create necessary directories""" print("📁 Creating directories...") directories = ['uploads', 'web'] for dir_name in directories: Path(dir_name).mkdir(exist_ok=True) print(f"✅ Created/verified {dir_name} directory") def main(): """Main setup function""" print("🚀 Setting up Document Translator...") print("=" * 50) success = True # Create directories create_directories() # Install requirements if not install_requirements(): success = False # Check LibreOffice if not check_libreoffice(): success = False # Check API key check_api_key() # Warning only, not failure print("=" * 50) if success: print("🎉 Setup completed successfully!") print("Run: python app.py") print("Then open: http://localhost:7860") else: print("❌ Setup failed. Please fix the issues above.") sys.exit(1) if __name__ == "__main__": main()