mertunsall commited on
Commit
ddc5859
·
1 Parent(s): fc19570
Files changed (1) hide show
  1. app.py +20 -1
app.py CHANGED
@@ -1,4 +1,5 @@
1
  from functools import lru_cache
 
2
  import traceback
3
  from typing import Optional
4
 
@@ -18,6 +19,8 @@ IMAGE_EXTENSIONS = (
18
  ".tif",
19
  ".tiff",
20
  )
 
 
21
 
22
 
23
  api = HfApi()
@@ -71,12 +74,28 @@ def _get_image_urls(repo_id: str, directory: str) -> list[str]:
71
  and path.lower().endswith(IMAGE_EXTENSIONS)
72
  ]
73
 
 
 
74
  return [
75
  hf_hub_url(repo_id=repo_id, filename=path, repo_type="dataset")
76
- for path in sorted(image_files)
77
  ]
78
 
79
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
80
  def _dropdown_update(
81
  *,
82
  choices: list[str],
 
1
  from functools import lru_cache
2
+ import re
3
  import traceback
4
  from typing import Optional
5
 
 
19
  ".tif",
20
  ".tiff",
21
  )
22
+ INIT_SCREENSHOT_NAMES = {"intial_screenshot", "initial_screenshot"}
23
+ STEP_FILENAME_PATTERN = re.compile(r"^step_(\d+)(?:\.[^.]+)?$", re.IGNORECASE)
24
 
25
 
26
  api = HfApi()
 
74
  and path.lower().endswith(IMAGE_EXTENSIONS)
75
  ]
76
 
77
+ sorted_files = sorted(image_files, key=_image_sort_key)
78
+
79
  return [
80
  hf_hub_url(repo_id=repo_id, filename=path, repo_type="dataset")
81
+ for path in sorted_files
82
  ]
83
 
84
 
85
+ def _image_sort_key(path: str):
86
+ filename = path.rsplit("/", 1)[-1]
87
+ lower_name = filename.lower()
88
+
89
+ if any(lower_name.startswith(name) for name in INIT_SCREENSHOT_NAMES):
90
+ return (0, 0)
91
+
92
+ match = STEP_FILENAME_PATTERN.match(lower_name)
93
+ if match:
94
+ return (1, int(match.group(1)))
95
+
96
+ return (2, lower_name)
97
+
98
+
99
  def _dropdown_update(
100
  *,
101
  choices: list[str],