katelynhur commited on
Commit
5dd084f
·
verified ·
1 Parent(s): e5c2364

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +46 -75
app.py CHANGED
@@ -290,73 +290,6 @@ def _round_df3(df: pd.DataFrame) -> pd.DataFrame:
290
  df[c] = df[c].round(3)
291
  return df
292
 
293
- # def predict_files(
294
- # files: List[str],
295
- # model1_name: str,
296
- # model2_name: str,
297
- # ckpt_map_json: str,
298
- # compact: bool
299
- # ) -> pd.DataFrame:
300
- # if not model1_name:
301
- # raise gr.Error("Please select Model 1.")
302
-
303
- # ckpt_map = json.loads(ckpt_map_json)
304
-
305
- # repo_file1 = ckpt_map[model1_name]
306
- # m1 = load_model_from_hub(model1_name, repo_file1)
307
- # arch1 = arch_from_filename(repo_file1)
308
-
309
- # m2, arch2 = None, None
310
- # if model2_name:
311
- # repo_file2 = ckpt_map[model2_name]
312
- # m2 = load_model_from_hub(model2_name, repo_file2)
313
- # arch2 = arch_from_filename(repo_file2)
314
-
315
- # rows = []
316
- # for f in files:
317
- # try:
318
- # img, base = _open_image(f)
319
- # except Exception:
320
- # continue
321
-
322
- # L1 = logits_for_model(m1, arch1, img)
323
- # L2 = logits_for_model(m2, arch2, img) if m2 else None
324
-
325
- # P1 = F.softmax(L1, dim=1)[0].cpu().numpy()
326
- # top1_idx = int(P1.argmax())
327
- # top1 = CLASS_NAMES[top1_idx]
328
- # conf1 = float(P1[top1_idx])
329
-
330
- # row = {"filename": base, "Model 1": model1_name, "M1:top": top1, "M1:conf": conf1}
331
-
332
- # if L2 is not None:
333
- # P2 = F.softmax(L2, dim=1)[0].cpu().numpy()
334
- # top2_idx = int(P2.argmax())
335
- # top2 = CLASS_NAMES[top2_idx]
336
- # conf2 = float(P2[top2_idx])
337
-
338
- # L_ens = ensemble_logits([L1, L2])
339
- # P_ens = F.softmax(L_ens, dim=1)[0].cpu().numpy()
340
- # topE_idx = int(P_ens.argmax())
341
- # topE = CLASS_NAMES[topE_idx]
342
- # confE = float(P_ens[topE_idx])
343
-
344
- # row.update({"Model 2": model2_name, "M2:top": top2, "M2:conf": conf2, "ENS:top": topE, "ENS:conf": confE})
345
-
346
- # if not compact:
347
- # for i, cls in enumerate(CLASS_NAMES):
348
- # row[f"M1:{cls}"] = float(P1[i])
349
- # row[f"M2:{cls}"] = float(P2[i])
350
- # row[f"ENS:{cls}"] = float(P_ens[i])
351
- # else:
352
- # if not compact:
353
- # for i, cls in enumerate(CLASS_NAMES):
354
- # row[f"M1:{cls}"] = float(P1[i])
355
-
356
- # rows.append(row)
357
-
358
- # return _round_df3(pd.DataFrame(rows))
359
-
360
  def predict_files(
361
  files: List[str],
362
  model1_name: str,
@@ -442,6 +375,22 @@ def _round_selected_cols(df: pd.DataFrame, cols: List[str]) -> pd.DataFrame:
442
  df[c] = pd.to_numeric(df[c], errors="coerce").round(3)
443
  return df
444
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
445
  def load_best_singles_table(leader_csv: Path) -> pd.DataFrame:
446
  if not leader_csv.exists():
447
  return pd.DataFrame([{"info": "leaderboard.csv not found"}])
@@ -456,21 +405,43 @@ def load_best_singles_table(leader_csv: Path) -> pd.DataFrame:
456
  # Exclude run_dir from display
457
  keep = [c for c in ["arch","test_acc","best_val_acc","img_size"] if c in df.columns]
458
  df = df[keep].reset_index(drop=True) if keep else df
459
- return _round_selected_cols(df, ["test_acc","best_val_acc"])
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
460
 
461
  def load_best_pairs_table() -> Optional[pd.DataFrame]:
462
  if PAIR_COMBINED.exists():
463
  df = pd.read_csv(PAIR_COMBINED)
464
  show = [c for c in ["members_names","avg_acc","min_acc","acc_LukeTest","acc_MarcoTest","acc_FalahTest"] if c in df.columns]
465
  df = df[show].head(20) if show else df.head(20)
466
- return _round_selected_cols(df, ["avg_acc","min_acc","acc_LukeTest","acc_MarcoTest","acc_FalahTest"])
467
- #if PAIR_FALLBACK.exists():
468
- # df = pd.read_csv(PAIR_FALLBACK)
469
- # show = [c for c in ["members_names","acc"] if c in df.columns]
470
- # df = df[show].head(20) if show else df.head(20)
471
- # return _round_selected_cols(df, ["acc"])
472
- return None # signal "not found"
473
 
 
 
 
 
474
  # ==============================
475
  # Upload helpers (gallery + state)
476
  # ==============================
 
290
  df[c] = df[c].round(3)
291
  return df
292
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
293
  def predict_files(
294
  files: List[str],
295
  model1_name: str,
 
375
  df[c] = pd.to_numeric(df[c], errors="coerce").round(3)
376
  return df
377
 
378
+ # def load_best_singles_table(leader_csv: Path) -> pd.DataFrame:
379
+ # if not leader_csv.exists():
380
+ # return pd.DataFrame([{"info": "leaderboard.csv not found"}])
381
+ # df = pd.read_csv(leader_csv)
382
+ # if "source" in df.columns:
383
+ # df = df[df["source"] == "single_arch"].copy()
384
+ # sort_cols = [c for c in ["test_acc", "best_val_acc"] if c in df.columns]
385
+ # if sort_cols:
386
+ # df = df.sort_values(sort_cols, ascending=False)
387
+ # if "arch" in df.columns:
388
+ # df = df.drop_duplicates(subset=["arch"], keep="first")
389
+ # # Exclude run_dir from display
390
+ # keep = [c for c in ["arch","test_acc","best_val_acc","img_size"] if c in df.columns]
391
+ # df = df[keep].reset_index(drop=True) if keep else df
392
+ # return _round_selected_cols(df, ["test_acc","best_val_acc"])
393
+
394
  def load_best_singles_table(leader_csv: Path) -> pd.DataFrame:
395
  if not leader_csv.exists():
396
  return pd.DataFrame([{"info": "leaderboard.csv not found"}])
 
405
  # Exclude run_dir from display
406
  keep = [c for c in ["arch","test_acc","best_val_acc","img_size"] if c in df.columns]
407
  df = df[keep].reset_index(drop=True) if keep else df
408
+
409
+ # ✅ CHANGE: Convert accuracy columns to percentages
410
+ if "test_acc" in df.columns:
411
+ df["test_acc"] = (df["test_acc"] * 100).round(2).astype(str) + "%"
412
+ if "best_val_acc" in df.columns:
413
+ df["best_val_acc"] = (df["best_val_acc"] * 100).round(2).astype(str) + "%"
414
+
415
+ return df
416
+
417
+ # def load_best_pairs_table() -> Optional[pd.DataFrame]:
418
+ # if PAIR_COMBINED.exists():
419
+ # df = pd.read_csv(PAIR_COMBINED)
420
+ # show = [c for c in ["members_names","avg_acc","min_acc","acc_LukeTest","acc_MarcoTest","acc_FalahTest"] if c in df.columns]
421
+ # df = df[show].head(20) if show else df.head(20)
422
+ # return _round_selected_cols(df, ["avg_acc","min_acc","acc_LukeTest","acc_MarcoTest","acc_FalahTest"])
423
+ # #if PAIR_FALLBACK.exists():
424
+ # # df = pd.read_csv(PAIR_FALLBACK)
425
+ # # show = [c for c in ["members_names","acc"] if c in df.columns]
426
+ # # df = df[show].head(20) if show else df.head(20)
427
+ # # return _round_selected_cols(df, ["acc"])
428
+ # return None # signal "not found"
429
 
430
  def load_best_pairs_table() -> Optional[pd.DataFrame]:
431
  if PAIR_COMBINED.exists():
432
  df = pd.read_csv(PAIR_COMBINED)
433
  show = [c for c in ["members_names","avg_acc","min_acc","acc_LukeTest","acc_MarcoTest","acc_FalahTest"] if c in df.columns]
434
  df = df[show].head(20) if show else df.head(20)
435
+
436
+ # ✅ CHANGE: Convert accuracy columns to percentages
437
+ for col in ["avg_acc", "min_acc", "acc_LukeTest", "acc_MarcoTest", "acc_FalahTest"]:
438
+ if col in df.columns:
439
+ df[col] = (pd.to_numeric(df[col], errors="coerce") * 100).round(2).astype(str) + "%"
 
 
440
 
441
+ return df
442
+ return None
443
+
444
+
445
  # ==============================
446
  # Upload helpers (gallery + state)
447
  # ==============================