CaffeinatedCoding commited on
Commit
343ba20
Β·
verified Β·
1 Parent(s): fadccb6

Upload folder using huggingface_hub

Browse files
Files changed (1) hide show
  1. api/startup.py +30 -7
api/startup.py CHANGED
@@ -120,41 +120,64 @@ def load_all():
120
  # ── CLIP model ────────────────────────────────────────────
121
  # Loaded here, injected into orchestrator
122
  print("Loading CLIP ViT-B/32...")
123
- clip_model, clip_preprocess = clip.load("ViT-B/32", device="cpu")
124
- clip_model.eval()
125
- print("CLIP loaded")
 
 
 
 
126
 
127
  # ── Thresholds ────────────────────────────────────────────
 
128
  thresholds_path = os.path.join(
129
  os.environ.get("DATA_DIR", "data"), "thresholds.json"
130
  )
131
  if os.path.exists(thresholds_path):
132
  with open(thresholds_path) as f:
133
  thresholds = json.load(f)
134
- print(f"Thresholds loaded: {len(thresholds)} categories")
135
  else:
136
  thresholds = {}
137
  print("WARNING: thresholds.json not found β€” using score > 0.5 fallback")
138
 
139
  # ── GradCAM++ ─────────────────────────────────────────────
 
140
  try:
141
  gradcam.load()
 
142
  except Exception as e:
143
  print(f"WARNING: GradCAM++ load failed: {e}")
144
  print("Forensics mode will run without GradCAM++")
145
 
146
  # ── SHAP background ───────────────────────────────────────
 
147
  bg_path = os.path.join(
148
  os.environ.get("DATA_DIR", "data"), "shap_background.npy"
149
  )
150
- shap_explainer.load_background(bg_path)
 
 
 
 
 
 
 
 
 
151
 
152
  # ── Inject into orchestrator ──────────────────────────────
153
- init_orchestrator(clip_model, clip_preprocess, thresholds)
 
 
 
 
 
 
154
 
155
  elapsed = time.time() - STARTUP_TIME
156
  print("=" * 50)
157
- print(f"Startup complete in {elapsed:.1f}s")
158
  print(f"Model version: {MODEL_VERSION}")
159
  print("=" * 50)
160
 
 
120
  # ── CLIP model ────────────────────────────────────────────
121
  # Loaded here, injected into orchestrator
122
  print("Loading CLIP ViT-B/32...")
123
+ try:
124
+ clip_model, clip_preprocess = clip.load("ViT-B/32", device="cpu")
125
+ clip_model.eval()
126
+ print("CLIP loaded βœ“")
127
+ except Exception as e:
128
+ print(f"ERROR loading CLIP: {e}")
129
+ raise
130
 
131
  # ── Thresholds ────────────────────────────────────────────
132
+ print("Loading thresholds...")
133
  thresholds_path = os.path.join(
134
  os.environ.get("DATA_DIR", "data"), "thresholds.json"
135
  )
136
  if os.path.exists(thresholds_path):
137
  with open(thresholds_path) as f:
138
  thresholds = json.load(f)
139
+ print(f"Thresholds loaded βœ“ {len(thresholds)} categories")
140
  else:
141
  thresholds = {}
142
  print("WARNING: thresholds.json not found β€” using score > 0.5 fallback")
143
 
144
  # ── GradCAM++ ─────────────────────────────────────────────
145
+ print("Loading GradCAM++...")
146
  try:
147
  gradcam.load()
148
+ print("GradCAM++ loaded βœ“")
149
  except Exception as e:
150
  print(f"WARNING: GradCAM++ load failed: {e}")
151
  print("Forensics mode will run without GradCAM++")
152
 
153
  # ── SHAP background ───────────────────────────────────────
154
+ print("Loading SHAP background...")
155
  bg_path = os.path.join(
156
  os.environ.get("DATA_DIR", "data"), "shap_background.npy"
157
  )
158
+ try:
159
+ if os.path.exists(bg_path):
160
+ shap_explainer.load_background(bg_path)
161
+ print("SHAP background loaded βœ“")
162
+ else:
163
+ print(f"WARNING: SHAP background not found at {bg_path}")
164
+ print("SHAP explanations will use default background")
165
+ except Exception as e:
166
+ print(f"WARNING: SHAP background load failed: {e}")
167
+ print("SHAP explanations will use default background")
168
 
169
  # ── Inject into orchestrator ──────────────────────────────
170
+ print("Initializing orchestrator...")
171
+ try:
172
+ init_orchestrator(clip_model, clip_preprocess, thresholds)
173
+ print("Orchestrator initialized βœ“")
174
+ except Exception as e:
175
+ print(f"ERROR initializing orchestrator: {e}")
176
+ raise
177
 
178
  elapsed = time.time() - STARTUP_TIME
179
  print("=" * 50)
180
+ print(f"Startup complete in {elapsed:.1f}s βœ“")
181
  print(f"Model version: {MODEL_VERSION}")
182
  print("=" * 50)
183