control api

This commit is contained in:
Vladimir Mandic
2024-03-27 11:33:29 -04:00
parent 738f115d06
commit 89e9debbcd
11 changed files with 199 additions and 83 deletions
+21 -5
View File
@@ -12,6 +12,7 @@ from modules.control.units import reference # pylint: disable=unused-import
default_device = None
default_dtype = None
unit_types = ['t2i adapter', 'controlnet', 'xs', 'lite', 'reference', 'ip']
class Unit(): # mashup of gradio controls and mapping to actual implementation classes
@@ -135,22 +136,34 @@ class Unit(): # mashup of gradio controls and mapping to actual implementation c
# bind ui controls to properties if present
if self.type == 't2i adapter':
if model_id is not None:
model_id.change(fn=self.adapter.load, inputs=[model_id], outputs=[result_txt], show_progress=True)
if isinstance(model_id, str):
self.adapter.load(model_id)
else:
model_id.change(fn=self.adapter.load, inputs=[model_id], outputs=[result_txt], show_progress=True)
if extra_controls is not None and len(extra_controls) > 0:
extra_controls[0].change(fn=adapter_extra, inputs=extra_controls)
elif self.type == 'controlnet':
if model_id is not None:
model_id.change(fn=self.controlnet.load, inputs=[model_id], outputs=[result_txt], show_progress=True)
if isinstance(model_id, str):
self.controlnet.load(model_id)
else:
model_id.change(fn=self.controlnet.load, inputs=[model_id], outputs=[result_txt], show_progress=True)
if extra_controls is not None and len(extra_controls) > 0:
extra_controls[0].change(fn=controlnet_extra, inputs=extra_controls)
elif self.type == 'xs':
if model_id is not None:
model_id.change(fn=self.controlnet.load, inputs=[model_id, extra_controls[0]], outputs=[result_txt], show_progress=True)
if isinstance(model_id, str):
self.controlnet.load(model_id)
else:
model_id.change(fn=self.controlnet.load, inputs=[model_id, extra_controls[0]], outputs=[result_txt], show_progress=True)
if extra_controls is not None and len(extra_controls) > 0:
extra_controls[0].change(fn=controlnetxs_extra, inputs=extra_controls)
elif self.type == 'lite':
if model_id is not None:
model_id.change(fn=self.controlnet.load, inputs=[model_id], outputs=[result_txt], show_progress=True)
if isinstance(model_id, str):
self.controlnet.load(model_id)
else:
model_id.change(fn=self.controlnet.load, inputs=[model_id], outputs=[result_txt], show_progress=True)
if extra_controls is not None and len(extra_controls) > 0:
extra_controls[0].change(fn=controlnetxs_extra, inputs=extra_controls)
elif self.type == 'reference':
@@ -164,7 +177,10 @@ class Unit(): # mashup of gradio controls and mapping to actual implementation c
if model_strength is not None:
model_strength.change(fn=strength_change, inputs=[model_strength])
if process_id is not None:
process_id.change(fn=self.process.load, inputs=[process_id], outputs=[result_txt], show_progress=True)
if isinstance(process_id, str):
self.process.load(process_id)
else:
process_id.change(fn=self.process.load, inputs=[process_id], outputs=[result_txt], show_progress=True)
if reset_btn is not None:
reset_btn.click(fn=reset, inputs=[], outputs=[enabled_cb, model_id, process_id, model_strength])
if preview_btn is not None: