guangkaixu commited on
Commit
bfac6cd
1 Parent(s): 272098b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +114 -115
app.py CHANGED
@@ -238,18 +238,73 @@ def run_demo_server(pipe_depth, pipe_normal, pipe_dis):
238
  )
239
 
240
  with gr.Tabs(elem_classes=["tabs"]):
241
- # with gr.Tab("Depth"):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
242
  # with gr.Row():
243
  # with gr.Column():
244
- # depth_image_input = gr.Image(
245
  # label="Input Image",
246
  # type="filepath",
247
  # )
248
  # with gr.Row():
249
- # depth_image_submit_btn = gr.Button(
250
- # value="Estimate Depth", variant="primary"
251
  # )
252
- # depth_image_reset_btn = gr.Button(value="Reset")
253
  # with gr.Accordion("Advanced options", open=False):
254
  # image_processing_res = gr.Radio(
255
  # [
@@ -260,8 +315,8 @@ def run_demo_server(pipe_depth, pipe_normal, pipe_dis):
260
  # value=default_image_processing_res,
261
  # )
262
  # with gr.Column():
263
- # depth_image_output_slider = ImageSlider(
264
- # label="Predicted depth of gray / color (red-near, blue-far)",
265
  # type="filepath",
266
  # show_download_button=True,
267
  # show_share_button=True,
@@ -269,82 +324,26 @@ def run_demo_server(pipe_depth, pipe_normal, pipe_dis):
269
  # elem_classes="slider",
270
  # position=0.25,
271
  # )
272
- # depth_image_output_files = gr.Files(
273
- # label="Depth outputs",
274
  # elem_id="download",
275
  # interactive=False,
276
  # )
277
 
278
  # filenames = []
279
- # filenames.extend(["anime_%d.jpg" %(i+1) for i in range(7)])
280
- # filenames.extend(["line_%d.jpg" %(i+1) for i in range(6)])
281
- # filenames.extend(["real_%d.jpg" %(i+1) for i in range(24)])
282
-
283
  # example_folder = os.path.join(os.path.dirname(__file__), "./images")
284
  # Examples(
285
- # fn=process_pipe_depth,
286
  # examples=[
287
- # os.path.join(example_folder, "depth", name)
288
  # for name in filenames
289
  # ],
290
- # inputs=[depth_image_input],
291
- # outputs=[depth_image_output_slider, depth_image_output_files],
292
  # cache_examples=True,
293
- # directory_name="examples_image",
294
  # )
295
-
296
- with gr.Tab("Normal"):
297
- with gr.Row():
298
- with gr.Column():
299
- normal_image_input = gr.Image(
300
- label="Input Image",
301
- type="filepath",
302
- )
303
- with gr.Row():
304
- normal_image_submit_btn = gr.Button(
305
- value="Estimate Normal", variant="primary"
306
- )
307
- normal_image_reset_btn = gr.Button(value="Reset")
308
- with gr.Accordion("Advanced options", open=False):
309
- image_processing_res = gr.Radio(
310
- [
311
- ("Native", 0),
312
- ("Recommended", 768),
313
- ],
314
- label="Processing resolution",
315
- value=default_image_processing_res,
316
- )
317
- with gr.Column():
318
- normal_image_output_slider = ImageSlider(
319
- label="Predicted surface normal",
320
- type="filepath",
321
- show_download_button=True,
322
- show_share_button=True,
323
- interactive=False,
324
- elem_classes="slider",
325
- position=0.25,
326
- )
327
- normal_image_output_files = gr.Files(
328
- label="Normal outputs",
329
- elem_id="download",
330
- interactive=False,
331
- )
332
-
333
- filenames = []
334
- filenames.extend(["%d.jpg" %(i+1) for i in range(10)])
335
- example_folder = os.path.join(os.path.dirname(__file__), "./images")
336
- print('example_folder :', example_folder)
337
- Examples(
338
- fn=process_pipe_normal,
339
- examples=[
340
- os.path.join(example_folder, "normal", name)
341
- for name in filenames
342
- ],
343
- inputs=[normal_image_input],
344
- outputs=[normal_image_output_slider, normal_image_output_files],
345
- # cache_examples=True,
346
- # directory_name="examples_image",
347
- )
348
 
349
  # with gr.Tab("Dichotomous Segmentation"):
350
  # with gr.Row():
