Add handling for non-existent or empty model file paths in compute_model_hash() method

This commit is contained in:
Sergey Krashevich 2023-04-26 04:11:28 +03:00
parent 17e8a46c7d
commit bebb22dc11
No known key found for this signature in database
GPG Key ID: 625171324E7D3856

View File

@ -118,11 +118,15 @@ class ModelConfig(BaseModel):
} }
def compute_model_hash(self) -> None: def compute_model_hash(self) -> None:
with open(self.path, "rb") as f: if not self.path or not os.path.exists(self.path):
file_hash = hashlib.md5() print("File does not exist or path is empty.")
while chunk := f.read(8192): self._model_hash = hashlib.md5(b"unknown").hexdigest()
file_hash.update(chunk) else:
self._model_hash = file_hash.hexdigest() with open(self.path, "rb") as f:
file_hash = hashlib.md5()
while chunk := f.read(8192):
file_hash.update(chunk)
self._model_hash = file_hash.hexdigest()
def create_colormap(self, enabled_labels: set[str]) -> None: def create_colormap(self, enabled_labels: set[str]) -> None:
"""Get a list of colors for enabled labels.""" """Get a list of colors for enabled labels."""