Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions medcat-den/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ root = ".."
tag_regex = "^medcat-den/v(?P<version>[0-9]+(?:\\.[0-9]+)*)$"
version_scheme = "guess-next-dev"
local_scheme = "no-local-version"
git_describe_command = "git describe --dirty --tags --long --match 'medcat-den/v*'"

[tool.setuptools]
package-dir = {"" = "src"}
Expand Down
17 changes: 14 additions & 3 deletions medcat-den/src/medcat_den/cache/local_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from io import BytesIO

import shutil
from tempfile import TemporaryDirectory

from diskcache import Cache

Expand Down Expand Up @@ -114,7 +115,9 @@ def push_wrapper(cat_path: str, description: str) -> None:
# and then cache it locally
base_name = os.path.basename(cat_path)
model_hash = base_name.removesuffix(".zip")
self[model_hash] = cat_path
with open(cat_path, "rb") as f:
model_bytes = f.read()
self.insert_raw(model_hash, model_bytes)

den._push_model_from_file = push_wrapper # type: ignore
# wrap fetch_model to check cache first
Expand All @@ -128,8 +131,16 @@ def fetch_wrapper(model_info: ModelInfo) -> CATWrapper:
model_path, model_info=model_info))
cat = orig_fetch(model_info)
# cache it
model_path = f"{model_hash}.zip"
self[model_hash] = model_path
with TemporaryDirectory() as tmpdir:
model_path = cat.save_model_pack(
tmpdir,
pack_name=model_hash,
add_hash_to_pack_name=False,
force_save_local=True
) + ".zip"
with open(model_path, "rb") as f:
model_bytes = f.read()
self.insert_raw(model_hash, model_bytes)
return cat

den.fetch_model = fetch_wrapper # type: ignore
Expand Down
Loading