ses7720 commited on
Commit
dd7d8fb
·
verified ·
1 Parent(s): 5dac8ab

Update CURE Gradio demo

Browse files
Files changed (1) hide show
  1. app.py +51 -4
app.py CHANGED
@@ -297,6 +297,42 @@ def _example_picker(
297
  )
298
 
299
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
300
  def build_demo() -> gr.Blocks:
301
  with gr.Blocks(title="CURE · Controllable Image Restoration") as interface:
302
  gr.Markdown(
@@ -368,7 +404,7 @@ def build_demo() -> gr.Blocks:
368
  label="Known source degradation",
369
  )
370
  selective_factors = gr.CheckboxGroup(
371
- ["low", "haze"],
372
  value=["haze"],
373
  label="Factors to remove",
374
  )
@@ -378,7 +414,11 @@ def build_demo() -> gr.Blocks:
378
  selective_factors,
379
  )
380
  selective_button = gr.Button("Remove selected factors", variant="primary")
381
- _example_picker(selective_input, selective_source, COMPOSITE_PROMPTS)
 
 
 
 
382
  selective_status = gr.Textbox(label="Run information", interactive=False)
383
  selective_button.click(
384
  run_selective,
@@ -417,8 +457,11 @@ def build_demo() -> gr.Blocks:
417
  label="Two-factor source degradation",
418
  )
419
  initial_orders = _order_choices("low_haze")
 
 
 
420
  twostage_order = gr.Radio(
421
- initial_orders,
422
  value=initial_orders[0],
423
  label="Removal order",
424
  )
@@ -428,7 +471,11 @@ def build_demo() -> gr.Blocks:
428
  twostage_order,
429
  )
430
  twostage_button = gr.Button("Run two stages", variant="primary")
431
- _example_picker(twostage_input, twostage_source, TWO_FACTOR_PROMPTS)
 
 
 
 
432
  twostage_status = gr.Textbox(label="Run information", interactive=False)
433
  twostage_button.click(
434
  run_twostage,
 
297
  )
298
 
299
 
300
+ def _selective_example_picker(
301
+ image_input: gr.Image,
302
+ source_input: gr.Dropdown,
303
+ factors_input: gr.CheckboxGroup,
304
+ ) -> gr.Examples:
305
+ available = tuple(prompt for prompt in COMPOSITE_PROMPTS if _example_path(prompt))
306
+ return gr.Examples(
307
+ examples=[
308
+ [_example_path(prompt), prompt, [prompt.split("_")[-1]]] for prompt in available
309
+ ],
310
+ inputs=[image_input, source_input, factors_input],
311
+ example_labels=[prompt.replace("_", " + ") for prompt in available],
312
+ examples_per_page=len(available),
313
+ label="CCDD-11 sample images · click to use",
314
+ show_api=False,
315
+ )
316
+
317
+
318
+ def _twostage_example_picker(
319
+ image_input: gr.Image,
320
+ source_input: gr.Dropdown,
321
+ order_input: gr.Radio,
322
+ ) -> gr.Examples:
323
+ available = tuple(prompt for prompt in TWO_FACTOR_PROMPTS if _example_path(prompt))
324
+ return gr.Examples(
325
+ examples=[
326
+ [_example_path(prompt), prompt, _order_choices(prompt)[0]] for prompt in available
327
+ ],
328
+ inputs=[image_input, source_input, order_input],
329
+ example_labels=[prompt.replace("_", " + ") for prompt in available],
330
+ examples_per_page=len(available),
331
+ label="CCDD-11 sample images · click to use",
332
+ show_api=False,
333
+ )
334
+
335
+
336
  def build_demo() -> gr.Blocks:
337
  with gr.Blocks(title="CURE · Controllable Image Restoration") as interface:
338
  gr.Markdown(
 
404
  label="Known source degradation",
405
  )
406
  selective_factors = gr.CheckboxGroup(
407
+ ["low", "haze", "rain", "snow"],
408
  value=["haze"],
409
  label="Factors to remove",
410
  )
 
414
  selective_factors,
415
  )
416
  selective_button = gr.Button("Remove selected factors", variant="primary")
417
+ _selective_example_picker(
418
+ selective_input,
419
+ selective_source,
420
+ selective_factors,
421
+ )
422
  selective_status = gr.Textbox(label="Run information", interactive=False)
423
  selective_button.click(
424
  run_selective,
 
457
  label="Two-factor source degradation",
458
  )
459
  initial_orders = _order_choices("low_haze")
460
+ all_orders = tuple(
461
+ order for prompt in TWO_FACTOR_PROMPTS for order in _order_choices(prompt)
462
+ )
463
  twostage_order = gr.Radio(
464
+ all_orders,
465
  value=initial_orders[0],
466
  label="Removal order",
467
  )
 
471
  twostage_order,
472
  )
473
  twostage_button = gr.Button("Run two stages", variant="primary")
474
+ _twostage_example_picker(
475
+ twostage_input,
476
+ twostage_source,
477
+ twostage_order,
478
+ )
479
  twostage_status = gr.Textbox(label="Run information", interactive=False)
480
  twostage_button.click(
481
  run_twostage,