Spaces:
Sleeping
Sleeping
Rajan Sharma
commited on
Create pipeline/io_utils.py
Browse files- pipeline/io_utils.py +12 -0
pipeline/io_utils.py
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import json
|
| 2 |
+
from pathlib import Path
|
| 3 |
+
from typing import Any, Dict
|
| 4 |
+
|
| 5 |
+
def load_json(p: Path) -> Dict[str, Any]:
|
| 6 |
+
with open(p, "r", encoding="utf-8") as f:
|
| 7 |
+
return json.load(f)
|
| 8 |
+
|
| 9 |
+
def save_json(p: Path, data: Dict[str, Any]):
|
| 10 |
+
p.parent.mkdir(parents=True, exist_ok=True)
|
| 11 |
+
with open(p, "w", encoding="utf-8") as f:
|
| 12 |
+
json.dump(data, f, ensure_ascii=False, indent=2)
|