#!/usr/bin/env python3 """ Pre-install Argos Translate models to avoid runtime delays. """ import sys import argostranslate.package import argostranslate.translate def main(): print("Updating Argos package index...") try: argostranslate.package.update_package_index() available_packages = argostranslate.package.get_available_packages() target_codes = ['en', 'es', 'fr', 'de', 'it', 'pt', 'sw', 'zh', 'hi'] installed = 0 for from_code in target_codes: for to_code in target_codes: if from_code == to_code: continue pkg = next( (p for p in available_packages if p.from_code == from_code and p.to_code == to_code), None ) if pkg: try: download_path = pkg.download() argostranslate.package.install_from_path(download_path) installed += 1 print(f'✓ Installed {from_code} → {to_code}') except Exception as e: print(f'✗ Failed {from_code} → {to_code}: {str(e)[:80]}') print(f'\nTotal models installed: {installed}') installed_langs = argostranslate.translate.get_installed_languages() print(f'Available languages: {", ".join([lang.code for lang in installed_langs])}') except Exception as e: print(f"Argos installation failed: {e}", file=sys.stderr) sys.exit(1) if __name__ == "__main__": main()