ghost233lism commited on
Commit
7558653
·
verified ·
1 Parent(s): c8957ff

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +68 -26
app.py CHANGED
@@ -166,6 +166,11 @@ def predict_depth(input_image, colormap_choice):
166
  return None
167
 
168
 
 
 
 
 
 
169
  def predict_video_depth(input_video, colormap_choice, progress=gr.Progress()):
170
  """Main depth prediction function for videos"""
171
  if input_video is None:
@@ -298,21 +303,34 @@ with gr.Blocks(title="Depth Anything AC - Depth Estimation Demo", theme=gr.theme
298
  with gr.TabItem("📷 Image Depth Estimation"):
299
  # Main image display row with strict alignment
300
  with gr.Row():
301
- input_image = gr.Image(
302
- label="Upload Image",
303
- type="pil",
304
- height=400,
305
- container=True,
306
- scale=1
307
- )
308
 
309
- output_image = gr.Image(
310
- label="Depth Map Result",
311
- type="pil",
312
- height=400,
313
- container=True,
314
- scale=1
315
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
316
 
317
  # Controls section in a separate row
318
  with gr.Row():
@@ -351,19 +369,31 @@ with gr.Blocks(title="Depth Anything AC - Depth Estimation Demo", theme=gr.theme
351
  with gr.TabItem("🎬 Video Depth Estimation"):
352
  # Main video display row with strict alignment
353
  with gr.Row():
354
- input_video = gr.Video(
355
- label="Upload Video",
356
- height=400,
357
- container=True,
358
- scale=1
359
- )
360
 
361
- output_video = gr.Video(
362
- label="Depth Map Video Result",
363
- height=400,
364
- container=True,
365
- scale=1
366
- )
 
 
 
 
 
 
 
 
 
 
 
 
367
 
368
  # Controls section in a separate row
369
  with gr.Row():
@@ -402,6 +432,12 @@ with gr.Blocks(title="Depth Anything AC - Depth Estimation Demo", theme=gr.theme
402
  show_progress=True
403
  )
404
 
 
 
 
 
 
 
405
  video_submit_btn.click(
406
  fn=predict_video_depth,
407
  inputs=[input_video, video_colormap_choice],
@@ -409,6 +445,12 @@ with gr.Blocks(title="Depth Anything AC - Depth Estimation Demo", theme=gr.theme
409
  show_progress=True
410
  )
411
 
 
 
 
 
 
 
412
  gr.Markdown("""
413
  ## 📝 Notes
414
  - **Spectral**: Rainbow spectrum with distinct near-far contrast
 
166
  return None
167
 
168
 
169
+ def clear_results():
170
+ """Clear the output image"""
171
+ return None
172
+
173
+
174
  def predict_video_depth(input_video, colormap_choice, progress=gr.Progress()):
175
  """Main depth prediction function for videos"""
176
  if input_video is None:
 
303
  with gr.TabItem("📷 Image Depth Estimation"):
304
  # Main image display row with strict alignment
305
  with gr.Row():
306
+ with gr.Column(scale=1):
307
+ input_image = gr.Image(
308
+ label="Upload Image",
309
+ type="pil",
310
+ height=400,
311
+ container=True
312
+ )
313
 
314
+ with gr.Column(scale=1):
315
+ output_image = gr.Image(
316
+ label="Depth Map Result",
317
+ type="pil",
318
+ height=400,
319
+ container=True,
320
+ interactive=True
321
+ )
322
+ # 添加工具栏来保持高度一致
323
+ with gr.Row():
324
+ download_btn = gr.DownloadButton(
325
+ "💾 Download Depth Map",
326
+ variant="secondary",
327
+ size="sm"
328
+ )
329
+ clear_btn = gr.Button(
330
+ "🗑️ Clear Result",
331
+ variant="secondary",
332
+ size="sm"
333
+ )
334
 
335
  # Controls section in a separate row
336
  with gr.Row():
 
369
  with gr.TabItem("🎬 Video Depth Estimation"):
370
  # Main video display row with strict alignment
371
  with gr.Row():
372
+ with gr.Column(scale=1):
373
+ input_video = gr.Video(
374
+ label="Upload Video",
375
+ height=400,
376
+ container=True
377
+ )
378
 
379
+ with gr.Column(scale=1):
380
+ output_video = gr.Video(
381
+ label="Depth Map Video Result",
382
+ height=400,
383
+ container=True
384
+ )
385
+ # 添加工具栏来保持高度一致
386
+ with gr.Row():
387
+ video_download_btn = gr.DownloadButton(
388
+ "💾 Download Depth Video",
389
+ variant="secondary",
390
+ size="sm"
391
+ )
392
+ video_clear_btn = gr.Button(
393
+ "🗑️ Clear Result",
394
+ variant="secondary",
395
+ size="sm"
396
+ )
397
 
398
  # Controls section in a separate row
399
  with gr.Row():
 
432
  show_progress=True
433
  )
434
 
435
+ clear_btn.click(
436
+ fn=clear_results,
437
+ inputs=[],
438
+ outputs=output_image
439
+ )
440
+
441
  video_submit_btn.click(
442
  fn=predict_video_depth,
443
  inputs=[input_video, video_colormap_choice],
 
445
  show_progress=True
446
  )
447
 
448
+ video_clear_btn.click(
449
+ fn=clear_results,
450
+ inputs=[],
451
+ outputs=output_video
452
+ )
453
+
454
  gr.Markdown("""
455
  ## 📝 Notes
456
  - **Spectral**: Rainbow spectrum with distinct near-far contrast