Spaces:
Sleeping
Sleeping
Download preload.py from vigneshwark/focusflow-api: direct link, hf CLI and curl.
- Browser
- Download file 816 Bytes
-
https://huggingface.co/spaces/vigneshwark/focusflow-api/resolve/main/preload.py
- Command line
-
hf download hf://spaces/vigneshwark/focusflow-api/preload.py
-
curl -L -o preload.py https://huggingface.co/spaces/vigneshwark/focusflow-api/resolve/main/preload.py
816 Bytes
| import os | |
| os.environ["HF_HOME"] = os.path.join(os.getcwd(), "model_cache") | |
| from sentence_transformers import SentenceTransformer | |
| from transformers import pipeline | |
| from faster_whisper import WhisperModel | |
| def preload_models(): | |
| print("Downloading models during build phase to prevent Render timeout...") | |
| print("1/3 Loading SentenceTransformer...") | |
| SentenceTransformer("all-MiniLM-L6-v2") | |
| print("2/3 Loading Zero-Shot Classifier...") | |
| pipeline("text-classification", model="typeform/distilbert-base-uncased-mnli", device=-1) | |
| print("3/3 Loading Whisper Model...") | |
| # faster-whisper saves to the HF cache by default | |
| WhisperModel("base.en", device="cpu", compute_type="int8") | |
| print("All models successfully cached!") | |
| if __name__ == "__main__": | |
| preload_models() | |