Spaces:
Runtime error
Runtime error
File size: 1,411 Bytes
b4c7867 c60446c 7921d06 b4c7867 c60446c b4c7867 7921d06 c60446c b4c7867 7921d06 c60446c 7921d06 c60446c 7921d06 c60446c | 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 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | import os
# HF Spaces uses /data; locally it can fall back to ./data
DATA_ROOT = os.getenv("DATA_ROOT", "./data")
def user_root(username: str) -> str:
return os.path.join(DATA_ROOT, "users", username, "notebooks")
def index_path(username: str) -> str:
# /data/users/<username>/notebooks/index.json
return os.path.join(user_root(username), "index.json")
def nb_root(username: str, notebook_id: str) -> str:
# /data/users/<username>/notebooks/<uuid>/
return os.path.join(user_root(username), notebook_id)
def ensure_tree(username: str, notebook_id: str):
# Ensure notebook folder layout exists
base = nb_root(username, notebook_id)
os.makedirs(user_root(username), exist_ok=True)
os.makedirs(base, exist_ok=True)
os.makedirs(os.path.join(base, "files_raw"), exist_ok=True)
os.makedirs(os.path.join(base, "files_extracted"), exist_ok=True)
os.makedirs(os.path.join(base, "chroma"), exist_ok=True)
os.makedirs(os.path.join(base, "chat"), exist_ok=True)
os.makedirs(os.path.join(base, "artifacts", "reports"), exist_ok=True)
os.makedirs(os.path.join(base, "artifacts", "quizzes"), exist_ok=True)
os.makedirs(os.path.join(base, "artifacts", "podcasts"), exist_ok=True)
# Make sure index.json exists
ip = index_path(username)
if not os.path.exists(ip):
with open(ip, "w", encoding="utf-8") as f:
f.write("[]") |