CoolFace
Apppublic

YassminOsama/FaceVerificationAPI

sourceHugging Faceupdated 3mo agoView on Hugging Face
0likes
storage.py31 linesDownload Raw Back to root
1"""2Temporary local storage adapter for the Face Verification service.3 4This module provides basic JSON-file based storage for enrollment embeddings5and verification logs. It serves as a testing/temporary storage layer until6the main backend integrates with its own database.7"""8 9import json10import threading11from pathlib import Path12 13LOCAL_DB_DIR = Path(__file__).parent / "local_db"14EMBEDDINGS_FILE = LOCAL_DB_DIR / "embeddings.json"15VERIFICATION_LOG_FILE = LOCAL_DB_DIR / "verification_log.json"16 17# Thread lock for JSON file read/write operations18_json_lock = threading.Lock()19 20 21def load_json(path: Path) -> dict:22    """Load a JSON file and return its contents as a dict."""23    with _json_lock:24        return json.loads(path.read_text(encoding="utf-8"))25 26 27def save_json(path: Path, data: dict) -> None:28    """Write *data* to a JSON file (pretty-printed)."""29    with _json_lock:30        path.write_text(json.dumps(data, indent=2, default=str), encoding="utf-8")31