Update app.py
Browse filesadd example module
    	
        app.py
    CHANGED
    
    | 
         @@ -95,13 +95,14 @@ def infer(edit_images, 
     | 
|
| 95 | 
         | 
| 96 | 
         
             
                return image, seed
         
     | 
| 97 | 
         | 
| 98 | 
         
            -
             
     | 
| 99 | 
         
            -
             
     | 
| 100 | 
         
            -
                 
     | 
| 101 | 
         
            -
                 
     | 
| 
         | 
|
| 102 | 
         
             
            ]
         
     | 
| 103 | 
         | 
| 104 | 
         
            -
            css="""
         
     | 
| 105 | 
         
             
            #col-container {
         
     | 
| 106 | 
         
             
                margin: 0 auto;
         
     | 
| 107 | 
         
             
                max-width: 1000px;
         
     | 
| 
         @@ -109,7 +110,7 @@ css=""" 
     | 
|
| 109 | 
         
             
            """
         
     | 
| 110 | 
         | 
| 111 | 
         
             
            with gr.Blocks(css=css) as demo:
         
     | 
| 112 | 
         
            -
             
     | 
| 113 | 
         
             
                with gr.Column(elem_id="col-container"):
         
     | 
| 114 | 
         
             
                    gr.Markdown(f"""# IC-Edit
         
     | 
