Spaces:
Running
Running
Download scripts/make_sample_data.py from lukehola/opa-traint: direct link, hf CLI and curl.
- Browser
- Download file 3.97 kB
-
https://huggingface.co/spaces/lukehola/opa-traint/resolve/main/scripts/make_sample_data.py
- Command line
-
hf download hf://spaces/lukehola/opa-traint/scripts/make_sample_data.py
-
curl -L -o make_sample_data.py https://huggingface.co/spaces/lukehola/opa-traint/resolve/main/scripts/make_sample_data.py
3.97 kB
| #!/usr/bin/env python3 | |
| """Generate SAMPLE family data in ./data for local testing. | |
| The public repo contains zero personal data; this script creates placeholder | |
| people/events with solid-color photos so the whole app can be tested locally | |
| without the private dataset. Run from the repo root: | |
| python scripts/make_sample_data.py | |
| """ | |
| from __future__ import annotations | |
| import json | |
| import os | |
| import struct | |
| import zlib | |
| from pathlib import Path | |
| ROOT = Path(__file__).resolve().parent.parent | |
| DATA = ROOT / "data" | |
| def make_png(path: Path, rgb: tuple, size: int = 240) -> None: | |
| """Minimal solid-color PNG writer (no dependencies).""" | |
| raw = b"".join(b"\x00" + bytes(rgb) * size for _ in range(size)) | |
| def chunk(tag: bytes, data: bytes) -> bytes: | |
| c = struct.pack(">I", len(data)) + tag + data | |
| return c + struct.pack(">I", zlib.crc32(tag + data) & 0xFFFFFFFF) | |
| png = b"\x89PNG\r\n\x1a\n" | |
| png += chunk(b"IHDR", struct.pack(">IIBBBBB", size, size, 8, 2, 0, 0, 0)) | |
| png += chunk(b"IDAT", zlib.compress(raw)) | |
| png += chunk(b"IEND", b"") | |
| path.parent.mkdir(parents=True, exist_ok=True) | |
| path.write_bytes(png) | |
| SAMPLE_NOTE = ("SAMPLE data for local testing only. Real family data lives in the " | |
| "private HF dataset (data/ is fully gitignored). Regenerate with " | |
| "scripts/make_sample_data.py; upload real data with " | |
| "scripts/upload_family_data.py.") | |
| PEOPLE = { | |
| "_comment": SAMPLE_NOTE, | |
| "people": [ | |
| {"id": "beth", "name": "Beth", "aliases": ["Bethje"], "relation": "vriendin van Luke", | |
| "photos": ["photos/people/beth/1.png"], "birthday": "07-06", "active": True}, | |
| {"id": "luke", "name": "Luke", "aliases": [], "relation": "je oudste kleinzoon", | |
| "photos": ["photos/people/luke/1.png"], "active": True}, | |
| {"id": "jacq", "name": "Jacq", "aliases": [], "relation": "je dochter", | |
| "photos": ["photos/people/jacq/1.png"], "active": True}, | |
| {"id": "pieter", "name": "Pieter", "aliases": ["Piet"], "relation": "je oude schaakvriend", | |
| "photos": ["photos/people/pieter/1.png"], "active": True}, | |
| ] | |
| } | |
| EVENTS = { | |
| "_comment": SAMPLE_NOTE, | |
| "events": [ | |
| {"id": "vakantie_1998", "photo": "photos/events/vakantie_1998.png", | |
| "title": "Vakantie in Frankrijk, 1998", | |
| "description": "In de zomer van 1998 reden jullie met de auto naar Frankrijk. " | |
| "Het was warm, de wijn was lekker, en er werd elke avond buiten " | |
| "gegeten onder de platanen.", | |
| "prompts": ["Waar was dit?", "Wie waren erbij?", "Wat aten jullie daar graag?"], | |
| "active": True}, | |
| {"id": "schaakclub", "photo": "photos/events/schaakclub.png", | |
| "title": "De schaakclub", | |
| "description": "Jarenlang speelde je elke donderdagavond op de schaakclub. " | |
| "Er werd fanatiek gespeeld, maar vooral veel gelachen — en na " | |
| "afloop altijd één biertje.", | |
| "prompts": ["Met wie speelde je het liefst?", "Won je vaak?"], | |
| "active": True}, | |
| ] | |
| } | |
| PHOTOS = { | |
| "photos/people/beth/1.png": (232, 163, 61), | |
| "photos/people/luke/1.png": (127, 168, 160), | |
| "photos/people/jacq/1.png": (217, 136, 128), | |
| "photos/people/pieter/1.png": (130, 176, 216), | |
| "photos/events/vakantie_1998.png": (246, 185, 59), | |
| "photos/events/schaakclub.png": (168, 213, 162), | |
| } | |
| def main() -> None: | |
| (DATA / "progress").mkdir(parents=True, exist_ok=True) | |
| (DATA / "recordings").mkdir(parents=True, exist_ok=True) | |
| (DATA / "people.json").write_text( | |
| json.dumps(PEOPLE, ensure_ascii=False, indent=2), encoding="utf-8") | |
| (DATA / "events.json").write_text( | |
| json.dumps(EVENTS, ensure_ascii=False, indent=2), encoding="utf-8") | |
| for rel, rgb in PHOTOS.items(): | |
| make_png(DATA / rel, rgb) | |
| print(f"sample data written to {DATA}") | |
| if __name__ == "__main__": | |
| main() | |