| |
| """ |
| 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() |
| |
| |
| if not install_requirements(): |
| success = False |
| |
| |
| if not check_libreoffice(): |
| success = False |
| |
| |
| check_api_key() |
| |
| 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() |