Spaces:
Sleeping
Sleeping
File size: 1,504 Bytes
52f8cb9 | 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 42 43 44 45 46 47 48 49 50 51 52 53 | """Data directory management for model files.
This module provides a centralized function to locate the directory containing
model data files, checking environment variables and falling back to local paths.
"""
import os
from pathlib import Path
# Global variable to store the model data directory path
_MODEL_DATA_DIR = None
def get_data_directory():
"""Get the directory containing model data files.
Returns the HuggingFace cache directory path for the model repository,
or falls back to local 'data/' directory if not yet downloaded.
Returns:
Path: Path to the model data directory
"""
global _MODEL_DATA_DIR
if _MODEL_DATA_DIR is not None:
return _MODEL_DATA_DIR
# Check if environment variable is set
if "MOSAIC_DATA_DIR" in os.environ:
_MODEL_DATA_DIR = Path(os.environ["MOSAIC_DATA_DIR"])
return _MODEL_DATA_DIR
# Check if local data/ directory exists (for development/backward compat)
local_data = Path("data")
if local_data.exists() and (local_data / "paladin_model_map.csv").exists():
_MODEL_DATA_DIR = local_data
return _MODEL_DATA_DIR
# Fall back to repo root data/ directory
_MODEL_DATA_DIR = local_data
return _MODEL_DATA_DIR
def set_data_directory(path):
"""Set the data directory path.
Args:
path: Path to the data directory
"""
global _MODEL_DATA_DIR
_MODEL_DATA_DIR = Path(path)
os.environ["MOSAIC_DATA_DIR"] = str(_MODEL_DATA_DIR)
|