Spaces:
Runtime error
Runtime error
File size: 720 Bytes
0385672 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
import os
import json
from datetime import datetime
import uuid
RESULTS_DIR = "results"
def save_result(data: dict) -> str:
if not os.path.exists(RESULTS_DIR):
os.makedirs(RESULTS_DIR)
unique_id = str(uuid.uuid4())[:8]
filename = f"{unique_id}.json"
path = os.path.join(RESULTS_DIR, filename)
with open(path, "w") as f:
json.dump({
"timestamp": datetime.utcnow().isoformat(),
"data": data
}, f, indent=2)
return filename
def load_result(filename: str) -> dict:
path = os.path.join(RESULTS_DIR, filename)
if not os.path.exists(path):
return {"error": "Result not found."}
with open(path, "r") as f:
return json.load(f) |