File size: 2,952 Bytes
3bb7d92 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
#!/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() |