| 115 | 
         
             
            A demo for [IC-Edit](https://arxiv.org/pdf/2504.20690).
         
     | 
| 
         @@ -133,11 +134,11 @@ For more details, check out our [Github Repository](https://github.com/River-Zha 
     | 
|
| 133 | 
         
             
                                container=False,
         
     | 
| 134 | 
         
             
                            )
         
     | 
| 135 | 
         
             
                            run_button = gr.Button("Run")
         
     | 
| 136 | 
         
            -
             
     | 
| 137 | 
         
             
                        result = gr.Image(label="Result", show_label=False)
         
     | 
| 138 | 
         
            -
             
     | 
| 139 | 
         
            -
                    with gr.Accordion("Advanced Settings", open= 
     | 
| 140 | 
         
            -
             
     | 
| 141 | 
         
             
                        seed = gr.Slider(
         
     | 
| 142 | 
         
             
                            label="Seed",
         
     | 
| 143 | 
         
             
                            minimum=0,
         
     | 
| 
         @@ -145,11 +146,11 @@ For more details, check out our [Github Repository](https://github.com/River-Zha 
     | 
|
| 145 | 
         
             
                            step=1,
         
     | 
| 146 | 
         
             
                            value=0,
         
     | 
| 147 | 
         
             
                        )
         
     | 
| 148 | 
         
            -
             
     | 
| 149 | 
         
             
                        randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
         
     | 
| 150 | 
         
            -
             
     | 
| 151 | 
         
             
                        with gr.Row():
         
     | 
| 152 | 
         
            -
             
     | 
| 153 | 
         
             
                            width = gr.Slider(
         
     | 
| 154 | 
         
             
                                label="Width",
         
     | 
| 155 | 
         
             
                                minimum=512,
         
     | 
| 
         @@ -158,7 +159,7 @@ For more details, check out our [Github Repository](https://github.com/River-Zha 
     | 
|
| 158 | 
         
             
                                value=1024,
         
     | 
| 159 | 
         
             
                                visible=False
         
     | 
| 160 | 
         
             
                            )
         
     | 
| 161 | 
         
            -
             
     | 
| 162 | 
         
             
                            height = gr.Slider(
         
     | 
| 163 | 
         
             
                                label="Height",
         
     | 
| 164 | 
         
             
                                minimum=512,
         
     | 
| 
         @@ -167,7 +168,7 @@ For more details, check out our [Github Repository](https://github.com/River-Zha 
     | 
|
| 167 | 
         
             
                                value=1024,
         
     | 
| 168 | 
         
             
                                visible=False
         
     | 
| 169 | 
         
             
                            )
         
     | 
| 170 | 
         
            -
             
     | 
| 171 | 
         
             
                        with gr.Row():
         
     | 
| 172 | 
         | 
| 173 | 
         
             
                            guidance_scale = gr.Slider(
         
     | 
| 
         @@ -177,7 +178,7 @@ For more details, check out our [Github Repository](https://github.com/River-Zha 
     | 
|
| 177 | 
         
             
                                step=0.5,
         
     | 
| 178 | 
         
             
                                value=50,
         
     | 
| 179 | 
         
             
                            )
         
     | 
| 180 | 
         
            -
             
     | 
| 181 | 
         
             
                            num_inference_steps = gr.Slider(
         
     | 
| 182 | 
         
             
                                label="Number of inference steps",
         
     | 
| 183 | 
         
             
                                minimum=1,
         
     | 
| 
         @@ -186,11 +187,20 @@ For more details, check out our [Github Repository](https://github.com/River-Zha 
     | 
|
| 186 | 
         
             
                                value=28,
         
     | 
| 187 | 
         
             
                            )
         
     | 
| 188 | 
         | 
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 189 | 
         
             
                gr.on(
         
     | 
| 190 | 
         
             
                    triggers=[run_button.click, prompt.submit],
         
     | 
| 191 | 
         
            -
                    fn 
     | 
| 192 | 
         
            -
                    inputs 
     | 
| 193 | 
         
            -
                    outputs 
     | 
| 194 | 
         
             
                )
         
     | 
| 195 | 
         | 
| 196 | 
         
             
            demo.launch(server_port=args.port)
         
     | 
| 
         | 
|
| 95 | 
         | 
| 96 | 
         
             
                return image, seed
         
     | 
| 97 | 
         | 
| 98 | 
         
            +
            # 新增的示例,将元组转换为列表
         
     | 
| 99 | 
         
            +
            new_examples = [
         
     | 
| 100 | 
         
            +
                ['assets/girl.png', 'Make her hair dark green and her clothes checked.', 42],
         
     | 
| 101 | 
         
            +
                ['assets/boy.png', 'Change the sunglasses to a Christmas hat.', 27440001],
         
     | 
| 102 | 
         
            +
                ['assets/kaori.jpg', 'Make it a sketch.', 329918865]
         
     | 
| 103 | 
         
             
            ]
         
     | 
| 104 | 
         | 
| 105 | 
         
            +
            css = """
         
     | 
| 106 | 
         
             
            #col-container {
         
     | 
| 107 | 
         
             
                margin: 0 auto;
         
     | 
| 108 | 
         
             
                max-width: 1000px;
         
     | 
| 
         | 
|
| 110 | 
         
             
            """
         
     | 
| 111 | 
         | 
| 112 | 
         
             
            with gr.Blocks(css=css) as demo:
         
     | 
| 113 | 
         
            +
             
     | 
| 114 | 
         
             
                with gr.Column(elem_id="col-container"):
         
     | 
| 115 | 
         
             
                    gr.Markdown(f"""# IC-Edit
         
     | 
| 116 | 
         
             
            A demo for [IC-Edit](https://arxiv.org/pdf/2504.20690).
         
     | 
| 
         | 
|
| 134 | 
         
             
                                container=False,
         
     | 
| 135 | 
         
             
                            )
         
     | 
| 136 | 
         
             
                            run_button = gr.Button("Run")
         
     | 
| 137 | 
         
            +
             
     | 
| 138 | 
         
             
                        result = gr.Image(label="Result", show_label=False)
         
     | 
| 139 | 
         
            +
             
     | 
| 140 | 
         
            +
                    with gr.Accordion("Advanced Settings", open=True):
         
     | 
| 141 | 
         
            +
             
     | 
| 142 | 
         
             
                        seed = gr.Slider(
         
     | 
| 143 | 
         
             
                            label="Seed",
         
     | 
| 144 | 
         
             
                            minimum=0,
         
     | 
| 
         | 
|
| 146 | 
         
             
                            step=1,
         
     | 
| 147 | 
         
             
                            value=0,
         
     | 
| 148 | 
         
             
                        )
         
     | 
| 149 | 
         
            +
             
     | 
| 150 | 
         
             
                        randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
         
     | 
| 151 | 
         
            +
             
     | 
| 152 | 
         
             
                        with gr.Row():
         
     | 
| 153 | 
         
            +
             
     | 
| 154 | 
         
             
                            width = gr.Slider(
         
     | 
| 155 | 
         
             
                                label="Width",
         
     | 
| 156 | 
         
             
                                minimum=512,
         
     | 
| 
         | 
|
| 159 | 
         
             
                                value=1024,
         
     | 
| 160 | 
         
             
                                visible=False
         
     | 
| 161 | 
         
             
                            )
         
     | 
| 162 | 
         
            +
             
     | 
| 163 | 
         
             
                            height = gr.Slider(
         
     | 
| 164 | 
         
             
                                label="Height",
         
     | 
| 165 | 
         
             
                                minimum=512,
         
     | 
| 
         | 
|
| 168 | 
         
             
                                value=1024,
         
     | 
| 169 | 
         
             
                                visible=False
         
     | 
| 170 | 
         
             
                            )
         
     | 
| 171 | 
         
            +
             
     | 
| 172 | 
         
             
                        with gr.Row():
         
     | 
| 173 | 
         | 
| 174 | 
         
             
                            guidance_scale = gr.Slider(
         
     | 
| 
         | 
|
| 178 | 
         
             
                                step=0.5,
         
     | 
| 179 | 
         
             
                                value=50,
         
     | 
| 180 | 
         
             
                            )
         
     | 
| 181 | 
         
            +
             
     | 
| 182 | 
         
             
                            num_inference_steps = gr.Slider(
         
     | 
| 183 | 
         
             
                                label="Number of inference steps",
         
     | 
| 184 | 
         
             
                                minimum=1,
         
     | 
| 
         | 
|
| 187 | 
         
             
                                value=28,
         
     | 
| 188 | 
         
             
                            )
         
     | 
| 189 | 
         | 
| 190 | 
         
            +
                    # 添加 Gradio 示例组件
         
     | 
| 191 | 
         
            +
                    gr.Examples(
         
     | 
| 192 | 
         
            +
                        examples=new_examples,
         
     | 
| 193 | 
         
            +
                        inputs=[edit_image, prompt, seed],
         
     | 
| 194 | 
         
            +
                        outputs=[result, seed],
         
     | 
| 195 | 
         
            +
                        fn=infer,
         
     | 
| 196 | 
         
            +
                        cache_examples=False
         
     | 
| 197 | 
         
            +
                    )
         
     | 
| 198 | 
         
            +
             
     | 
| 199 | 
         
             
                gr.on(
         
     | 
| 200 | 
         
             
                    triggers=[run_button.click, prompt.submit],
         
     | 
| 201 | 
         
            +
                    fn=infer,
         
     | 
| 202 | 
         
            +
                    inputs=[edit_image, prompt, seed, randomize_seed, width, height, guidance_scale, num_inference_steps],
         
     | 
| 203 | 
         
            +
                    outputs=[result, seed]
         
     | 
| 204 | 
         
             
                )
         
     | 
| 205 | 
         | 
| 206 | 
         
             
            demo.launch(server_port=args.port)
         
     |