chengzeyi Claude commited on
Commit
49038c3
·
1 Parent(s): c3ee48c

Replace gallery with single image output

Browse files

Simplify the UI by showing one generated image at a time instead of
accumulating images in a gallery. This removes unnecessary state
management and makes the interface cleaner.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>

Files changed (1) hide show
  1. app.py +8 -13
app.py CHANGED
@@ -365,7 +365,7 @@ def prompt_enhance(prompt, enable_enhance):
365
 
366
  @spaces.GPU
367
  def generate(
368
- prompt, resolution="1024x1024 ( 1:1 )", seed=42, steps=9, shift=3.0, random_seed=True, gallery_images=None, enhance=False, progress=gr.Progress(track_tqdm=True)
369
  ):
370
  """
371
  Generate an image using the Z-Image model based on the provided prompt and settings.
@@ -381,13 +381,12 @@ def generate(
381
  steps (int): Number of inference steps for the diffusion process
382
  shift (float): Time shift parameter for the flow matching scheduler
383
  random_seed (bool): Whether to generate a new random seed, if True will ignore the seed input
384
- gallery_images (list): List of previously generated images to append to (only needed for the Gradio UI)
385
  enhance (bool): This was Whether to enhance the prompt (DISABLED! Do not use)
386
  progress (gr.Progress): Gradio progress tracker for displaying generation progress (only needed for the Gradio UI)
387
 
388
  Returns:
389
- tuple: (gallery_images, seed_str, seed_int)
390
- - gallery_images: Updated list of generated images including the new image
391
  - seed_str: String representation of the seed used for generation
392
  - seed_int: Integer representation of the seed used for generation
393
  """
@@ -420,11 +419,7 @@ def generate(
420
  shift=shift,
421
  )
422
 
423
- if gallery_images is None:
424
- gallery_images = []
425
- gallery_images.append(image)
426
-
427
- return gallery_images, str(new_seed), int(new_seed)
428
 
429
 
430
  init_app()
@@ -479,8 +474,8 @@ with gr.Blocks(title="Z-Image Demo") as demo:
479
  gr.Examples(examples=EXAMPLE_PROMPTS, inputs=prompt_input, label=None)
480
 
481
  with gr.Column(scale=1):
482
- output_gallery = gr.Gallery(
483
- label="Generated Images", columns=2, rows=2, height=600, object_fit="contain", format="png", interactive=False
484
  )
485
  used_seed = gr.Textbox(label="Seed Used", interactive=False)
486
 
@@ -502,8 +497,8 @@ with gr.Blocks(title="Z-Image Demo") as demo:
502
 
503
  generate_btn.click(
504
  generate,
505
- inputs=[prompt_input, resolution, seed, steps, shift, random_seed, output_gallery],
506
- outputs=[output_gallery, used_seed, seed],
507
  api_visibility="public",
508
  )
509
 
 
365
 
366
  @spaces.GPU
367
  def generate(
368
+ prompt, resolution="1024x1024 ( 1:1 )", seed=42, steps=9, shift=3.0, random_seed=True, enhance=False, progress=gr.Progress(track_tqdm=True)
369
  ):
370
  """
371
  Generate an image using the Z-Image model based on the provided prompt and settings.
 
381
  steps (int): Number of inference steps for the diffusion process
382
  shift (float): Time shift parameter for the flow matching scheduler
383
  random_seed (bool): Whether to generate a new random seed, if True will ignore the seed input
 
384
  enhance (bool): This was Whether to enhance the prompt (DISABLED! Do not use)
385
  progress (gr.Progress): Gradio progress tracker for displaying generation progress (only needed for the Gradio UI)
386
 
387
  Returns:
388
+ tuple: (image, seed_str, seed_int)
389
+ - image: The generated image
390
  - seed_str: String representation of the seed used for generation
391
  - seed_int: Integer representation of the seed used for generation
392
  """
 
419
  shift=shift,
420
  )
421
 
422
+ return image, str(new_seed), int(new_seed)
 
 
 
 
423
 
424
 
425
  init_app()
 
474
  gr.Examples(examples=EXAMPLE_PROMPTS, inputs=prompt_input, label=None)
475
 
476
  with gr.Column(scale=1):
477
+ output_image = gr.Image(
478
+ label="Generated Image", height=600, format="png", interactive=False
479
  )
480
  used_seed = gr.Textbox(label="Seed Used", interactive=False)
481
 
 
497
 
498
  generate_btn.click(
499
  generate,
500
+ inputs=[prompt_input, resolution, seed, steps, shift, random_seed],
501
+ outputs=[output_image, used_seed, seed],
502
  api_visibility="public",
503
  )
504