cheenchan commited on
Commit
7c7d36f
·
1 Parent(s): f0a2986

Fix state initialization for catalog

Browse files
frame_extraction/src/frame_extraction/app.py CHANGED
@@ -28,12 +28,11 @@ def ensure_output_dirs() -> None:
28
  (OUTPUT_DIR / "frames").mkdir(parents=True, exist_ok=True)
29
 
30
 
31
- def build_catalog_from_video(files: list[gr.FileData]) -> tuple[str | None, str]:
32
- if not files:
33
  raise gr.Error("Please upload a source video first.")
34
 
35
  ensure_output_dirs()
36
- file = files[0]
37
  run_id = uuid.uuid4().hex[:8]
38
  video_dir = OUTPUT_DIR / "videos"
39
  video_path = video_dir / f"{run_id}_{Path(file.name).name}"
@@ -83,15 +82,10 @@ def predict_from_arrays(arrays: list[np.ndarray], catalog_path: str | None) -> t
83
  def build_interface() -> gr.Blocks:
84
  with gr.Blocks() as demo:
85
  gr.Markdown("# Character Reference Matcher")
86
- catalog_state = gr.State[str | None](str(CATALOG_PATH) if CATALOG_PATH.exists() else None)
87
  status_box = gr.Textbox(label="Status", value="Upload a video to generate a catalog.", interactive=False)
88
 
89
- video_upload = gr.UploadButton(
90
- label="Upload source video",
91
- file_types=["video"],
92
- file_count="single",
93
- )
94
-
95
  frame_upload = gr.UploadButton(
96
  label="Upload frames",
97
  file_types=["image"],
@@ -101,7 +95,7 @@ def build_interface() -> gr.Blocks:
101
  matches_json = gr.JSON(label="Matches")
102
  gallery = gr.Gallery(label="Reference Thumbnails", columns=2)
103
 
104
- video_upload.upload(build_catalog_from_video, inputs=video_upload, outputs=[catalog_state, status_box])
105
 
106
  def handle_frames(files: list[gr.FileData], catalog_path: str | None) -> tuple[list[dict[str, Any]], list[list[str]]]:
107
  arrays = [np.array(Image.open(file.name).convert("RGB")) for file in files]
 
28
  (OUTPUT_DIR / "frames").mkdir(parents=True, exist_ok=True)
29
 
30
 
31
+ def build_catalog_from_video(file: gr.FileData) -> tuple[str | None, str]:
32
+ if file is None:
33
  raise gr.Error("Please upload a source video first.")
34
 
35
  ensure_output_dirs()
 
36
  run_id = uuid.uuid4().hex[:8]
37
  video_dir = OUTPUT_DIR / "videos"
38
  video_path = video_dir / f"{run_id}_{Path(file.name).name}"
 
82
  def build_interface() -> gr.Blocks:
83
  with gr.Blocks() as demo:
84
  gr.Markdown("# Character Reference Matcher")
85
+ catalog_state = gr.State(str(CATALOG_PATH) if CATALOG_PATH.exists() else None)
86
  status_box = gr.Textbox(label="Status", value="Upload a video to generate a catalog.", interactive=False)
87
 
88
+ video_upload = gr.File(label="Source video", file_types=["video"], height="auto")
 
 
 
 
 
89
  frame_upload = gr.UploadButton(
90
  label="Upload frames",
91
  file_types=["image"],
 
95
  matches_json = gr.JSON(label="Matches")
96
  gallery = gr.Gallery(label="Reference Thumbnails", columns=2)
97
 
98
+ video_upload.change(build_catalog_from_video, inputs=video_upload, outputs=[catalog_state, status_box])
99
 
100
  def handle_frames(files: list[gr.FileData], catalog_path: str | None) -> tuple[list[dict[str, Any]], list[list[str]]]:
101
  arrays = [np.array(Image.open(file.name).convert("RGB")) for file in files]