Michael Paonam commited on
Commit
b3cbac7
·
1 Parent(s): c4c6a40

Add startup logging for data path resolution

Browse files

Prints which data directory is used (bucket mount vs local) and
whether critical files exist. Helps debug missing data on HF Spaces.

Files changed (1) hide show
  1. app.py +20 -9
app.py CHANGED
@@ -18,8 +18,11 @@ APP_DIR = Path(__file__).resolve().parent
18
  HF_BUCKET_MOUNT = Path("/data")
19
  if HF_BUCKET_MOUNT.exists() and HF_BUCKET_MOUNT.is_dir():
20
  DATA_DIR = HF_BUCKET_MOUNT
 
 
21
  else:
22
  DATA_DIR = APP_DIR / "data"
 
23
 
24
  RESULTS_PATH = DATA_DIR / "vlm_results" / "results.json"
25
  DEMO_PATH = DATA_DIR / "demo_matches.json"
@@ -29,6 +32,11 @@ INDEX_PATH = DATA_DIR / "frames_index.json"
29
  ALL_FRAMES_DIR = DATA_DIR / "frames"
30
  MATCH_STATS_PATH = DATA_DIR / "match_stats.json"
31
 
 
 
 
 
 
32
  VLM_BASE_URL = os.environ.get("VLM_BASE_URL", "")
33
  VLM_MODEL = os.environ.get("VLM_MODEL", "Qwen/Qwen3-VL-32B-Instruct")
34
  VLM_API_KEY = os.environ.get("VLM_API_KEY", "EMPTY")
@@ -202,14 +210,17 @@ def make_formation_plot(match):
202
 
203
  centers = np.array(centers)
204
 
205
- # Normalize to pitch coordinates (0-105 x 0-68)
206
- x_min, x_max = centers[:, 0].min(), centers[:, 0].max()
207
- y_min, y_max = centers[:, 1].min(), centers[:, 1].max()
208
- x_range = x_max - x_min if x_max - x_min > 0 else 1
209
- y_range = y_max - y_min if y_max - y_min > 0 else 1
 
 
210
 
211
- pitch_x = (centers[:, 0] - x_min) / x_range * 100 + 2.5
212
- pitch_y = (centers[:, 1] - y_min) / y_range * 64 + 2
 
213
 
214
  # KMeans to split into two teams
215
  from sklearn.cluster import KMeans
@@ -258,8 +269,8 @@ def make_formation_plot(match):
258
  if ball:
259
  ball_cx = (ball["bbox"][0] + ball["bbox"][2]) / 2
260
  ball_cy = (ball["bbox"][1] + ball["bbox"][3]) / 2
261
- ball_px = (ball_cx - x_min) / x_range * 100 + 2.5
262
- ball_py = (ball_cy - y_min) / y_range * 64 + 2
263
  fig.add_trace(go.Scatter(
264
  x=[ball_px], y=[ball_py], mode="markers",
265
  marker=dict(size=10, color="#fbbf24", symbol="circle",
 
18
  HF_BUCKET_MOUNT = Path("/data")
19
  if HF_BUCKET_MOUNT.exists() and HF_BUCKET_MOUNT.is_dir():
20
  DATA_DIR = HF_BUCKET_MOUNT
21
+ print(f"[Offsides] Using HF bucket mount: {DATA_DIR}")
22
+ print(f"[Offsides] Bucket contents: {list(DATA_DIR.iterdir())}")
23
  else:
24
  DATA_DIR = APP_DIR / "data"
25
+ print(f"[Offsides] Using local data: {DATA_DIR}")
26
 
27
  RESULTS_PATH = DATA_DIR / "vlm_results" / "results.json"
28
  DEMO_PATH = DATA_DIR / "demo_matches.json"
 
32
  ALL_FRAMES_DIR = DATA_DIR / "frames"
33
  MATCH_STATS_PATH = DATA_DIR / "match_stats.json"
34
 
35
+ print(f"[Offsides] results.json exists: {RESULTS_PATH.exists()}")
36
+ print(f"[Offsides] demo_matches.json exists: {DEMO_PATH.exists()}")
37
+ print(f"[Offsides] frames dir exists: {ALL_FRAMES_DIR.exists()}")
38
+ print(f"[Offsides] match_stats.json exists: {MATCH_STATS_PATH.exists()}")
39
+
40
  VLM_BASE_URL = os.environ.get("VLM_BASE_URL", "")
41
  VLM_MODEL = os.environ.get("VLM_MODEL", "Qwen/Qwen3-VL-32B-Instruct")
42
  VLM_API_KEY = os.environ.get("VLM_API_KEY", "EMPTY")
 
210
 
211
  centers = np.array(centers)
212
 
213
+ # Normalize to pitch coordinates centered on (52.5, 34)
214
+ cx_mid = (centers[:, 0].min() + centers[:, 0].max()) / 2
215
+ cy_mid = (centers[:, 1].min() + centers[:, 1].max()) / 2
216
+ x_range = centers[:, 0].max() - centers[:, 0].min()
217
+ y_range = centers[:, 1].max() - centers[:, 1].min()
218
+ x_range = x_range if x_range > 0 else 1
219
+ y_range = y_range if y_range > 0 else 1
220
 
221
+ # Scale to fit within pitch (with padding) and center
222
+ pitch_x = (centers[:, 0] - cx_mid) / x_range * 90 + 52.5
223
+ pitch_y = (centers[:, 1] - cy_mid) / y_range * 58 + 34
224
 
225
  # KMeans to split into two teams
226
  from sklearn.cluster import KMeans
 
269
  if ball:
270
  ball_cx = (ball["bbox"][0] + ball["bbox"][2]) / 2
271
  ball_cy = (ball["bbox"][1] + ball["bbox"][3]) / 2
272
+ ball_px = (ball_cx - cx_mid) / x_range * 90 + 52.5
273
+ ball_py = (ball_cy - cy_mid) / y_range * 58 + 34
274
  fig.add_trace(go.Scatter(
275
  x=[ball_px], y=[ball_py], mode="markers",
276
  marker=dict(size=10, color="#fbbf24", symbol="circle",