import gradio as gr from modules import shared, scripts, sd_models class Script(scripts.Script): def title(self): return 'LayerDiffuse: Transparent Image' def show(self, is_img2img): return True if shared.native else False def apply(self): from modules import layerdiffuse if not shared.sd_loaded: shared.log.error('LayerDiffuse: model not loaded') return self.is_active() if shared.sd_model_type != 'sd' and shared.sd_model_type != 'sdxl': shared.log.error(f'LayerDiffuse: incorrect base model: class={shared.sd_model.__class__.__name__} type={shared.sd_model_type}') return self.is_active() if hasattr(shared.sd_model, 'layerdiffusion'): shared.log.warning('LayerDiffuse: already applied') return self.is_active() layerdiffuse.apply_layerdiffuse() return self.is_active() def reload(self): sd_models.reload_model_weights(force=True) return self.is_active() def is_active(self): if not shared.sd_loaded: return '
LayerDiffuse: model not loaded

' if shared.sd_model_type != 'sd' and shared.sd_model_type != 'sdxl': return '
LayerDiffuse: incorrect base model

' if hasattr(shared.sd_model, 'layerdiffusion'): return '
LayerDiffuse: active

' return '
LayerDiffuse: inactive

' def ui(self, _is_img2img): with gr.Row(): gr.HTML("""   LayerDiffuse: Transparent Image

- Click Apply to model to apply LayerDiffuse to current model
- Click Reload model to remove LayerDiffuse from current model

""") with gr.Row(): active = gr.HTML('') with gr.Row(): check_btn = gr.Button('Check status', variant='primary') apply_btn = gr.Button('Apply to model', variant='primary') reload_btn = gr.Button('Reload model', variant='primary') check_btn.click(fn=self.is_active, inputs=[], outputs=[active]) apply_btn.click(fn=self.apply, inputs=[], outputs=[active]) reload_btn.click(fn=self.reload, inputs=[], outputs=[active]) return []