Spaces:
Runtime error
Runtime error
Download models/model_loader.py from Chittrarasu/embedding_FastAPI: direct link, hf CLI and curl.
- Browser
- Download file 725 Bytes
-
https://huggingface.co/spaces/Chittrarasu/embedding_FastAPI/resolve/81c61890ea66034eaaa8bc7785b93b09511ba71f/models/model_loader.py
- Command line
-
hf download hf://spaces/Chittrarasu/embedding_FastAPI@81c61890ea66034eaaa8bc7785b93b09511ba71f/models/model_loader.py
-
curl -L -o model_loader.py https://huggingface.co/spaces/Chittrarasu/embedding_FastAPI/resolve/81c61890ea66034eaaa8bc7785b93b09511ba71f/models/model_loader.py
725 Bytes
| from sentence_transformers import SentenceTransformer | |
| import os | |
| from huggingface_hub import login | |
| # Get the token from environment variable | |
| hf_token = os.getenv('HF_TOKEN') | |
| # Model path and Hugging Face model ID | |
| model_dir = '/tmp/sentence_transformer' | |
| hf_model_id = 'Alibaba-NLP/gte-base-en-v1.5' | |
| # Authenticate with Hugging Face | |
| login(token=hf_token) | |
| # Check if model directory exists | |
| if not os.path.exists(model_dir): | |
| print(f"Downloading model '{hf_model_id}' from Hugging Face...") | |
| model = SentenceTransformer(hf_model_id, use_auth_token=hf_token, trust_remote_code=True) | |
| model.save(model_dir) | |
| else: | |
| print(f"Loading model from local directory: {model_dir}") | |
| model = SentenceTransformer(model_dir) | |