Add button to unload models manually.

This commit is contained in:
Ean Garvey
2024-05-30 14:50:38 -04:00
parent 6dfded3759
commit fe142c8a0b
2 changed files with 12 additions and 5 deletions

View File

@@ -434,6 +434,14 @@ def shark_sd_fn(
return (generated_imgs, "")
def unload_sd():
print("Unloading models.")
import apps.shark_studio.web.utils.globals as global_obj
global_obj.clear_cache()
gc.collect()
def cancel_sd():
print("Inject call to cancel longer API calls.")
return

View File

@@ -19,6 +19,7 @@ from apps.shark_studio.web.utils.file_utils import (
from apps.shark_studio.api.sd import (
shark_sd_fn_dict_input,
cancel_sd,
unload_sd,
)
from apps.shark_studio.api.controlnet import (
cnet_preview,
@@ -611,11 +612,9 @@ with gr.Blocks(title="Stable Diffusion") as sd_element:
)
with gr.Row():
stable_diffusion = gr.Button("Start")
random_seed = gr.Button("Randomize Seed")
random_seed.click(
lambda: -1,
inputs=[],
outputs=[seed],
unload = gr.Button("Unload Models")
unload.click(
fn=unload_sd,
queue=False,
show_progress=False,
)