@@ -395,61 +394,28 @@ def run_demo_server(pipe_depth, pipe_normal, pipe_dis):
395
  # inputs=[dis_image_input],
396
  # outputs=[dis_image_output_slider, dis_image_output_files],
397
  # cache_examples=True,
398
- # directory_name="examples_image",
399
  # )
400
 
401
 
402
- # ### Image tab
403
- # depth_image_submit_btn.click(
404
- # fn=process_image_check,
405
- # inputs=depth_image_input,
406
- # outputs=None,
407
- # preprocess=False,
408
- # queue=False,
409
- # ).success(
410
- # fn=process_pipe_depth,
411
- # inputs=[
412
- # depth_image_input,
413
- # image_processing_res,
414
- # ],
415
- # outputs=[depth_image_output_slider, depth_image_output_files],
416
- # concurrency_limit=1,
417
- # )
418
-
419
- # depth_image_reset_btn.click(
420
- # fn=lambda: (
421
- # None,
422
- # None,
423
- # None,
424
- # default_image_processing_res,
425
- # ),
426
- # inputs=[],
427
- # outputs=[
428
- # depth_image_input,
429
- # depth_image_output_slider,
430
- # depth_image_output_files,
431
- # image_processing_res,
432
- # ],
433
- # queue=False,
434
- # )
435
-
436
- normal_image_submit_btn.click(
437
  fn=process_image_check,
438
- inputs=normal_image_input,
439
  outputs=None,
440
  preprocess=False,
441
  queue=False,
442
  ).success(
443
- fn=process_pipe_normal,
444
  inputs=[
445
- normal_image_input,
446
  image_processing_res,
447
  ],
448
- outputs=[normal_image_output_slider, normal_image_output_files],
449
  concurrency_limit=1,
450
  )
451
 
452
- normal_image_reset_btn.click(
453
  fn=lambda: (
454
  None,
455
  None,
@@ -458,14 +424,47 @@ def run_demo_server(pipe_depth, pipe_normal, pipe_dis):
458
  ),
459
  inputs=[],
460
  outputs=[
461
- normal_image_input,
462
- normal_image_output_slider,
463
- normal_image_output_files,
464
  image_processing_res,
465
  ],
466
  queue=False,
467
  )
468
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
469
  # dis_image_submit_btn.click(
470
  # fn=process_image_check,
471
  # inputs=dis_image_input,
 
238
  )
239
 
240
  with gr.Tabs(elem_classes=["tabs"]):
241
+ with gr.Tab("Depth"):
242
+ with gr.Row():
243
+ with gr.Column():
244
+ depth_image_input = gr.Image(
245
+ label="Input Image",
246
+ type="filepath",
247
+ )
248
+ with gr.Row():
249
+ depth_image_submit_btn = gr.Button(
250
+ value="Estimate Depth", variant="primary"
251
+ )
252
+ depth_image_reset_btn = gr.Button(value="Reset")
253
+ with gr.Accordion("Advanced options", open=False):
254
+ image_processing_res = gr.Radio(
255
+ [
256
+ ("Native", 0),
257
+ ("Recommended", 768),
258
+ ],
259
+ label="Processing resolution",
260
+ value=default_image_processing_res,
261
+ )
262
+ with gr.Column():
263
+ depth_image_output_slider = ImageSlider(
264
+ label="Predicted depth of gray / color (red-near, blue-far)",
265
+ type="filepath",
266
+ show_download_button=True,
267
+ show_share_button=True,
268
+ interactive=False,
269
+ elem_classes="slider",
270
+ position=0.25,
271
+ )
272
+ depth_image_output_files = gr.Files(
273
+ label="Depth outputs",
274
+ elem_id="download",
275
+ interactive=False,
276
+ )
277
+
278
+ filenames = []
279
+ filenames.extend(["anime_%d.jpg" %(i+1) for i in range(7)])
280
+ filenames.extend(["line_%d.jpg" %(i+1) for i in range(6)])
281
+ filenames.extend(["real_%d.jpg" %(i+1) for i in range(24)])
282
+
283
+ example_folder = os.path.join(os.path.dirname(__file__), "./images")
284
+ Examples(
285
+ fn=process_pipe_depth,
286
+ examples=[
287
+ os.path.join(example_folder, "depth", name)
288
+ for name in filenames
289
+ ],
290
+ inputs=[depth_image_input],
291
+ outputs=[depth_image_output_slider, depth_image_output_files],
292
+ cache_examples=True,
293
+ directory_name="examples_depth",
294
+ )
295
+
296
+ # with gr.Tab("Normal"):
297
  # with gr.Row():
