Spaces:
Running
on
Zero
Running
on
Zero
Refactor and clean up Gradio UI and generation logic
Browse filesRefactored the generate function to return a single image instead of a gallery, updated the Gradio UI to use an Image component instead of a Gallery, and improved code formatting for readability. Enhanced docstrings and argument descriptions, and made minor style and error handling improvements throughout the file.
app.py
CHANGED
|
@@ -57,7 +57,7 @@ RES_CHOICES = {
|
|
| 57 |
"1536x1024 ( 3:2 )",
|
| 58 |
"1024x1536 ( 2:3 )",
|
| 59 |
"1600x896 ( 16:9 )",
|
| 60 |
-
"896x1600 ( 9:16 )",
|
| 61 |
"1680x720 ( 21:9 )",
|
| 62 |
"720x1680 ( 9:21 )",
|
| 63 |
],
|
|
@@ -119,10 +119,14 @@ def load_models(model_path, enable_compile=False, attention_backend="native"):
|
|
| 119 |
use_auth_token=use_auth_token,
|
| 120 |
).eval()
|
| 121 |
|
| 122 |
-
tokenizer = AutoTokenizer.from_pretrained(
|
|
|
|
|
|
|
| 123 |
else:
|
| 124 |
vae = AutoencoderKL.from_pretrained(
|
| 125 |
-
os.path.join(model_path, "vae"),
|
|
|
|
|
|
|
| 126 |
)
|
| 127 |
|
| 128 |
text_encoder = AutoModel.from_pretrained(
|
|
@@ -145,7 +149,13 @@ def load_models(model_path, enable_compile=False, attention_backend="native"):
|
|
| 145 |
torch._inductor.config.max_autotune_gemm_backends = "TRITON,ATEN"
|
| 146 |
torch._inductor.config.triton.cudagraphs = False
|
| 147 |
|
| 148 |
-
pipe = ZImagePipeline(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 149 |
|
| 150 |
if enable_compile:
|
| 151 |
pipe.vae.disable_tiling()
|
|
@@ -155,16 +165,18 @@ def load_models(model_path, enable_compile=False, attention_backend="native"):
|
|
| 155 |
f"{model_path}", subfolder="transformer", use_auth_token=use_auth_token
|
| 156 |
).to("cuda", torch.bfloat16)
|
| 157 |
else:
|
| 158 |
-
transformer = ZImageTransformer2DModel.from_pretrained(
|
| 159 |
-
"
|
| 160 |
-
)
|
| 161 |
|
| 162 |
pipe.transformer = transformer
|
| 163 |
pipe.transformer.set_attention_backend(attention_backend)
|
| 164 |
|
| 165 |
if enable_compile:
|
| 166 |
print("Compiling transformer...")
|
| 167 |
-
pipe.transformer = torch.compile(
|
|
|
|
|
|
|
| 168 |
|
| 169 |
pipe.to("cuda", torch.bfloat16)
|
| 170 |
|
|
@@ -254,7 +266,9 @@ class APIPromptExpander(PromptExpander):
|
|
| 254 |
from openai import OpenAI
|
| 255 |
|
| 256 |
api_key = self.api_config.get("api_key") or DASHSCOPE_API_KEY
|
| 257 |
-
base_url = self.api_config.get(
|
|
|
|
|
|
|
| 258 |
|
| 259 |
if not api_key:
|
| 260 |
print("Warning: DASHSCOPE_API_KEY not found.")
|
|
@@ -273,7 +287,9 @@ class APIPromptExpander(PromptExpander):
|
|
| 273 |
|
| 274 |
def extend(self, prompt, system_prompt=None, seed=-1, **kwargs):
|
| 275 |
if self.client is None:
|
| 276 |
-
return PromptOutput(
|
|
|
|
|
|
|
| 277 |
|
| 278 |
if system_prompt is None:
|
| 279 |
system_prompt = self.decide_system_prompt()
|
|
@@ -286,7 +302,10 @@ class APIPromptExpander(PromptExpander):
|
|
| 286 |
model = self.api_config.get("model", "qwen3-max-preview")
|
| 287 |
response = self.client.chat.completions.create(
|
| 288 |
model=model,
|
| 289 |
-
messages=[
|
|
|
|
|
|
|
|
|
|
| 290 |
temperature=0.7,
|
| 291 |
top_p=0.8,
|
| 292 |
)
|
|
@@ -305,7 +324,11 @@ class APIPromptExpander(PromptExpander):
|
|
| 305 |
expanded_prompt = content
|
| 306 |
|
| 307 |
return PromptOutput(
|
| 308 |
-
status=True,
|
|
|
|
|
|
|
|
|
|
|
|
|
| 309 |
)
|
| 310 |
except Exception as e:
|
| 311 |
return PromptOutput(False, "", seed, system_prompt, str(e))
|
|
@@ -325,7 +348,11 @@ def init_app():
|
|
| 325 |
global pipe, prompt_expander
|
| 326 |
|
| 327 |
try:
|
| 328 |
-
pipe = load_models(
|
|
|
|
|
|
|
|
|
|
|
|
|
| 329 |
print(f"Model loaded. Compile: {ENABLE_COMPILE}, Backend: {ATTENTION_BACKEND}")
|
| 330 |
|
| 331 |
if ENABLE_WARMUP:
|
|
@@ -339,7 +366,9 @@ def init_app():
|
|
| 339 |
pipe = None
|
| 340 |
|
| 341 |
try:
|
| 342 |
-
prompt_expander = create_prompt_expander(
|
|
|
|
|
|
|
| 343 |
print("Prompt expander initialized.")
|
| 344 |
except Exception as e:
|
| 345 |
print(f"Error initializing prompt expander: {e}")
|
|
@@ -365,55 +394,34 @@ def prompt_enhance(prompt, enable_enhance):
|
|
| 365 |
|
| 366 |
@spaces.GPU
|
| 367 |
def generate(
|
| 368 |
-
prompt
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 369 |
):
|
| 370 |
"""
|
| 371 |
-
Generate
|
| 372 |
|
| 373 |
-
This function is
|
| 374 |
-
|
| 375 |
-
|
| 376 |
|
| 377 |
Args:
|
| 378 |
-
prompt
|
| 379 |
-
resolution
|
| 380 |
-
|
| 381 |
-
|
| 382 |
-
|
| 383 |
-
|
| 384 |
-
|
| 385 |
-
|
| 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: (
|
| 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.")
|
|
@@ -431,7 +439,7 @@ def generate(
|
|
| 431 |
|
| 432 |
try:
|
| 433 |
resolution_str = resolution.split(" ")[0]
|
| 434 |
-
except:
|
| 435 |
resolution_str = "1024x1024"
|
| 436 |
|
| 437 |
image = generate_image(
|
|
@@ -444,11 +452,7 @@ def generate(
|
|
| 444 |
shift=shift,
|
| 445 |
)
|
| 446 |
|
| 447 |
-
|
| 448 |
-
gallery_images = []
|
| 449 |
-
gallery_images.append(image)
|
| 450 |
-
|
| 451 |
-
return gallery_images, str(new_seed), int(new_seed)
|
| 452 |
|
| 453 |
|
| 454 |
init_app()
|
|
@@ -473,7 +477,9 @@ with gr.Blocks(title="Z-Image Demo") as demo:
|
|
| 473 |
|
| 474 |
with gr.Row():
|
| 475 |
with gr.Column(scale=1):
|
| 476 |
-
prompt_input = gr.Textbox(
|
|
|
|
|
|
|
| 477 |
# PE components (Temporarily disabled)
|
| 478 |
# with gr.Row():
|
| 479 |
# enable_enhance = gr.Checkbox(label="Enhance Prompt (DashScope)", value=False)
|
|
@@ -481,18 +487,33 @@ with gr.Blocks(title="Z-Image Demo") as demo:
|
|
| 481 |
|
| 482 |
with gr.Row():
|
| 483 |
choices = [int(k) for k in RES_CHOICES.keys()]
|
| 484 |
-
res_cat = gr.Dropdown(
|
|
|
|
|
|
|
| 485 |
|
| 486 |
initial_res_choices = RES_CHOICES["1024"]
|
| 487 |
-
resolution = gr.Dropdown(
|
|
|
|
|
|
|
|
|
|
|
|
|
| 488 |
|
| 489 |
with gr.Row():
|
| 490 |
seed = gr.Number(label="Seed", value=42, precision=0)
|
| 491 |
random_seed = gr.Checkbox(label="Random Seed", value=True)
|
| 492 |
|
| 493 |
with gr.Row():
|
| 494 |
-
steps = gr.Slider(
|
| 495 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 496 |
|
| 497 |
generate_btn = gr.Button("Generate", variant="primary")
|
| 498 |
|
|
@@ -501,8 +522,12 @@ with gr.Blocks(title="Z-Image Demo") as demo:
|
|
| 501 |
gr.Examples(examples=EXAMPLE_PROMPTS, inputs=prompt_input, label=None)
|
| 502 |
|
| 503 |
with gr.Column(scale=1):
|
| 504 |
-
|
| 505 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 506 |
)
|
| 507 |
used_seed = gr.Textbox(label="Seed Used", interactive=False)
|
| 508 |
|
|
@@ -513,27 +538,31 @@ with gr.Blocks(title="Z-Image Demo") as demo:
|
|
| 513 |
res_choices = RES_CHOICES["1024"]
|
| 514 |
return gr.update(value=res_choices[0], choices=res_choices)
|
| 515 |
|
| 516 |
-
res_cat.change(
|
| 517 |
-
|
| 518 |
-
|
| 519 |
-
# enhance_btn.click(
|
| 520 |
-
# prompt_enhance,
|
| 521 |
-
# inputs=[prompt_input, enable_enhance],
|
| 522 |
-
# outputs=[prompt_input, final_prompt_output]
|
| 523 |
-
# )
|
| 524 |
|
| 525 |
# Dummy enable_enhance variable set to False
|
| 526 |
enable_enhance = gr.State(value=False)
|
| 527 |
|
| 528 |
generate_btn.click(
|
| 529 |
generate,
|
| 530 |
-
inputs=[
|
| 531 |
-
|
| 532 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 533 |
)
|
| 534 |
|
| 535 |
-
css=
|
| 536 |
.fillable{max-width: 1230px !important}
|
| 537 |
-
|
| 538 |
if __name__ == "__main__":
|
| 539 |
-
demo.launch(css=css, mcp_server=True)
|
|
|
|
| 57 |
"1536x1024 ( 3:2 )",
|
| 58 |
"1024x1536 ( 2:3 )",
|
| 59 |
"1600x896 ( 16:9 )",
|
| 60 |
+
"896x1600 ( 9:16 )", # not 900 coz divided by 16 needed
|
| 61 |
"1680x720 ( 21:9 )",
|
| 62 |
"720x1680 ( 9:21 )",
|
| 63 |
],
|
|
|
|
| 119 |
use_auth_token=use_auth_token,
|
| 120 |
).eval()
|
| 121 |
|
| 122 |
+
tokenizer = AutoTokenizer.from_pretrained(
|
| 123 |
+
f"{model_path}", subfolder="tokenizer", use_auth_token=use_auth_token
|
| 124 |
+
)
|
| 125 |
else:
|
| 126 |
vae = AutoencoderKL.from_pretrained(
|
| 127 |
+
os.path.join(model_path, "vae"),
|
| 128 |
+
torch_dtype=torch.bfloat16,
|
| 129 |
+
device_map="cuda",
|
| 130 |
)
|
| 131 |
|
| 132 |
text_encoder = AutoModel.from_pretrained(
|
|
|
|
| 149 |
torch._inductor.config.max_autotune_gemm_backends = "TRITON,ATEN"
|
| 150 |
torch._inductor.config.triton.cudagraphs = False
|
| 151 |
|
| 152 |
+
pipe = ZImagePipeline(
|
| 153 |
+
scheduler=None,
|
| 154 |
+
vae=vae,
|
| 155 |
+
text_encoder=text_encoder,
|
| 156 |
+
tokenizer=tokenizer,
|
| 157 |
+
transformer=None,
|
| 158 |
+
)
|
| 159 |
|
| 160 |
if enable_compile:
|
| 161 |
pipe.vae.disable_tiling()
|
|
|
|
| 165 |
f"{model_path}", subfolder="transformer", use_auth_token=use_auth_token
|
| 166 |
).to("cuda", torch.bfloat16)
|
| 167 |
else:
|
| 168 |
+
transformer = ZImageTransformer2DModel.from_pretrained(
|
| 169 |
+
os.path.join(model_path, "transformer")
|
| 170 |
+
).to("cuda", torch.bfloat16)
|
| 171 |
|
| 172 |
pipe.transformer = transformer
|
| 173 |
pipe.transformer.set_attention_backend(attention_backend)
|
| 174 |
|
| 175 |
if enable_compile:
|
| 176 |
print("Compiling transformer...")
|
| 177 |
+
pipe.transformer = torch.compile(
|
| 178 |
+
pipe.transformer, mode="max-autotune-no-cudagraphs", fullgraph=False
|
| 179 |
+
)
|
| 180 |
|
| 181 |
pipe.to("cuda", torch.bfloat16)
|
| 182 |
|
|
|
|
| 266 |
from openai import OpenAI
|
| 267 |
|
| 268 |
api_key = self.api_config.get("api_key") or DASHSCOPE_API_KEY
|
| 269 |
+
base_url = self.api_config.get(
|
| 270 |
+
"base_url", "https://dashscope.aliyuncs.com/compatible-mode/v1"
|
| 271 |
+
)
|
| 272 |
|
| 273 |
if not api_key:
|
| 274 |
print("Warning: DASHSCOPE_API_KEY not found.")
|
|
|
|
| 287 |
|
| 288 |
def extend(self, prompt, system_prompt=None, seed=-1, **kwargs):
|
| 289 |
if self.client is None:
|
| 290 |
+
return PromptOutput(
|
| 291 |
+
False, "", seed, system_prompt, "API client not initialized"
|
| 292 |
+
)
|
| 293 |
|
| 294 |
if system_prompt is None:
|
| 295 |
system_prompt = self.decide_system_prompt()
|
|
|
|
| 302 |
model = self.api_config.get("model", "qwen3-max-preview")
|
| 303 |
response = self.client.chat.completions.create(
|
| 304 |
model=model,
|
| 305 |
+
messages=[
|
| 306 |
+
{"role": "system", "content": system_prompt},
|
| 307 |
+
{"role": "user", "content": prompt},
|
| 308 |
+
],
|
| 309 |
temperature=0.7,
|
| 310 |
top_p=0.8,
|
| 311 |
)
|
|
|
|
| 324 |
expanded_prompt = content
|
| 325 |
|
| 326 |
return PromptOutput(
|
| 327 |
+
status=True,
|
| 328 |
+
prompt=expanded_prompt,
|
| 329 |
+
seed=seed,
|
| 330 |
+
system_prompt=system_prompt,
|
| 331 |
+
message=content,
|
| 332 |
)
|
| 333 |
except Exception as e:
|
| 334 |
return PromptOutput(False, "", seed, system_prompt, str(e))
|
|
|
|
| 348 |
global pipe, prompt_expander
|
| 349 |
|
| 350 |
try:
|
| 351 |
+
pipe = load_models(
|
| 352 |
+
MODEL_PATH,
|
| 353 |
+
enable_compile=ENABLE_COMPILE,
|
| 354 |
+
attention_backend=ATTENTION_BACKEND,
|
| 355 |
+
)
|
| 356 |
print(f"Model loaded. Compile: {ENABLE_COMPILE}, Backend: {ATTENTION_BACKEND}")
|
| 357 |
|
| 358 |
if ENABLE_WARMUP:
|
|
|
|
| 366 |
pipe = None
|
| 367 |
|
| 368 |
try:
|
| 369 |
+
prompt_expander = create_prompt_expander(
|
| 370 |
+
backend="api", api_config={"model": "qwen3-max-preview"}
|
| 371 |
+
)
|
| 372 |
print("Prompt expander initialized.")
|
| 373 |
except Exception as e:
|
| 374 |
print(f"Error initializing prompt expander: {e}")
|
|
|
|
| 394 |
|
| 395 |
@spaces.GPU
|
| 396 |
def generate(
|
| 397 |
+
prompt: str,
|
| 398 |
+
resolution: str = "1024x1024 ( 1:1 )",
|
| 399 |
+
seed: int = 42,
|
| 400 |
+
steps: int = 9,
|
| 401 |
+
shift: float = 3.0,
|
| 402 |
+
enhance: bool = False,
|
| 403 |
+
random_seed: bool = True,
|
| 404 |
+
progress: gr.Progress = gr.Progress(track_tqdm=True),
|
| 405 |
):
|
| 406 |
"""
|
| 407 |
+
Generate a single image using the Z-Image model based on the provided prompt and settings.
|
| 408 |
|
| 409 |
+
This function is exposed as a Gradio/MCP tool via the main 'Generate' button.
|
| 410 |
+
It optionally enhances the prompt, configures generation parameters, and
|
| 411 |
+
returns exactly one image plus the seed used.
|
| 412 |
|
| 413 |
Args:
|
| 414 |
+
prompt: Text prompt describing the desired image content.
|
| 415 |
+
resolution: Output resolution in format "WIDTHxHEIGHT ( RATIO )".
|
| 416 |
+
seed: Seed for reproducible generation. Ignored if random_seed is True.
|
| 417 |
+
steps: Number of inference steps for the diffusion process.
|
| 418 |
+
shift: Time shift parameter for the flow matching scheduler.
|
| 419 |
+
enhance: (Currently disabled in the UI) Whether to enhance the prompt.
|
| 420 |
+
random_seed: If True, a new random seed will be sampled.
|
| 421 |
+
progress: Gradio progress tracker (automatically provided by Gradio).
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 422 |
|
| 423 |
Returns:
|
| 424 |
+
tuple[object, str, int]: (image, seed_str, seed_int)
|
|
|
|
|
|
|
|
|
|
| 425 |
"""
|
| 426 |
if pipe is None:
|
| 427 |
raise gr.Error("Model not loaded.")
|
|
|
|
| 439 |
|
| 440 |
try:
|
| 441 |
resolution_str = resolution.split(" ")[0]
|
| 442 |
+
except Exception:
|
| 443 |
resolution_str = "1024x1024"
|
| 444 |
|
| 445 |
image = generate_image(
|
|
|
|
| 452 |
shift=shift,
|
| 453 |
)
|
| 454 |
|
| 455 |
+
return image, str(new_seed), int(new_seed)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 456 |
|
| 457 |
|
| 458 |
init_app()
|
|
|
|
| 477 |
|
| 478 |
with gr.Row():
|
| 479 |
with gr.Column(scale=1):
|
| 480 |
+
prompt_input = gr.Textbox(
|
| 481 |
+
label="Prompt", lines=3, placeholder="Enter your prompt here..."
|
| 482 |
+
)
|
| 483 |
# PE components (Temporarily disabled)
|
| 484 |
# with gr.Row():
|
| 485 |
# enable_enhance = gr.Checkbox(label="Enhance Prompt (DashScope)", value=False)
|
|
|
|
| 487 |
|
| 488 |
with gr.Row():
|
| 489 |
choices = [int(k) for k in RES_CHOICES.keys()]
|
| 490 |
+
res_cat = gr.Dropdown(
|
| 491 |
+
value=1024, choices=choices, label="Resolution Category"
|
| 492 |
+
)
|
| 493 |
|
| 494 |
initial_res_choices = RES_CHOICES["1024"]
|
| 495 |
+
resolution = gr.Dropdown(
|
| 496 |
+
value=initial_res_choices[0],
|
| 497 |
+
choices=RESOLUTION_SET,
|
| 498 |
+
label="Width x Height (Ratio)",
|
| 499 |
+
)
|
| 500 |
|
| 501 |
with gr.Row():
|
| 502 |
seed = gr.Number(label="Seed", value=42, precision=0)
|
| 503 |
random_seed = gr.Checkbox(label="Random Seed", value=True)
|
| 504 |
|
| 505 |
with gr.Row():
|
| 506 |
+
steps = gr.Slider(
|
| 507 |
+
label="Steps",
|
| 508 |
+
minimum=1,
|
| 509 |
+
maximum=100,
|
| 510 |
+
value=8,
|
| 511 |
+
step=1,
|
| 512 |
+
interactive=False,
|
| 513 |
+
)
|
| 514 |
+
shift = gr.Slider(
|
| 515 |
+
label="Time Shift", minimum=1.0, maximum=10.0, value=3.0, step=0.1
|
| 516 |
+
)
|
| 517 |
|
| 518 |
generate_btn = gr.Button("Generate", variant="primary")
|
| 519 |
|
|
|
|
| 522 |
gr.Examples(examples=EXAMPLE_PROMPTS, inputs=prompt_input, label=None)
|
| 523 |
|
| 524 |
with gr.Column(scale=1):
|
| 525 |
+
# Switched from Gallery -> single Image for MCP-friendly output
|
| 526 |
+
output_image = gr.Image(
|
| 527 |
+
label="Generated Image",
|
| 528 |
+
format="png",
|
| 529 |
+
height=600,
|
| 530 |
+
interactive=False,
|
| 531 |
)
|
| 532 |
used_seed = gr.Textbox(label="Seed Used", interactive=False)
|
| 533 |
|
|
|
|
| 538 |
res_choices = RES_CHOICES["1024"]
|
| 539 |
return gr.update(value=res_choices[0], choices=res_choices)
|
| 540 |
|
| 541 |
+
res_cat.change(
|
| 542 |
+
update_res_choices, inputs=res_cat, outputs=resolution, api_visibility="private"
|
| 543 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 544 |
|
| 545 |
# Dummy enable_enhance variable set to False
|
| 546 |
enable_enhance = gr.State(value=False)
|
| 547 |
|
| 548 |
generate_btn.click(
|
| 549 |
generate,
|
| 550 |
+
inputs=[
|
| 551 |
+
prompt_input,
|
| 552 |
+
resolution,
|
| 553 |
+
seed,
|
| 554 |
+
steps,
|
| 555 |
+
shift,
|
| 556 |
+
enable_enhance,
|
| 557 |
+
random_seed,
|
| 558 |
+
],
|
| 559 |
+
outputs=[output_image, used_seed, seed],
|
| 560 |
+
api_visibility="public", # exposed as MCP tool
|
| 561 |
+
api_name="generate_image", # nice, stable name for tool clients
|
| 562 |
)
|
| 563 |
|
| 564 |
+
css = """
|
| 565 |
.fillable{max-width: 1230px !important}
|
| 566 |
+
"""
|
| 567 |
if __name__ == "__main__":
|
| 568 |
+
demo.launch(css=css, mcp_server=True)
|