yeq6x commited on
Commit
67b33c8
ยท
1 Parent(s): 4cf412e

Add functionality to refresh scripts and configuration files in app.py

Browse files

Implement _find_latest_dataset_dir to locate the most recent dataset directory and _collect_scripts_and_config to gather relevant files. Enhance the UI with a button to refresh scripts from the latest dataset, improving user experience and accessibility to training resources.

Files changed (1) hide show
  1. app.py +56 -0
app.py CHANGED
@@ -270,6 +270,46 @@ def _list_checkpoints(out_dir: str, limit: int = 20) -> List[str]:
270
  return []
271
 
272
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
273
  def _files_to_gallery(files: Any) -> List[str]:
274
  items: List[str] = []
275
  if not files:
@@ -959,6 +999,8 @@ def build_ui() -> gr.Blocks:
959
  logs = gr.Textbox(label="Logs", lines=20)
960
  ckpt_files = gr.Files(label="Checkpoints (live)", interactive=False)
961
  scripts_files = gr.Files(label="Scripts & Config (live)", interactive=False)
 
 
962
 
963
  # moved max_epochs/save_every above next to OUTPUT NAME
964
 
@@ -992,6 +1034,20 @@ def build_ui() -> gr.Blocks:
992
  outputs=[logs, ckpt_files, scripts_files],
993
  )
994
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
995
  with gr.TabItem("Prompt Generator"):
996
  gr.Markdown("""
997
  # ๐ŸŽจ Aโ†’B ๅค‰ๆ›ใƒ—ใƒญใƒณใƒ—ใƒˆ่‡ชๅ‹•็”Ÿๆˆ
 
270
  return []
271
 
272
 
273
+ def _find_latest_dataset_dir(root: str) -> Optional[str]:
274
+ try:
275
+ if not os.path.isdir(root):
276
+ return None
277
+ cand: List[Tuple[float, str]] = []
278
+ for name in os.listdir(root):
279
+ if not name.startswith("dataset_"):
280
+ continue
281
+ full = os.path.join(root, name)
282
+ if os.path.isdir(full):
283
+ try:
284
+ cand.append((os.path.getmtime(full), full))
285
+ except Exception:
286
+ pass
287
+ if not cand:
288
+ return None
289
+ cand.sort(reverse=True)
290
+ return cand[0][1]
291
+ except Exception:
292
+ return None
293
+
294
+
295
+ def _collect_scripts_and_config(ds_dir: Optional[str]) -> List[str]:
296
+ files: List[str] = []
297
+ try:
298
+ ds_conf = str(Path(AUTO_DIR_RUNTIME) / "dataset_QIE.toml")
299
+ if os.path.isfile(ds_conf):
300
+ files.append(ds_conf)
301
+ if ds_dir and os.path.isdir(ds_dir):
302
+ used_script = os.path.join(ds_dir, "train_QIE_used.sh")
303
+ if os.path.isfile(used_script):
304
+ files.append(used_script)
305
+ meta = os.path.join(ds_dir, "metadata.jsonl")
306
+ if os.path.isfile(meta):
307
+ files.append(meta)
308
+ except Exception:
309
+ pass
310
+ return files
311
+
312
+
313
  def _files_to_gallery(files: Any) -> List[str]:
314
  items: List[str] = []
315
  if not files:
 
999
  logs = gr.Textbox(label="Logs", lines=20)
1000
  ckpt_files = gr.Files(label="Checkpoints (live)", interactive=False)
1001
  scripts_files = gr.Files(label="Scripts & Config (live)", interactive=False)
1002
+ with gr.Row():
1003
+ refresh_scripts_btn = gr.Button("ใƒ•ใ‚กใ‚คใƒซใ‚’ๅ†ๅ–ๅพ—", variant="secondary")
1004
 
1005
  # moved max_epochs/save_every above next to OUTPUT NAME
1006
 
 
1034
  outputs=[logs, ckpt_files, scripts_files],
1035
  )
1036
 
1037
+ # ๅ›žๅŽใƒœใ‚ฟใƒณ: ็›ด่ฟ‘ใฎ dataset_ ใƒ‡ใ‚ฃใƒฌใ‚ฏใƒˆใƒชใ‹ใ‚‰ใƒ•ใ‚กใ‚คใƒซใ‚’ๅ†ๅ–ๅพ—
1038
+ def _refresh_scripts() -> List[str]:
1039
+ try:
1040
+ ds_dir = _find_latest_dataset_dir(DATA_ROOT_RUNTIME)
1041
+ return _collect_scripts_and_config(ds_dir)
1042
+ except Exception:
1043
+ return _collect_scripts_and_config(None)
1044
+
1045
+ refresh_scripts_btn.click(
1046
+ fn=_refresh_scripts,
1047
+ inputs=[],
1048
+ outputs=[scripts_files],
1049
+ )
1050
+
1051
  with gr.TabItem("Prompt Generator"):
1052
  gr.Markdown("""
1053
  # ๐ŸŽจ Aโ†’B ๅค‰ๆ›ใƒ—ใƒญใƒณใƒ—ใƒˆ่‡ชๅ‹•็”Ÿๆˆ