298
  # with gr.Column():
299
+ # normal_image_input = gr.Image(
300
  # label="Input Image",
301
  # type="filepath",
302
  # )
303
  # with gr.Row():
304
+ # normal_image_submit_btn = gr.Button(
305
+ # value="Estimate Normal", variant="primary"
306
  # )
307
+ # normal_image_reset_btn = gr.Button(value="Reset")
308
  # with gr.Accordion("Advanced options", open=False):
309
  # image_processing_res = gr.Radio(
310
  # [
 
315
  # value=default_image_processing_res,
316
  # )
317
  # with gr.Column():
318
+ # normal_image_output_slider = ImageSlider(
319
+ # label="Predicted surface normal",
320
  # type="filepath",
321
  # show_download_button=True,
322
  # show_share_button=True,
 
324
  # elem_classes="slider",
325
  # position=0.25,
326
  # )
327
+ # normal_image_output_files = gr.Files(
328
+ # label="Normal outputs",
329
  # elem_id="download",
330
  # interactive=False,
331
  # )
332
 
333
  # filenames = []
334
+ # filenames.extend(["%d.jpg" %(i+1) for i in range(10)])
 
 
 
335
  # example_folder = os.path.join(os.path.dirname(__file__), "./images")
336
  # Examples(
337
+ # fn=process_pipe_normal,
338
  # examples=[
339
+ # os.path.join(example_folder, "normal", name)
340
  # for name in filenames
341
  # ],
342
+ # inputs=[normal_image_input],
343
+ # outputs=[normal_image_output_slider, normal_image_output_files],
344
  # cache_examples=True,
345
+ # directory_name="examples_normal",
346
  # )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
347
 
348
  # with gr.Tab("Dichotomous Segmentation"):
349
  # with gr.Row():
 
394
  # inputs=[dis_image_input],
395
  # outputs=[dis_image_output_slider, dis_image_output_files],
396
  # cache_examples=True,
397
+ # directory_name="examples_dis",
398
  # )
399
 
400
 
401
+ ### Image tab
402
+ depth_image_submit_btn.click(
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
403
  fn=process_image_check,
404
+ inputs=depth_image_input,
405
  outputs=None,
406
  preprocess=False,
407
  queue=False,
408
  ).success(
409
+ fn=process_pipe_depth,
410
  inputs=[
411
+ depth_image_input,
412
  image_processing_res,
413
  ],
414
+ outputs=[depth_image_output_slider, depth_image_output_files],
415
  concurrency_limit=1,
416
  )
417
 
418
+ depth_image_reset_btn.click(
419
  fn=lambda: (
420
  None,
421
  None,
 
424
  ),
425
  inputs=[],
426
  outputs=[
427
+ depth_image_input,
428
+ depth_image_output_slider,
429
+ depth_image_output_files,
430
  image_processing_res,
431
  ],
432
  queue=False,
433
  )
434
 
435
+ # normal_image_submit_btn.click(
436
+ # fn=process_image_check,
437
+ # inputs=normal_image_input,
438
+ # outputs=None,
439
+ # preprocess=False,
440
+ # queue=False,
441
+ # ).success(
442
+ # fn=process_pipe_normal,
443
+ # inputs=[
444
+ # normal_image_input,
445
+ # image_processing_res,
446
+ # ],
447
+ # outputs=[normal_image_output_slider, normal_image_output_files],
448
+ # concurrency_limit=1,
449
+ # )
450
+
451
+ # normal_image_reset_btn.click(
452
+ # fn=lambda: (
453
+ # None,
454
+ # None,
455
+ # None,
456
+ # default_image_processing_res,
457
+ # ),
458
+ # inputs=[],
459
+ # outputs=[
460
+ # normal_image_input,
461
+ # normal_image_output_slider,
462
+ # normal_image_output_files,
463
+ # image_processing_res,
464
+ # ],
465
+ # queue=False,
466
+ # )
467
+
468
  # dis_image_submit_btn.click(
469
  # fn=process_image_check,
470
  # inputs=dis_image_input,