Spaces:
Running
on
Zero
Running
on
Zero
use gradio error + fix support for webcam
Browse files
app.py
CHANGED
@@ -75,8 +75,8 @@ def predict_depth(input_image):
|
|
75 |
|
76 |
@rr.thread_local_stream("rerun_example_ml_depth_pro")
|
77 |
def run_rerun(path_to_video):
|
78 |
-
stream = rr.binary_stream()
|
79 |
print("video path:", path_to_video)
|
|
|
80 |
|
81 |
blueprint = rrb.Blueprint(
|
82 |
rrb.Vertical(
|
@@ -103,8 +103,15 @@ def run_rerun(path_to_video):
|
|
103 |
|
104 |
cap = cv2.VideoCapture(path_to_video)
|
105 |
num_frames = cap.get(cv2.CAP_PROP_FRAME_COUNT)
|
106 |
-
|
|
|
|
|
|
|
|
|
107 |
for i in range(len(frame_timestamps_ns)):
|
|
|
|
|
|
|
108 |
ret, frame = cap.read()
|
109 |
if not ret:
|
110 |
break
|
@@ -151,10 +158,7 @@ def run_rerun(path_to_video):
|
|
151 |
|
152 |
yield stream.read()
|
153 |
except Exception as e:
|
154 |
-
|
155 |
-
"error",
|
156 |
-
rr.TextLog(f"An error has occurred: {e}", level=rr.TextLogLevel.ERROR),
|
157 |
-
)
|
158 |
finally:
|
159 |
# Clean up the temporary file
|
160 |
if temp_file and os.path.exists(temp_file):
|
@@ -169,18 +173,14 @@ with gr.Blocks() as interface:
|
|
169 |
# DepthPro Rerun Demo
|
170 |
|
171 |
[DepthPro](https://huggingface.co/apple/DepthPro) is a fast metric depth prediction model. Simply upload a video to visualize the depth predictions in real-time.
|
172 |
-
|
173 |
High resolution videos will be automatically resized to 256x256 pixels, to speed up the inference and visualize multiple frames.
|
174 |
"""
|
175 |
)
|
176 |
with gr.Row():
|
177 |
with gr.Column(variant="compact"):
|
178 |
video = gr.Video(
|
179 |
-
format="mp4",
|
180 |
-
interactive=True,
|
181 |
-
label="Video",
|
182 |
-
include_audio=False,
|
183 |
-
max_length=10,
|
184 |
)
|
185 |
visualize = gr.Button("Visualize ML Depth Pro")
|
186 |
with gr.Column():
|
|
|
75 |
|
76 |
@rr.thread_local_stream("rerun_example_ml_depth_pro")
|
77 |
def run_rerun(path_to_video):
|
|
|
78 |
print("video path:", path_to_video)
|
79 |
+
stream = rr.binary_stream()
|
80 |
|
81 |
blueprint = rrb.Blueprint(
|
82 |
rrb.Vertical(
|
|
|
103 |
|
104 |
cap = cv2.VideoCapture(path_to_video)
|
105 |
num_frames = cap.get(cv2.CAP_PROP_FRAME_COUNT)
|
106 |
+
fps_video = cap.get(cv2.CAP_PROP_FPS)
|
107 |
+
|
108 |
+
# limit the number of frames to 10 seconds of video
|
109 |
+
max_frames = min(10 * fps_video, num_frames)
|
110 |
+
|
111 |
for i in range(len(frame_timestamps_ns)):
|
112 |
+
if i >= max_frames:
|
113 |
+
raise gr.Error("Reached the maximum number of frames to process")
|
114 |
+
|
115 |
ret, frame = cap.read()
|
116 |
if not ret:
|
117 |
break
|
|
|
158 |
|
159 |
yield stream.read()
|
160 |
except Exception as e:
|
161 |
+
raise gr.Error(f"An error has occurred: {e}")
|
|
|
|
|
|
|
162 |
finally:
|
163 |
# Clean up the temporary file
|
164 |
if temp_file and os.path.exists(temp_file):
|
|
|
173 |
# DepthPro Rerun Demo
|
174 |
|
175 |
[DepthPro](https://huggingface.co/apple/DepthPro) is a fast metric depth prediction model. Simply upload a video to visualize the depth predictions in real-time.
|
176 |
+
|
177 |
High resolution videos will be automatically resized to 256x256 pixels, to speed up the inference and visualize multiple frames.
|
178 |
"""
|
179 |
)
|
180 |
with gr.Row():
|
181 |
with gr.Column(variant="compact"):
|
182 |
video = gr.Video(
|
183 |
+
format="mp4", interactive=True, label="Video", include_audio=False
|
|
|
|
|
|
|
|
|
184 |
)
|
185 |
visualize = gr.Button("Visualize ML Depth Pro")
|
186 |
with gr.Column():
|