with gr.Blocks(css=css, theme=gr.themes.Citrus()) as demo: gr.HTML("

Qwen-Image with InstantX Inpainting ControlNet") gr.Markdown( "Generate images with the [InstantX/Qwen-Image-ControlNet-Inpainting](https://huggingface.co/InstantX/Qwen-Image-ControlNet-Inpainting) that takes depth, pose and canny conditionings" ) with gr.Row(): with gr.Column(): edit_image = gr.ImageEditor( label='Upload and draw mask for inpainting', type='pil', sources=["upload", "webcam"], image_mode='RGB', layers=False, brush=gr.Brush(colors=["#FFFFFF"], color_mode="fixed"), height=600 ) prompt = gr.Text( label="Prompt", show_label=False, max_lines=1, placeholder="Enter your prompt (e.g., 'change the hat to red')", container=False, ) negative_prompt = gr.Text( label="Negative Prompt", show_label=True, max_lines=1, placeholder="Enter what you don't want (optional)", container=False, value="", visible=False ) run_button = gr.Button("Run") with gr.Column(): result = gr.ImageSlider(label="Result", show_label=False, interactive=False) use_as_input_button = gr.Button("🔄 Use as Input Image", visible=False, variant="secondary") with gr.Accordion("Advanced Settings", open=False): seed = gr.Slider( label="Seed", minimum=0, maximum=MAX_SEED, step=1, value=42, ) randomize_seed = gr.Checkbox(label="Randomize seed", value=True) with gr.Row(): strength = gr.Slider( label="Conditioning Scale", minimum=0.0, maximum=1.0, step=0.1, value=1.0, info="Controls how much the inpainted region should change" ) true_cfg_scale = gr.Slider( label="True CFG Scale", minimum=1.0, maximum=10.0, step=0.5, value=4.0, info="Classifier-free guidance scale" ) num_inference_steps = gr.Slider( label="Number of inference steps", minimum=1, maximum=50, step=1, value=30, ) rewrite_prompt = gr.Checkbox( label="Enhance prompt (using HF Inference)", value=True ) # Event handlers for reuse functionality (MUST be inside gr.Blocks context with 4 spaces) use_as_input_button.click( fn=use_output_as_input, inputs=[result], outputs=[edit_image], show_api=False ) # Main generation pipeline with result clearing and button visibility gr.on( triggers=[run_button.click, prompt.submit], fn=clear_result, inputs=None, outputs=result, show_api=False ).then( fn=infer, inputs=[edit_image, prompt, negative_prompt, seed, randomize_seed, strength, num_inference_steps, true_cfg_scale, rewrite_prompt], outputs=[result, seed] ).then( fn=lambda: gr.update(visible=True), inputs=None, outputs=use_as_input_button, show_api=False ) demo.launch()