Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,9 +2,44 @@
|
|
| 2 |
from app.gradio_app import build_demo
|
| 3 |
from models.tts_router import cleanup_old_audio
|
| 4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
def main():
|
| 6 |
# Clean up old TTS files on boot
|
| 7 |
cleanup_old_audio(keep_latest=None)
|
|
|
|
|
|
|
| 8 |
|
| 9 |
demo = build_demo()
|
| 10 |
# Don’t set server_name/server_port; HF will handle it.
|
|
|
|
| 2 |
from app.gradio_app import build_demo
|
| 3 |
from models.tts_router import cleanup_old_audio
|
| 4 |
|
| 5 |
+
import os
|
| 6 |
+
import huggingface_hub
|
| 7 |
+
|
| 8 |
+
def ensure_model():
|
| 9 |
+
"""
|
| 10 |
+
Downloads the GGUF model into ./models if not already present.
|
| 11 |
+
- LLAMACPP_MODEL_PATH must include the filename.
|
| 12 |
+
- HF_MODEL_REPO must point to the Hugging Face repo.
|
| 13 |
+
"""
|
| 14 |
+
model_path = os.getenv("LLAMACPP_MODEL_PATH")
|
| 15 |
+
repo_id = os.getenv("HF_MODEL_REPO")
|
| 16 |
+
|
| 17 |
+
if not model_path or not repo_id:
|
| 18 |
+
raise RuntimeError("Both LLAMACPP_MODEL_PATH and HF_MODEL_REPO must be set in .env")
|
| 19 |
+
|
| 20 |
+
if os.path.exists(model_path):
|
| 21 |
+
print(f"[MODEL] Found existing model at {model_path}")
|
| 22 |
+
return model_path
|
| 23 |
+
|
| 24 |
+
os.makedirs(os.path.dirname(model_path), exist_ok=True)
|
| 25 |
+
|
| 26 |
+
filename = os.path.basename(model_path)
|
| 27 |
+
|
| 28 |
+
print(f"[MODEL] Downloading {filename} from {repo_id} …")
|
| 29 |
+
local_path = huggingface_hub.hf_hub_download(
|
| 30 |
+
repo_id=repo_id,
|
| 31 |
+
filename=filename,
|
| 32 |
+
local_dir=os.path.dirname(model_path),
|
| 33 |
+
local_dir_use_symlinks=False,
|
| 34 |
+
)
|
| 35 |
+
print(f"[MODEL] Saved at {local_path}")
|
| 36 |
+
return local_path
|
| 37 |
+
|
| 38 |
def main():
|
| 39 |
# Clean up old TTS files on boot
|
| 40 |
cleanup_old_audio(keep_latest=None)
|
| 41 |
+
# dowload model at startup
|
| 42 |
+
ensure_model()
|
| 43 |
|
| 44 |
demo = build_demo()
|
| 45 |
# Don’t set server_name/server_port; HF will handle it.
|