MCPcopy Create free account
hub / github.com/ali-vilab/ACE_plus / set_callbacks

Method set_callbacks

demo_lora.py:258–501  ·  view source on GitHub ↗
(self, *args, **kwargs)

Source from the content-addressed store, hash-verified

256
257
258 def set_callbacks(self, *args, **kwargs):
259 ########################################
260 def change_model(model_name):
261 if model_name not in self.model_choices:
262 gr.Info('The provided model name is not a valid choice!')
263 return model_name, gr.update(), gr.update()
264
265 if model_name != self.model_name:
266 lock.acquire()
267 del self.pipe
268 torch.cuda.empty_cache()
269 torch.cuda.ipc_collect()
270 pipe_cfg = self.model_choices[model_name]
271 infer_name = pipe_cfg.get("INFERENCE_TYPE", "ACE")
272 self.pipe = inference_dict[infer_name]()
273 self.pipe.init_from_cfg(pipe_cfg)
274 self.model_name = model_name
275 lock.release()
276
277 return (model_name, gr.update(),
278 gr.Slider(
279 value=self.pipe.input.get("sample_steps", 20),
280 visible=self.pipe.input.get("sample_steps", None) is not None),
281 gr.Slider(
282 value=self.pipe.input.get("guide_scale", 4.5),
283 visible=self.pipe.input.get("guide_scale", None) is not None),
284 gr.Slider(
285 value=self.pipe.input.get("output_height", 1024),
286 visible=self.pipe.input.get("output_height", None) is not None),
287 gr.Slider(
288 value=self.pipe.input.get("output_width", 1024),
289 visible=self.pipe.input.get("output_width", None) is not None),
290 gr.Slider(value=self.pipe.input.get("repainting_scale", 1.0))
291 )
292
293 self.model_name_dd.change(
294 change_model,
295 inputs=[self.model_name_dd],
296 outputs=[
297 self.model_name_dd, self.text,
298 self.step,
299 self.cfg_scale,
300 self.output_height,
301 self.output_width,
302 self.repainting_scale])
303
304 def change_task_type(task_type):
305 task_info = self.task_model[task_type]
306 edit_type_list = [self.edit_type_list[0]]
307 for preprocessor in task_info.get("PREPROCESSOR", []):
308 preprocessor["REPAINTING_SCALE"] = task_info.get("REPAINTING_SCALE", 1.0)
309 self.edit_type_dict[preprocessor["TYPE"]] = preprocessor
310 edit_type_list.append(preprocessor["TYPE"])
311
312 return gr.update(choices=edit_type_list, value=edit_type_list[0])
313
314 self.task_type.change(change_task_type, inputs=[self.task_type], outputs=[self.edit_type])
315

Callers 1

run_grFunction · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected