| import os, sys | |
| # HF Spaces pass the port via PORT | |
| PORT = os.environ.get("PORT", "7860") | |
| # Limit models for faster boot + smaller disk use (tweak as you like) | |
| os.environ.setdefault( | |
| "LT_LOAD_ONLY", | |
| "en,es,fr,de,pt,ru,ar,hi,ja,ko,zh" | |
| ) | |
| # Start LibreTranslate and download/update models on first boot | |
| args = [ | |
| "libretranslate", | |
| "--host", "0.0.0.0", | |
| "--port", str(PORT), | |
| "--update-models" | |
| ] | |
| # Replace this Python process with the LT server (cleaner signals) | |
| os.execvp(args[0], args) | |