Skip to content

Commit

Permalink
Add button to unload models manually.
Browse files Browse the repository at this point in the history
  • Loading branch information
eagarvey-amd committed May 30, 2024
1 parent 6dfded3 commit fe142c8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
8 changes: 8 additions & 0 deletions apps/shark_studio/api/sd.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 4 additions & 5 deletions apps/shark_studio/web/ui/sd.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
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,
Expand Down Expand Up @@ -611,11 +612,9 @@ def base_model_changed(base_model_id):
)
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,
)
Expand Down

0 comments on commit fe142c8

Please sign in to comment.