Spaces:
Sleeping
Sleeping
Download utils/model_loader.py from Ray1ee01/ChartPipeline: direct link, hf CLI and curl.
- Browser
- Download file 948 Bytes
-
https://huggingface.co/spaces/Ray1ee01/ChartPipeline/resolve/main/utils/model_loader.py
- Command line
-
hf download hf://spaces/Ray1ee01/ChartPipeline/utils/model_loader.py
-
curl -L -o model_loader.py https://huggingface.co/spaces/Ray1ee01/ChartPipeline/resolve/main/utils/model_loader.py
948 Bytes
| from sentence_transformers import SentenceTransformer | |
| from typing import Optional | |
| class ModelLoader: | |
| _instance = None | |
| _model = None | |
| def __new__(cls): | |
| if cls._instance is None: | |
| cls._instance = super(ModelLoader, cls).__new__(cls) | |
| return cls._instance | |
| def get_model(cls, model_path: Optional[str] = None) -> SentenceTransformer: | |
| """ | |
| Get the SentenceTransformer model instance. If it hasn't been loaded yet, | |
| load it with the provided model path. | |
| Args: | |
| model_path: Path to the model. If None, use default model. | |
| Returns: | |
| SentenceTransformer instance | |
| """ | |
| if cls._model is None: | |
| if model_path: | |
| cls._model = SentenceTransformer(model_path) | |
| else: | |
| cls._model = SentenceTransformer("all-MiniLM-L6-v2") | |
| return cls._model |