samwaugh commited on
Commit
cfa56f8
·
1 Parent(s): 2c9a398

Try again 2

Browse files
Files changed (1) hide show
  1. backend/runner/config.py +25 -3
backend/runner/config.py CHANGED
@@ -6,8 +6,22 @@ All runner modules should import from this module instead of defining their own
6
  import os
7
  from pathlib import Path
8
 
 
 
 
9
  # Data root from environment variable (set by Hugging Face Space)
10
- DATA_ROOT = Path(os.getenv("DATA_ROOT", "/app/data")).resolve()
 
 
 
 
 
 
 
 
 
 
 
11
 
12
  # Core data directories
13
  EMBEDDINGS_DIR = DATA_ROOT / "embeddings"
@@ -19,10 +33,10 @@ MARKER_DIR = DATA_ROOT / "marker_output"
19
 
20
  # Model-specific embedding directories
21
  CLIP_EMBEDDINGS_DIR = EMBEDDINGS_DIR / "CLIP_Embeddings"
22
- PAINTINGCLIP_EMBEDDINGS_DIR = EMBEDDINGS_DIR / "PaintingCLIP_Embeddings"
23
 
24
  # Model directories
25
- PAINTINGCLIP_MODEL_DIR = MODELS_DIR / "PaintingCLIP"
26
 
27
  # Metadata files
28
  SENTENCES_JSON = JSON_INFO_DIR / "sentences.json"
@@ -30,3 +44,11 @@ WORKS_JSON = JSON_INFO_DIR / "works.json"
30
  TOPICS_JSON = JSON_INFO_DIR / "topics.json"
31
  CREATORS_JSON = JSON_INFO_DIR / "creators.json"
32
  TOPIC_NAMES_JSON = JSON_INFO_DIR / "topic_names.json"
 
 
 
 
 
 
 
 
 
6
  import os
7
  from pathlib import Path
8
 
9
+ # Get the directory where this config.py file is located
10
+ CONFIG_DIR = Path(__file__).parent.parent.parent # Go up from backend/runner/config.py to project root
11
+
12
  # Data root from environment variable (set by Hugging Face Space)
13
+ # Fall back to project data directory if /app/data doesn't exist or isn't writable
14
+ DATA_ROOT_ENV = os.getenv("DATA_ROOT", "/app/data")
15
+ DATA_ROOT = Path(DATA_ROOT_ENV)
16
+
17
+ # Check if the default directory is writable, fall back to project data directory if not
18
+ if not DATA_ROOT.exists() or not os.access(DATA_ROOT, os.W_OK):
19
+ print(f"⚠️ DATA_ROOT {DATA_ROOT} not writable, falling back to project data directory")
20
+ DATA_ROOT = CONFIG_DIR / "data"
21
+ else:
22
+ print(f"✅ Using DATA_ROOT: {DATA_ROOT}")
23
+
24
+ DATA_ROOT = DATA_ROOT.resolve()
25
 
26
  # Core data directories
27
  EMBEDDINGS_DIR = DATA_ROOT / "embeddings"
 
33
 
34
  # Model-specific embedding directories
35
  CLIP_EMBEDDINGS_DIR = EMBEDDINGS_DIR / "CLIP_Embeddings"
36
+ PAINTINGCLIP_EMBEDDINGS_DIR = EMBEDDINGS_DIR / "PaintingClip_Embeddings"
37
 
38
  # Model directories
39
+ PAINTINGCLIP_MODEL_DIR = MODELS_DIR / "PaintingClip"
40
 
41
  # Metadata files
42
  SENTENCES_JSON = JSON_INFO_DIR / "sentences.json"
 
44
  TOPICS_JSON = JSON_INFO_DIR / "topics.json"
45
  CREATORS_JSON = JSON_INFO_DIR / "creators.json"
46
  TOPIC_NAMES_JSON = JSON_INFO_DIR / "topic_names.json"
47
+
48
+ # Ensure writable directories exist
49
+ for dir_path in [OUTPUTS_DIR, ARTIFACTS_DIR]:
50
+ try:
51
+ dir_path.mkdir(parents=True, exist_ok=True)
52
+ print(f"✅ Ensured directory exists: {dir_path}")
53
+ except Exception as e:
54
+ print(f"⚠️ Could not create directory {dir_path}: {e}")