CoolFace
Apppublic

NeuralInternet/Audio-to-Text_Advanced_Playground

sourceHugging Faceapache-2.0updated 4y agoView on Hugging Face
0likes
modelCache.py17 linesDownload Raw Back to src
1class ModelCache:2    def __init__(self):3        self._cache = dict()4 5    def get(self, model_key: str, model_factory):6        result = self._cache.get(model_key)7 8        if result is None:9            result = model_factory()10            self._cache[model_key] = result11        return result12 13    def clear(self):14        self._cache.clear()15 16# A global cache of models. This is mainly used by the daemon processes to avoid loading the same model multiple times.17GLOBAL_MODEL_CACHE = ModelCache()