adithya9903's picture
Deploy PolyGuard HF training Space
fd0c71a verified
"""Package/local artifact loading."""
from __future__ import annotations
import json
from pathlib import Path
from typing import Any
import yaml
def load_artifact(path: Path) -> Any:
if path.suffix.lower() in {".json"}:
return json.loads(path.read_text(encoding="utf-8"))
if path.suffix.lower() in {".yaml", ".yml"}:
return yaml.safe_load(path.read_text(encoding="utf-8"))
if path.suffix.lower() in {".txt", ".md"}:
return path.read_text(encoding="utf-8")
return path.read_bytes()