blanchon commited on
Commit
06de6e8
·
verified ·
1 Parent(s): 22fb356

fix: VideoData path extraction; surface real errors as picklable gr.Error

Browse files
Files changed (1) hide show
  1. app.py +34 -2
app.py CHANGED
@@ -18,6 +18,7 @@ import gc
18
  import os
19
  import tempfile
20
  import threading
 
21
  from pathlib import Path
22
 
23
  import spaces # must precede torch/gradio on ZeroGPU
@@ -122,8 +123,15 @@ def get_extractor(model_key: str):
122
 
123
 
124
  def _video_to_tmp_path(video_file) -> str:
125
- """gradio video input -> local path on disk."""
126
- return video_file if isinstance(video_file, str) else video_file.name
 
 
 
 
 
 
 
127
 
128
 
129
  def export_video(frames: torch.Tensor, fps: float) -> str:
@@ -203,6 +211,14 @@ def _atomic_anchors(pipe) -> dict[str, np.ndarray] | None:
203
 
204
  @spaces.GPU(duration=240)
205
  def run_transfer(source_video, first_frame, model_key, guidance, steps, seed):
 
 
 
 
 
 
 
 
206
  if not source_video:
207
  raise gr.Error("Pick or upload a source video first.")
208
  from o2laf import ActionGuidance
@@ -232,6 +248,14 @@ def run_transfer(source_video, first_frame, model_key, guidance, steps, seed):
232
 
233
  @spaces.GPU(duration=240)
234
  def run_idm(source_video, model_key, block, head):
 
 
 
 
 
 
 
 
235
  if not source_video:
236
  raise gr.Error("Pick or upload a video first.")
237
  pipe = get_pipe(model_key)
@@ -250,6 +274,14 @@ def run_idm(source_video, model_key, block, head):
250
 
251
  @spaces.GPU(duration=240)
252
  def run_atomic(first_frame, action, num_frames, steps, seed):
 
 
 
 
 
 
 
 
253
  if first_frame is None:
254
  raise gr.Error("Pick or upload a first frame first.")
255
  from o2laf import ActionGuidance
 
18
  import os
19
  import tempfile
20
  import threading
21
+ import traceback
22
  from pathlib import Path
23
 
24
  import spaces # must precede torch/gradio on ZeroGPU
 
123
 
124
 
125
  def _video_to_tmp_path(video_file) -> str:
126
+ """gradio video input -> local path on disk (str in gradio 3, VideoData in 4/5)."""
127
+ if isinstance(video_file, str):
128
+ return video_file
129
+ if hasattr(video_file, "video"):
130
+ return video_file.video.path
131
+ if isinstance(video_file, dict):
132
+ v = video_file.get("video", video_file)
133
+ return v["path"] if isinstance(v, dict) else v.path
134
+ return video_file.name
135
 
136
 
137
  def export_video(frames: torch.Tensor, fps: float) -> str:
 
211
 
212
  @spaces.GPU(duration=240)
213
  def run_transfer(source_video, first_frame, model_key, guidance, steps, seed):
214
+ try:
215
+ return _run_transfer(source_video, first_frame, model_key, guidance, steps, seed)
216
+ except Exception as exc:
217
+ traceback.print_exc()
218
+ raise gr.Error(f"O2LaF failed: {type(exc).__name__}: {exc}") from None
219
+
220
+
221
+ def _run_transfer(source_video, first_frame, model_key, guidance, steps, seed):
222
  if not source_video:
223
  raise gr.Error("Pick or upload a source video first.")
224
  from o2laf import ActionGuidance
 
248
 
249
  @spaces.GPU(duration=240)
250
  def run_idm(source_video, model_key, block, head):
251
+ try:
252
+ return _run_idm(source_video, model_key, block, head)
253
+ except Exception as exc:
254
+ traceback.print_exc()
255
+ raise gr.Error(f"O2LaF failed: {type(exc).__name__}: {exc}") from None
256
+
257
+
258
+ def _run_idm(source_video, model_key, block, head):
259
  if not source_video:
260
  raise gr.Error("Pick or upload a video first.")
261
  pipe = get_pipe(model_key)
 
274
 
275
  @spaces.GPU(duration=240)
276
  def run_atomic(first_frame, action, num_frames, steps, seed):
277
+ try:
278
+ return _run_atomic(first_frame, action, num_frames, steps, seed)
279
+ except Exception as exc:
280
+ traceback.print_exc()
281
+ raise gr.Error(f"O2LaF failed: {type(exc).__name__}: {exc}") from None
282
+
283
+
284
+ def _run_atomic(first_frame, action, num_frames, steps, seed):
285
  if first_frame is None:
286
  raise gr.Error("Pick or upload a first frame first.")
287
  from o2laf import ActionGuidance