multimodalart HF Staff commited on
Commit
3d07c28
·
verified ·
1 Parent(s): 2bba772

Add MCP support

Browse files

Closes #6

Files changed (1) hide show
  1. app.py +52 -3
app.py CHANGED
@@ -365,8 +365,56 @@ def prompt_enhance(prompt, enable_enhance):
365
 
366
  @spaces.GPU
367
  def generate(
368
- prompt, resolution, seed, steps, shift, enhance, random_seed, gallery_images, progress=gr.Progress(track_tqdm=True)
369
  ):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
370
  if pipe is None:
371
  raise gr.Error("Model not loaded.")
372
 
@@ -465,7 +513,7 @@ with gr.Blocks(title="Z-Image Demo") as demo:
465
  res_choices = RES_CHOICES["1024"]
466
  return gr.update(value=res_choices[0], choices=res_choices)
467
 
468
- res_cat.change(update_res_choices, inputs=res_cat, outputs=resolution)
469
 
470
  # PE enhancement button (Temporarily disabled)
471
  # enhance_btn.click(
@@ -481,10 +529,11 @@ with gr.Blocks(title="Z-Image Demo") as demo:
481
  generate,
482
  inputs=[prompt_input, resolution, seed, steps, shift, enable_enhance, random_seed, output_gallery],
483
  outputs=[output_gallery, used_seed, seed],
 
484
  )
485
 
486
  css='''
487
  .fillable{max-width: 1230px !important}
488
  '''
489
  if __name__ == "__main__":
490
- demo.launch(css=css)
 
365
 
366
  @spaces.GPU
367
  def generate(
368
+ prompt, resolution="1024x1024 ( 1:1 )", seed=42, steps=9, shift=3.0, enhance=False, random_seed=True, gallery_images=None, progress=gr.Progress(track_tqdm=True)
369
  ):
370
+ """
371
+ Generate an image using the Z-Image model based on the provided prompt and settings.
372
+
373
+ This function is triggered when the user clicks the "Generate" button. It processes
374
+ the input prompt (optionally enhancing it), configures generation parameters, and
375
+ produces an image using the Z-Image diffusion transformer pipeline.
376
+
377
+ Args:
378
+ prompt (str): Text prompt describing the desired image content
379
+ resolution (str): Output resolution in format "WIDTHxHEIGHT ( RATIO )" (e.g., "1024x1024 ( 1:1 )")
380
+ valid options, 1024 category:
381
+ - "1024x1024 ( 1:1 )"
382
+ - "1152x896 ( 9:7 )"
383
+ - "896x1152 ( 7:9 )"
384
+ - "1152x864 ( 4:3 )"
385
+ - "864x1152 ( 3:4 )"
386
+ - "1248x832 ( 3:2 )"
387
+ - "832x1248 ( 2:3 )"
388
+ - "1280x720 ( 16:9 )"
389
+ - "720x1280 ( 9:16 )"
390
+ - "1344x576 ( 21:9 )"
391
+ - "576x1344 ( 9:21 )"
392
+ 1280 category:
393
+ - "1280x1280 ( 1:1 )"
394
+ - "1440x1120 ( 9:7 )"
395
+ - "1120x1440 ( 7:9 )"
396
+ - "1472x1104 ( 4:3 )"
397
+ - "1104x1472 ( 3:4 )"
398
+ - "1536x1024 ( 3:2 )"
399
+ - "1024x1536 ( 2:3 )"
400
+ - "1600x896 ( 16:9 )"
401
+ - "896x1600 ( 9:16 )"
402
+ - "1680x720 ( 21:9 )"
403
+ - "720x1680 ( 9:21 )"
404
+ seed (int): Seed for reproducible generation
405
+ steps (int): Number of inference steps for the diffusion process
406
+ shift (float): Time shift parameter for the flow matching scheduler
407
+ enhance (bool): This was Whether to enhance the prompt (DISABLED! Do not use)
408
+ random_seed (bool): Whether to generate a new random seed, if True will ignore the seed input
409
+ gallery_images (list): List of previously generated images to append to (only needed for the Gradio UI)
410
+ progress (gr.Progress): Gradio progress tracker for displaying generation progress (only needed for the Gradio UI)
411
+
412
+ Returns:
413
+ tuple: (gallery_images, seed_str, seed_int)
414
+ - gallery_images: Updated list of generated images including the new image
415
+ - seed_str: String representation of the seed used for generation
416
+ - seed_int: Integer representation of the seed used for generation
417
+ """
418
  if pipe is None:
419
  raise gr.Error("Model not loaded.")
420
 
 
513
  res_choices = RES_CHOICES["1024"]
514
  return gr.update(value=res_choices[0], choices=res_choices)
515
 
516
+ res_cat.change(update_res_choices, inputs=res_cat, outputs=resolution, api_visibility="private")
517
 
518
  # PE enhancement button (Temporarily disabled)
519
  # enhance_btn.click(
 
529
  generate,
530
  inputs=[prompt_input, resolution, seed, steps, shift, enable_enhance, random_seed, output_gallery],
531
  outputs=[output_gallery, used_seed, seed],
532
+ api_visibility="public",
533
  )
534
 
535
  css='''
536
  .fillable{max-width: 1230px !important}
537
  '''
538
  if __name__ == "__main__":
539
+ demo.launch(css=css, mcp_server=True)