(self, root: gr.Blocks)
| 143 | self.submit_button = gr.Button("Enqueue", elem_id=f"{id_part}_enqueue", variant="primary") |
| 144 | |
| 145 | def bind_enqueue_button(self, root: gr.Blocks): |
| 146 | generate = self.generate_button |
| 147 | is_img2img = self.is_img2img |
| 148 | dependencies: List[dict] = [ |
| 149 | x for x in root.dependencies if x["trigger"] == "click" and generate._id in x["targets"] |
| 150 | ] |
| 151 | |
| 152 | dependency: dict = None |
| 153 | cnet_dependency: dict = None |
| 154 | UiControlNetUnit = None |
| 155 | for d in dependencies: |
| 156 | if len(d["outputs"]) == 1: |
| 157 | outputs = get_components_by_ids(root, d["outputs"]) |
| 158 | output = outputs[0] |
| 159 | if isinstance(output, gr.State) and type(output.value).__name__ == "UiControlNetUnit": |
| 160 | cnet_dependency = d |
| 161 | UiControlNetUnit = type(output.value) |
| 162 | |
| 163 | elif len(d["outputs"]) == 4: |
| 164 | dependency = d |
| 165 | |
| 166 | with root: |
| 167 | if self.checkpoint_dropdown is not None: |
| 168 | self.checkpoint_dropdown.change(fn=self.on_checkpoint_changed, inputs=[self.checkpoint_dropdown]) |
| 169 | |
| 170 | fn_block = next(fn for fn in root.fns if compare_components_with_ids(fn.inputs, dependency["inputs"])) |
| 171 | fn = self.wrap_register_ui_task() |
| 172 | inputs = fn_block.inputs.copy() |
| 173 | inputs.insert(0, self.checkpoint_dropdown) |
| 174 | args = dict( |
| 175 | fn=fn, |
| 176 | _js="submit_enqueue_img2img" if is_img2img else "submit_enqueue", |
| 177 | inputs=inputs, |
| 178 | outputs=None, |
| 179 | show_progress=False, |
| 180 | ) |
| 181 | |
| 182 | self.submit_button.click(**args) |
| 183 | |
| 184 | if cnet_dependency is not None: |
| 185 | cnet_fn_block = next( |
| 186 | fn for fn in root.fns if compare_components_with_ids(fn.inputs, cnet_dependency["inputs"]) |
| 187 | ) |
| 188 | self.submit_button.click( |
| 189 | fn=UiControlNetUnit, |
| 190 | inputs=cnet_fn_block.inputs, |
| 191 | outputs=cnet_fn_block.outputs, |
| 192 | queue=False, |
| 193 | ) |
| 194 | |
| 195 | def wrap_register_ui_task(self): |
| 196 | def f(request: gr.Request, *args): |
no test coverage detected