Instructions to use kesha-humonen/runic-reader-2 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- PEFT
How to use kesha-humonen/runic-reader-2 with PEFT:
Task type is invalid.
- Notebooks
- Google Colab
- Kaggle
Download code/doc_filter.py from kesha-humonen/runic-reader-2: direct link, hf CLI and curl.
- Browser
- Download file 1.1 kB
-
https://huggingface.co/kesha-humonen/runic-reader-2/resolve/main/code/doc_filter.py
- Command line
-
hf download hf://kesha-humonen/runic-reader-2/code/doc_filter.py
-
curl -L -o doc_filter.py https://huggingface.co/kesha-humonen/runic-reader-2/resolve/main/code/doc_filter.py
1.1 kB
| """Flag archival cards and document scans among photographs. | |
| Archive cards of the runic archives are mostly blank cream-coloured paper with small pasted | |
| photographs. The feature is the share of warm cream pixels (bright, red and green clearly above | |
| blue) in a downscaled image; neutral white or grey backgrounds of object photographs do not count. | |
| """ | |
| import json | |
| import sys | |
| import numpy as np | |
| from PIL import Image | |
| def cream_share(path): | |
| im = Image.open(path).convert("RGB") | |
| im.draft("RGB", (256, 256)) | |
| im.thumbnail((256, 256)) | |
| a = np.asarray(im).astype(np.float32) | |
| r, g, b = a[..., 0], a[..., 1], a[..., 2] | |
| cream = (r > 195) & (g > 185) & (r - b > 14) & (r - b < 60) & (np.abs(r - g) < 22) | |
| return float(cream.mean()) | |
| if __name__ == "__main__": | |
| out = {} | |
| for split in sys.argv[2:]: | |
| for l in open(split): | |
| rec = json.loads(l) | |
| if rec["image"] not in out: | |
| out[rec["image"]] = cream_share(f"{sys.argv[1]}/{rec['image']}") | |
| json.dump(out, open(f"{sys.argv[1]}/data/cream_share.json", "w")) | |
| print(len(out)) | |