piitag 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- piitag/__init__.py +5 -0
- piitag/_assets.py +67 -0
- piitag/_deterministic.py +1009 -0
- piitag/_head.py +86 -0
- piitag/_labels.py +1 -0
- piitag/_pipeline.py +659 -0
- piitag/_tokenizer.py +142 -0
- piitag/_utf16.py +80 -0
- piitag/cli.py +85 -0
- piitag/model.py +363 -0
- piitag/py.typed +0 -0
- piitag-0.1.0.dist-info/METADATA +152 -0
- piitag-0.1.0.dist-info/RECORD +17 -0
- piitag-0.1.0.dist-info/WHEEL +4 -0
- piitag-0.1.0.dist-info/entry_points.txt +2 -0
- piitag-0.1.0.dist-info/licenses/LICENSE.md +21 -0
- piitag-0.1.0.dist-info/licenses/NOTICE.md +10 -0
piitag/__init__.py
ADDED
piitag/_assets.py
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"""Resolve the pinned Redact model assets."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from dataclasses import dataclass
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
|
|
8
|
+
from huggingface_hub import hf_hub_download
|
|
9
|
+
|
|
10
|
+
REPOSITORY = "desert-ant-labs/redact"
|
|
11
|
+
REVISION = "v0.4.0"
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
@dataclass(frozen=True)
|
|
15
|
+
class Assets:
|
|
16
|
+
"""Paths to the files required by the Redact model."""
|
|
17
|
+
|
|
18
|
+
tokenizer: Path
|
|
19
|
+
labels: Path
|
|
20
|
+
tflite: Path
|
|
21
|
+
|
|
22
|
+
@property
|
|
23
|
+
def directory(self) -> Path:
|
|
24
|
+
"""Return the common directory when all assets share one."""
|
|
25
|
+
return self.tokenizer.parent
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
ASSET_FILENAMES = {
|
|
29
|
+
"tokenizer": "redact_tokenizer.bin",
|
|
30
|
+
"labels": "labels.json",
|
|
31
|
+
"tflite": "redact.tflite",
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def _from_directory(directory: Path) -> Assets:
|
|
36
|
+
paths = {name: directory / filename for name, filename in ASSET_FILENAMES.items()}
|
|
37
|
+
missing = [str(path) for path in paths.values() if not path.is_file()]
|
|
38
|
+
if missing:
|
|
39
|
+
raise FileNotFoundError(
|
|
40
|
+
"Redact model assets are missing from the supplied directory: "
|
|
41
|
+
+ ", ".join(missing)
|
|
42
|
+
)
|
|
43
|
+
return Assets(**paths)
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def resolve_assets(directory: str | Path | None = None) -> Assets:
|
|
47
|
+
"""Resolve local assets or download the pinned files into the HF cache.
|
|
48
|
+
|
|
49
|
+
A supplied directory is strictly offline: it must already contain all
|
|
50
|
+
three files. Without a directory, ``huggingface_hub`` manages the cache.
|
|
51
|
+
"""
|
|
52
|
+
if directory is not None:
|
|
53
|
+
return _from_directory(Path(directory))
|
|
54
|
+
downloaded = {
|
|
55
|
+
name: Path(
|
|
56
|
+
hf_hub_download(
|
|
57
|
+
repo_id=REPOSITORY,
|
|
58
|
+
filename=filename,
|
|
59
|
+
revision=REVISION,
|
|
60
|
+
)
|
|
61
|
+
)
|
|
62
|
+
for name, filename in ASSET_FILENAMES.items()
|
|
63
|
+
}
|
|
64
|
+
return Assets(**downloaded)
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
__all__ = ["ASSET_FILENAMES", "Assets", "resolve_assets"]
|