bear-ty commited on
Commit
beaaeba
·
verified ·
1 Parent(s): ebcdff5

Plus ZeroGPU shell

Browse files
Files changed (1) hide show
  1. app.py +20 -1
app.py CHANGED
@@ -80,13 +80,32 @@ os.environ.setdefault("KMP_DUPLICATE_LIB_OK", "TRUE")
80
  sys.path.insert(0, str(RUNTIME_ROOT))
81
 
82
  from app_runtime import create_demo, run_gpu_stage # noqa: E402
 
 
 
 
 
 
83
 
84
 
85
  @spaces.GPU(duration=150, size="large")
86
- def zero_gpu_inference(video_path: str, progress=gr.Progress()) -> dict:
87
  return run_gpu_stage(video_path, progress=progress)
88
 
89
 
 
 
 
 
 
 
 
 
 
 
 
 
 
90
  demo = create_demo(zero_gpu_inference)
91
  demo.queue(default_concurrency_limit=1, max_size=3)
92
 
 
80
  sys.path.insert(0, str(RUNTIME_ROOT))
81
 
82
  from app_runtime import create_demo, run_gpu_stage # noqa: E402
83
+ import cv2 # noqa: E402
84
+
85
+
86
+ @spaces.GPU(duration=80, size="large")
87
+ def gpu_fast(video_path: str, progress=gr.Progress()) -> dict:
88
+ return run_gpu_stage(video_path, progress=progress)
89
 
90
 
91
  @spaces.GPU(duration=150, size="large")
92
+ def gpu_full(video_path: str, progress=gr.Progress()) -> dict:
93
  return run_gpu_stage(video_path, progress=progress)
94
 
95
 
96
+ def zero_gpu_inference(video_path: str, progress=gr.Progress()) -> dict:
97
+ capture = cv2.VideoCapture(video_path)
98
+ try:
99
+ fps = float(capture.get(cv2.CAP_PROP_FPS) or 0.0)
100
+ frames = int(capture.get(cv2.CAP_PROP_FRAME_COUNT) or 0)
101
+ finally:
102
+ capture.release()
103
+ duration = frames / fps if fps > 0 else 0.0
104
+ # Short clips fit the anonymous 120s ZeroGPU allowance; longer clips use
105
+ # the 225s allowance, which requires a signed-in Hugging Face user.
106
+ return gpu_fast(video_path, progress=progress) if duration <= 2.2 else gpu_full(video_path, progress=progress)
107
+
108
+
109
  demo = create_demo(zero_gpu_inference)
110
  demo.queue(default_concurrency_limit=1, max_size=3)
111