Spaces:
Sleeping
Sleeping
Fix: Remove model download from Docker build to prevent timeout
Browse filesDocker builds on HF Spaces were timing out when trying to download large models.
Solution:
- Removed 'RUN cd backend && python download_models.py' from Dockerfile
- Models now download on first request (lazy loading)
- English models: Downloaded on first voice enrollment/synthesis
- Hindi XTTS: Downloaded on first Hindi synthesis request
This prevents build failures while keeping the app functional.
- Dockerfile +4 -2
- backend/download_models.py +11 -3
Dockerfile
CHANGED
|
@@ -16,8 +16,10 @@ COPY . .
|
|
| 16 |
# Install Python dependencies
|
| 17 |
RUN pip install --no-cache-dir -r backend/requirements.txt
|
| 18 |
|
| 19 |
-
#
|
| 20 |
-
|
|
|
|
|
|
|
| 21 |
|
| 22 |
# Expose port (HF Spaces uses 7860)
|
| 23 |
EXPOSE 7860
|
|
|
|
| 16 |
# Install Python dependencies
|
| 17 |
RUN pip install --no-cache-dir -r backend/requirements.txt
|
| 18 |
|
| 19 |
+
# Note: Models will be downloaded on first request
|
| 20 |
+
# Skipping download_models.py to avoid build timeout on HF Spaces
|
| 21 |
+
# - English models: Downloaded via hf_hub_download on first voice enrollment/synthesis
|
| 22 |
+
# - Hindi XTTS: Downloaded via TTS library on first Hindi synthesis request
|
| 23 |
|
| 24 |
# Expose port (HF Spaces uses 7860)
|
| 25 |
EXPOSE 7860
|
backend/download_models.py
CHANGED
|
@@ -22,6 +22,8 @@ def download_models(models_dir: Path) -> None:
|
|
| 22 |
|
| 23 |
print(f"[Models] Target directory: {target_dir}")
|
| 24 |
|
|
|
|
|
|
|
| 25 |
for filename, (repo_id, repo_filename) in MODEL_SPECS.items():
|
| 26 |
destination = target_dir / filename
|
| 27 |
|
|
@@ -41,10 +43,16 @@ def download_models(models_dir: Path) -> None:
|
|
| 41 |
print(f"✓ Saved {filename} ({size_mb:.1f} MB) to {destination}")
|
| 42 |
except Exception as e:
|
| 43 |
print(f"✗ Failed to download {filename}: {e}")
|
| 44 |
-
|
|
|
|
| 45 |
|
| 46 |
-
|
| 47 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
|
| 49 |
if __name__ == "__main__":
|
| 50 |
backend_dir = Path(__file__).parent
|
|
|
|
| 22 |
|
| 23 |
print(f"[Models] Target directory: {target_dir}")
|
| 24 |
|
| 25 |
+
failed_models = []
|
| 26 |
+
|
| 27 |
for filename, (repo_id, repo_filename) in MODEL_SPECS.items():
|
| 28 |
destination = target_dir / filename
|
| 29 |
|
|
|
|
| 43 |
print(f"✓ Saved {filename} ({size_mb:.1f} MB) to {destination}")
|
| 44 |
except Exception as e:
|
| 45 |
print(f"✗ Failed to download {filename}: {e}")
|
| 46 |
+
failed_models.append(filename)
|
| 47 |
+
print(f" Models will be downloaded on first request")
|
| 48 |
|
| 49 |
+
if failed_models:
|
| 50 |
+
print(f"\n⚠ {len(failed_models)} model(s) failed to download during build")
|
| 51 |
+
print(f" These will be downloaded on first use")
|
| 52 |
+
return False
|
| 53 |
+
else:
|
| 54 |
+
print("[Models] All models downloaded successfully!")
|
| 55 |
+
return True
|
| 56 |
|
| 57 |
if __name__ == "__main__":
|
| 58 |
backend_dir = Path(__file__).parent
|