gheinrich commited on
Commit
c9c896d
·
1 Parent(s): 904bf44

Make app compatible with Gradio 6 (Space) and 4.x (local)

Browse files

- Drop show_download_button from Gallery/Image (removed in Gradio 6; download shown by default)
- Move NVIDIA-green theme to launch() on Gradio 6, keep on Blocks for <6
- Version-detect via gr.__version__ to support both

Files changed (1) hide show
  1. app.py +28 -28
app.py CHANGED
@@ -402,7 +402,7 @@ def generate(
402
  )
403
 
404
 
405
- def build_demo() -> gr.Blocks:
406
  nvidia_green = gr.themes.Color(
407
  c50="#f3f9e6",
408
  c100="#e3f1c2",
@@ -416,8 +416,19 @@ def build_demo() -> gr.Blocks:
416
  c900="#2a4200",
417
  c950="#1a2900",
418
  )
419
- theme = gr.themes.Soft(primary_hue=nvidia_green, secondary_hue=nvidia_green)
420
- with gr.Blocks(title="Nemotron Labs Diffusion Image", theme=theme) as demo:
 
 
 
 
 
 
 
 
 
 
 
421
  gr.Markdown(
422
  "# Nemotron Labs Diffusion Image\n\n"
423
  "NL-Diffusion-Image generates high-resolution images via **masked discrete diffusion** "
@@ -547,9 +558,7 @@ def build_demo() -> gr.Blocks:
547
  columns=3,
548
  height="auto",
549
  object_fit="contain",
550
- show_label=False,
551
- show_download_button=True,
552
- )
553
 
554
  gr.Markdown(
555
  "### Generation speed\n\n"
@@ -560,9 +569,7 @@ def build_demo() -> gr.Blocks:
560
  gr.Image(
561
  value=_asset("speed_comparison.gif"),
562
  show_label=False,
563
- interactive=False,
564
- show_download_button=True,
565
- )
566
 
567
  with gr.Row(equal_height=True):
568
  with gr.Column(scale=1):
@@ -577,9 +584,7 @@ def build_demo() -> gr.Blocks:
577
  gr.Image(
578
  value=_asset("architecture.png"),
579
  show_label=False,
580
- interactive=False,
581
- show_download_button=True,
582
- )
583
 
584
  with gr.Row(equal_height=True):
585
  with gr.Column(scale=1):
@@ -593,9 +598,7 @@ def build_demo() -> gr.Blocks:
593
  gr.Image(
594
  value=_asset("benchmarks.png"),
595
  show_label=False,
596
- interactive=False,
597
- show_download_button=True,
598
- )
599
 
600
  gr.Markdown("### Key findings")
601
 
@@ -610,9 +613,7 @@ def build_demo() -> gr.Blocks:
610
  gr.Image(
611
  value=_asset("token_editing.png"),
612
  show_label=False,
613
- interactive=False,
614
- show_download_button=True,
615
- )
616
 
617
  with gr.Row(equal_height=True):
618
  with gr.Column(scale=1):
@@ -627,9 +628,7 @@ def build_demo() -> gr.Blocks:
627
  gr.Image(
628
  value=_asset("gce_objective.png"),
629
  show_label=False,
630
- interactive=False,
631
- show_download_button=True,
632
- )
633
 
634
  with gr.Row(equal_height=True):
635
  with gr.Column(scale=1):
@@ -643,9 +642,7 @@ def build_demo() -> gr.Blocks:
643
  gr.Image(
644
  value=_asset("few_step_generation.png"),
645
  show_label=False,
646
- interactive=False,
647
- show_download_button=True,
648
- )
649
 
650
  gr.Markdown(
651
  "**Future work:** extend the model to unified vision generation and understanding."
@@ -657,7 +654,10 @@ def build_demo() -> gr.Blocks:
657
  demo = build_demo()
658
 
659
  if __name__ == "__main__":
660
- demo.queue(default_concurrency_limit=1).launch(
661
- server_name=os.getenv("HOST", "0.0.0.0"),
662
- server_port=int(os.getenv("PORT", "7860")),
663
- )
 
 
 
 
402
  )
403
 
404
 
405
+ def make_theme() -> gr.themes.Base:
406
  nvidia_green = gr.themes.Color(
407
  c50="#f3f9e6",
408
  c100="#e3f1c2",
 
416
  c900="#2a4200",
417
  c950="#1a2900",
418
  )
419
+ return gr.themes.Soft(primary_hue=nvidia_green, secondary_hue=nvidia_green)
420
+
421
+
422
+ # Gradio 6.0 moved `theme` from Blocks(...) to launch(...).
423
+ _GRADIO_MAJOR = int(gr.__version__.split(".")[0])
424
+
425
+
426
+ def build_demo() -> gr.Blocks:
427
+ theme = make_theme()
428
+ blocks_kwargs: dict[str, Any] = {"title": "Nemotron Labs Diffusion Image"}
429
+ if _GRADIO_MAJOR < 6:
430
+ blocks_kwargs["theme"] = theme
431
+ with gr.Blocks(**blocks_kwargs) as demo:
432
  gr.Markdown(
433
  "# Nemotron Labs Diffusion Image\n\n"
434
  "NL-Diffusion-Image generates high-resolution images via **masked discrete diffusion** "
 
558
  columns=3,
559
  height="auto",
560
  object_fit="contain",
561
+ show_label=False, )
 
 
562
 
563
  gr.Markdown(
564
  "### Generation speed\n\n"
 
569
  gr.Image(
570
  value=_asset("speed_comparison.gif"),
571
  show_label=False,
572
+ interactive=False, )
 
 
573
 
574
  with gr.Row(equal_height=True):
575
  with gr.Column(scale=1):
 
584
  gr.Image(
585
  value=_asset("architecture.png"),
586
  show_label=False,
587
+ interactive=False, )
 
 
588
 
589
  with gr.Row(equal_height=True):
590
  with gr.Column(scale=1):
 
598
  gr.Image(
599
  value=_asset("benchmarks.png"),
600
  show_label=False,
601
+ interactive=False, )
 
 
602
 
603
  gr.Markdown("### Key findings")
604
 
 
613
  gr.Image(
614
  value=_asset("token_editing.png"),
615
  show_label=False,
616
+ interactive=False, )
 
 
617
 
618
  with gr.Row(equal_height=True):
619
  with gr.Column(scale=1):
 
628
  gr.Image(
629
  value=_asset("gce_objective.png"),
630
  show_label=False,
631
+ interactive=False, )
 
 
632
 
633
  with gr.Row(equal_height=True):
634
  with gr.Column(scale=1):
 
642
  gr.Image(
643
  value=_asset("few_step_generation.png"),
644
  show_label=False,
645
+ interactive=False, )
 
 
646
 
647
  gr.Markdown(
648
  "**Future work:** extend the model to unified vision generation and understanding."
 
654
  demo = build_demo()
655
 
656
  if __name__ == "__main__":
657
+ launch_kwargs: dict[str, Any] = {
658
+ "server_name": os.getenv("HOST", "0.0.0.0"),
659
+ "server_port": int(os.getenv("PORT", "7860")),
660
+ }
661
+ if _GRADIO_MAJOR >= 6:
662
+ launch_kwargs["theme"] = make_theme()
663
+ demo.queue(default_concurrency_limit=1).launch(**launch_kwargs)