testingfaces commited on
Commit
5aaae7e
Β·
verified Β·
1 Parent(s): 6322e69

Update translator.py

Browse files
Files changed (1) hide show
  1. translator.py +5 -21
translator.py CHANGED
@@ -86,27 +86,11 @@ class Translator:
86
  self._tokenizer = None
87
  self._model = None
88
  self._nllb_loaded = False
89
- print("[Translator] Ready β€” pre-loading Telugu + Hindi in background...")
90
-
91
- # Pre-load most common models at startup in background thread
92
- threading.Thread(target=self._preload_common_models, daemon=True).start()
93
-
94
- def _preload_common_models(self):
95
- """Pre-load Telugu and Hindi models at startup (background)."""
96
- time.sleep(5) # wait for space to fully start first
97
- preload = [
98
- ("en", "te"), # English β†’ Telugu (most common)
99
- ("en", "hi"), # English β†’ Hindi
100
- ]
101
- for src, tgt in preload:
102
- try:
103
- model_id = HELSINKI_MODELS.get((src, tgt))
104
- if model_id:
105
- print(f"[Translator] Pre-loading {src}β†’{tgt} ({model_id})...")
106
- self._load_helsinki(model_id)
107
- print(f"[Translator] βœ… {src}β†’{tgt} pre-loaded and ready!")
108
- except Exception as e:
109
- print(f"[Translator] Pre-load {src}β†’{tgt} failed: {e}")
110
 
111
  # ══════════════════════════════════════════════════════════════════
112
  # PUBLIC β€” TRANSLATE
 
86
  self._tokenizer = None
87
  self._model = None
88
  self._nllb_loaded = False
89
+ # STARTUP FIX: Removed background preload thread.
90
+ # It was downloading ~600MB of Helsinki-NLP models at container startup,
91
+ # causing HuggingFace Spaces to hang on the health check and never boot.
92
+ # Models are now lazy-loaded on first translate() call instead.
93
+ print("[Translator] Ready β€” models load on first use")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
94
 
95
  # ══════════════════════════════════════════════════════════════════
96
  # PUBLIC β€” TRANSLATE