Update app.py
Browse files
app.py
CHANGED
|
@@ -17,7 +17,11 @@ model_configs = {
|
|
| 17 |
'vitl': {'encoder': 'vitl', 'features': 256, 'out_channels': [256, 512, 1024, 1024]},
|
| 18 |
}
|
| 19 |
|
| 20 |
-
encoder2name = {
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
encoder='vitl'
|
| 22 |
model_name = encoder2name[encoder]
|
| 23 |
|
|
@@ -28,9 +32,33 @@ video_depth_anything = video_depth_anything.to(DEVICE).eval()
|
|
| 28 |
|
| 29 |
|
| 30 |
@spaces.GPU(duration=240)
|
| 31 |
-
def infer_video_depth(
|
| 32 |
-
|
| 33 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
frames, target_fps = read_video_frames(input_video, max_len, target_fps, max_res)
|
| 35 |
depths, fps = video_depth_anything.infer_video_depth(frames, target_fps, input_size=input_size, device=DEVICE)
|
| 36 |
|
|
@@ -45,57 +73,248 @@ def infer_video_depth(input_video: str, max_len: int = -1, target_fps: int = -1,
|
|
| 45 |
|
| 46 |
gc.collect()
|
| 47 |
torch.cuda.empty_cache()
|
|
|
|
| 48 |
return [processed_video_path, depth_vis_path]
|
| 49 |
|
| 50 |
|
| 51 |
-
# CUSTOM THEME - Copy this to any app for consistent styling
|
| 52 |
-
custom_theme = gr.themes.Base(
|
| 53 |
-
primary_hue="orange",
|
| 54 |
-
secondary_hue="gray",
|
| 55 |
-
neutral_hue="slate",
|
| 56 |
-
).set(
|
| 57 |
-
body_background_fill="*neutral_950",
|
| 58 |
-
body_background_fill_dark="*neutral_950",
|
| 59 |
-
button_primary_background_fill="orange",
|
| 60 |
-
button_primary_background_fill_hover="*orange_600",
|
| 61 |
-
button_primary_text_color="white",
|
| 62 |
-
)
|
| 63 |
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 67 |
gr.Markdown("""
|
| 68 |
-
#
|
| 69 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 70 |
""")
|
| 71 |
|
| 72 |
with gr.Row():
|
| 73 |
-
with gr.Column():
|
| 74 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 75 |
|
| 76 |
-
|
| 77 |
-
|
|
|
|
|
|
|
| 78 |
target_fps = gr.Slider(-1, 30, label="Target FPS", value=15, step=1)
|
| 79 |
-
max_res = gr.Slider(480, 1920, label="Max Resolution", value=1280, step=1)
|
| 80 |
grayscale = gr.Checkbox(label="Grayscale Output", value=False)
|
| 81 |
|
| 82 |
-
generate_btn = gr.Button("
|
| 83 |
-
|
| 84 |
-
with gr.Column():
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 88 |
generate_btn.click(
|
| 89 |
fn=infer_video_depth,
|
| 90 |
inputs=[input_video, max_len, target_fps, max_res, grayscale],
|
| 91 |
-
outputs=[video_output,
|
| 92 |
)
|
| 93 |
|
| 94 |
gr.Markdown("""
|
| 95 |
-
---
|
| 96 |
-
|
|
|
|
|
|
|
|
|
|
| 97 |
""")
|
| 98 |
|
|
|
|
| 99 |
if __name__ == "__main__":
|
| 100 |
-
demo.launch(share=True)
|
| 101 |
-
|
|
|
|
| 17 |
'vitl': {'encoder': 'vitl', 'features': 256, 'out_channels': [256, 512, 1024, 1024]},
|
| 18 |
}
|
| 19 |
|
| 20 |
+
encoder2name = {
|
| 21 |
+
'vits': 'Small',
|
| 22 |
+
'vitl': 'Large',
|
| 23 |
+
}
|
| 24 |
+
|
| 25 |
encoder='vitl'
|
| 26 |
model_name = encoder2name[encoder]
|
| 27 |
|
|
|
|
| 32 |
|
| 33 |
|
| 34 |
@spaces.GPU(duration=240)
|
| 35 |
+
def infer_video_depth(
|
| 36 |
+
input_video: str,
|
| 37 |
+
max_len: int = -1,
|
| 38 |
+
target_fps: int = -1,
|
| 39 |
+
max_res: int = 1280,
|
| 40 |
+
grayscale: bool = False,
|
| 41 |
+
output_dir: str = './outputs',
|
| 42 |
+
input_size: int = 518,
|
| 43 |
+
):
|
| 44 |
+
"""
|
| 45 |
+
Generate depth maps from input video.
|
| 46 |
+
|
| 47 |
+
This function processes the input video to generate corresponding depth maps
|
| 48 |
+
using the Video Depth Anything model.
|
| 49 |
+
|
| 50 |
+
Args:
|
| 51 |
+
input_video (str): Path to the input video file
|
| 52 |
+
max_len (int): Maximum number of frames to process
|
| 53 |
+
target_fps (int): Target frames per second for processing
|
| 54 |
+
max_res (int): Maximum resolution for processing
|
| 55 |
+
grayscale (bool): Whether to output in grayscale
|
| 56 |
+
output_dir (str): Directory to save output videos
|
| 57 |
+
input_size (int): Input size for the model
|
| 58 |
+
|
| 59 |
+
Returns:
|
| 60 |
+
List[str]: Paths to the processed video and depth visualization
|
| 61 |
+
"""
|
| 62 |
frames, target_fps = read_video_frames(input_video, max_len, target_fps, max_res)
|
| 63 |
depths, fps = video_depth_anything.infer_video_depth(frames, target_fps, input_size=input_size, device=DEVICE)
|
| 64 |
|
|
|
|
| 73 |
|
| 74 |
gc.collect()
|
| 75 |
torch.cuda.empty_cache()
|
| 76 |
+
|
| 77 |
return [processed_video_path, depth_vis_path]
|
| 78 |
|
| 79 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 80 |
|
| 81 |
+
|
| 82 |
+
with gr.Blocks(
|
| 83 |
+
delete_cache=(600, 600),
|
| 84 |
+
css="""
|
| 85 |
+
.gradio-container {
|
| 86 |
+
background: #1A1A1A !important;
|
| 87 |
+
color: #CCCCCC !important;
|
| 88 |
+
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif !important;
|
| 89 |
+
}
|
| 90 |
+
|
| 91 |
+
.gradio-container .footer,
|
| 92 |
+
.gradio-container footer,
|
| 93 |
+
.gradio-container [data-testid="footer"],
|
| 94 |
+
.gradio-container .gradio-footer {
|
| 95 |
+
display: none !important;
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
.gradio-container .gradio-container {
|
| 99 |
+
padding-bottom: 0 !important;
|
| 100 |
+
}
|
| 101 |
+
|
| 102 |
+
.gradio-container h1, .gradio-container h2, .gradio-container h3 {
|
| 103 |
+
color: #FFFFFF !important;
|
| 104 |
+
font-weight: bold !important;
|
| 105 |
+
}
|
| 106 |
+
|
| 107 |
+
.gradio-container .markdown {
|
| 108 |
+
color: #CCCCCC !important;
|
| 109 |
+
}
|
| 110 |
+
|
| 111 |
+
.gradio-container .tab-nav {
|
| 112 |
+
background: #2C2C2C !important;
|
| 113 |
+
border: none !important;
|
| 114 |
+
}
|
| 115 |
+
|
| 116 |
+
.gradio-container .tab-nav button {
|
| 117 |
+
background: #2C2C2C !important;
|
| 118 |
+
color: #CCCCCC !important;
|
| 119 |
+
border: none !important;
|
| 120 |
+
border-radius: 8px 8px 0 0 !important;
|
| 121 |
+
}
|
| 122 |
+
|
| 123 |
+
.gradio-container .tab-nav button.selected {
|
| 124 |
+
background: #FF8C00 !important;
|
| 125 |
+
color: #FFFFFF !important;
|
| 126 |
+
}
|
| 127 |
+
|
| 128 |
+
.gradio-container .tab-nav button:hover {
|
| 129 |
+
background: #3C3C3C !important;
|
| 130 |
+
}
|
| 131 |
+
|
| 132 |
+
.gradio-container .tab-nav button.selected:hover {
|
| 133 |
+
background: #FF8C00 !important;
|
| 134 |
+
}
|
| 135 |
+
|
| 136 |
+
.gradio-container .tab-content {
|
| 137 |
+
background: #2C2C2C !important;
|
| 138 |
+
border: none !important;
|
| 139 |
+
border-radius: 0 0 8px 8px !important;
|
| 140 |
+
padding: 20px !important;
|
| 141 |
+
}
|
| 142 |
+
|
| 143 |
+
.gradio-container .accordion {
|
| 144 |
+
background: #2C2C2C !important;
|
| 145 |
+
border: 1px solid #3C3C3C !important;
|
| 146 |
+
border-radius: 8px !important;
|
| 147 |
+
margin: 10px 0 !important;
|
| 148 |
+
}
|
| 149 |
+
|
| 150 |
+
.gradio-container .accordion .accordion-header {
|
| 151 |
+
background: #2C2C2C !important;
|
| 152 |
+
color: #FFFFFF !important;
|
| 153 |
+
border: none !important;
|
| 154 |
+
border-radius: 8px !important;
|
| 155 |
+
}
|
| 156 |
+
|
| 157 |
+
.gradio-container .accordion .accordion-content {
|
| 158 |
+
background: #2C2C2C !important;
|
| 159 |
+
color: #CCCCCC !important;
|
| 160 |
+
border: none !important;
|
| 161 |
+
border-radius: 0 0 8px 8px !important;
|
| 162 |
+
}
|
| 163 |
+
|
| 164 |
+
.gradio-container .button {
|
| 165 |
+
background: #FF8C00 !important;
|
| 166 |
+
color: #FFFFFF !important;
|
| 167 |
+
border: none !important;
|
| 168 |
+
border-radius: 8px !important;
|
| 169 |
+
font-weight: bold !important;
|
| 170 |
+
padding: 12px 24px !important;
|
| 171 |
+
}
|
| 172 |
+
|
| 173 |
+
.gradio-container .button:hover {
|
| 174 |
+
background: #FF9F33 !important;
|
| 175 |
+
}
|
| 176 |
+
|
| 177 |
+
.gradio-container .button.secondary {
|
| 178 |
+
background: #3C3C3C !important;
|
| 179 |
+
color: #CCCCCC !important;
|
| 180 |
+
}
|
| 181 |
|
| 182 |
+
.gradio-container .button.secondary:hover {
|
| 183 |
+
background: #4C4C4C !important;
|
| 184 |
+
}
|
| 185 |
+
|
| 186 |
+
.gradio-container .slider {
|
| 187 |
+
background: #3C3C3C !important;
|
| 188 |
+
}
|
| 189 |
+
|
| 190 |
+
.gradio-container .slider .slider-handle {
|
| 191 |
+
background: #FF8C00 !important;
|
| 192 |
+
border: 2px solid #FFFFFF !important;
|
| 193 |
+
}
|
| 194 |
+
|
| 195 |
+
.gradio-container .slider .slider-track {
|
| 196 |
+
background: #3C3C3C !important;
|
| 197 |
+
}
|
| 198 |
+
|
| 199 |
+
.gradio-container .slider .slider-track-fill {
|
| 200 |
+
background: #FF8C00 !important;
|
| 201 |
+
}
|
| 202 |
+
|
| 203 |
+
.gradio-container .checkbox {
|
| 204 |
+
color: #CCCCCC !important;
|
| 205 |
+
}
|
| 206 |
+
|
| 207 |
+
.gradio-container .radio {
|
| 208 |
+
color: #CCCCCC !important;
|
| 209 |
+
}
|
| 210 |
+
|
| 211 |
+
.gradio-container .gallery {
|
| 212 |
+
background: #2C2C2C !important;
|
| 213 |
+
border: 1px solid #3C3C3C !important;
|
| 214 |
+
border-radius: 8px !important;
|
| 215 |
+
}
|
| 216 |
+
|
| 217 |
+
.gradio-container .image {
|
| 218 |
+
background: #2C2C2C !important;
|
| 219 |
+
border: 1px solid #3C3C3C !important;
|
| 220 |
+
border-radius: 8px !important;
|
| 221 |
+
}
|
| 222 |
+
|
| 223 |
+
.gradio-container .video {
|
| 224 |
+
background: #2C2C2C !important;
|
| 225 |
+
border: 1px solid #3C3C3C !important;
|
| 226 |
+
border-radius: 8px !important;
|
| 227 |
+
}
|
| 228 |
+
|
| 229 |
+
.gradio-container .model3d {
|
| 230 |
+
background: #2C2C2C !important;
|
| 231 |
+
border: 1px solid #3C3C3C !important;
|
| 232 |
+
border-radius: 8px !important;
|
| 233 |
+
}
|
| 234 |
+
|
| 235 |
+
.gradio-container .row {
|
| 236 |
+
gap: 20px !important;
|
| 237 |
+
}
|
| 238 |
+
|
| 239 |
+
.gradio-container .column {
|
| 240 |
+
background: #2C2C2C !important;
|
| 241 |
+
border: 1px solid #3C3C3C !important;
|
| 242 |
+
border-radius: 8px !important;
|
| 243 |
+
padding: 20px !important;
|
| 244 |
+
}
|
| 245 |
+
|
| 246 |
+
.gradio-container .row {
|
| 247 |
+
align-items: flex-start !important;
|
| 248 |
+
justify-content: center !important;
|
| 249 |
+
}
|
| 250 |
+
|
| 251 |
+
.gradio-container .container {
|
| 252 |
+
max-width: 1200px !important;
|
| 253 |
+
margin: 0 auto !important;
|
| 254 |
+
padding: 20px !important;
|
| 255 |
+
}
|
| 256 |
+
"""
|
| 257 |
+
) as demo:
|
| 258 |
gr.Markdown("""
|
| 259 |
+
<div style="text-align: center; margin-bottom: 30px; padding: 20px; background: #2C2C2C; border: 1px solid #3C3C3C; border-radius: 8px;">
|
| 260 |
+
<h3 style="color: #FFFFFF; margin-bottom: 15px;">Instructions</h3>
|
| 261 |
+
<p style="color: #CCCCCC; margin-bottom: 10px;">
|
| 262 |
+
• Upload a video and click "Generate Depth" to create depth maps
|
| 263 |
+
</p>
|
| 264 |
+
<p style="color: #CCCCCC; margin-bottom: 10px;">
|
| 265 |
+
• Adjust settings in Generation Settings for optimal results
|
| 266 |
+
</p>
|
| 267 |
+
<p style="color: #CCCCCC;">
|
| 268 |
+
• Download the processed video and depth visualization
|
| 269 |
+
</p>
|
| 270 |
+
</div>
|
| 271 |
""")
|
| 272 |
|
| 273 |
with gr.Row():
|
| 274 |
+
with gr.Column(scale=1):
|
| 275 |
+
gr.Markdown("""
|
| 276 |
+
<div style="background: #2C2C2C; border: 1px solid #3C3C3C; border-radius: 8px; padding: 20px; margin-bottom: 20px;">
|
| 277 |
+
<h3 style="color: #FFFFFF; margin-bottom: 15px;">Video Depth Generation</h3>
|
| 278 |
+
<p style="color: #CCCCCC; margin-bottom: 20px;">Generate depth maps from video content for compositing and 3D effects.</p>
|
| 279 |
+
</div>
|
| 280 |
+
""")
|
| 281 |
|
| 282 |
+
input_video = gr.Video(label="Input Video", height=300)
|
| 283 |
+
|
| 284 |
+
with gr.Accordion(label="Generation Settings", open=False):
|
| 285 |
+
max_len = gr.Slider(0, 1000, label="Max Process Length", value=500, step=1)
|
| 286 |
target_fps = gr.Slider(-1, 30, label="Target FPS", value=15, step=1)
|
| 287 |
+
max_res = gr.Slider(480, 1920, label="Max Side Resolution", value=1280, step=1)
|
| 288 |
grayscale = gr.Checkbox(label="Grayscale Output", value=False)
|
| 289 |
|
| 290 |
+
generate_btn = gr.Button("Generate Depth", variant="primary", size="lg")
|
| 291 |
+
|
| 292 |
+
with gr.Column(scale=1):
|
| 293 |
+
gr.Markdown("""
|
| 294 |
+
<div style="background: #2C2C2C; border: 1px solid #3C3C3C; border-radius: 8px; padding: 20px; margin-bottom: 20px;">
|
| 295 |
+
<h3 style="color: #FFFFFF; margin-bottom: 15px;">Generated Depth Maps</h3>
|
| 296 |
+
<p style="color: #CCCCCC; margin-bottom: 20px;">Preview and download your generated depth maps.</p>
|
| 297 |
+
</div>
|
| 298 |
+
""")
|
| 299 |
+
|
| 300 |
+
video_output = gr.Video(label="Generated 3D Asset", autoplay=True, loop=True, height=300)
|
| 301 |
+
model_output = gr.Video(label="Generated Depth Video", autoplay=True, loop=True, height=300)
|
| 302 |
+
|
| 303 |
+
|
| 304 |
generate_btn.click(
|
| 305 |
fn=infer_video_depth,
|
| 306 |
inputs=[input_video, max_len, target_fps, max_res, grayscale],
|
| 307 |
+
outputs=[video_output, model_output],
|
| 308 |
)
|
| 309 |
|
| 310 |
gr.Markdown("""
|
| 311 |
+
<div style="text-align: center; margin-top: 40px; padding: 20px; background: #2C2C2C; border: 1px solid #3C3C3C; border-radius: 8px;">
|
| 312 |
+
<p style="color: #CCCCCC; font-size: 0.9rem; margin: 0;">
|
| 313 |
+
Powered by <span style="color: #FF8C00;">Mean Cat Entertainment</span> • Built for the future of VFX
|
| 314 |
+
</p>
|
| 315 |
+
</div>
|
| 316 |
""")
|
| 317 |
|
| 318 |
+
# Launch the Gradio app
|
| 319 |
if __name__ == "__main__":
|
| 320 |
+
demo.launch(share=True)
|
|
|