stable-diffusion-webui icon indicating copy to clipboard operation
stable-diffusion-webui copied to clipboard

[Feature Request]: Add Hypernetwork Refresh API for API Mode.

Open FEXAQAQ opened this issue 11 months ago • 1 comments

Is there an existing issue for this?

  • [x] I have searched the existing issues and checked the recent builds/commits

What would your feature do ?

Hello,

I've recently been working with Stable Diffusion and my project is deployed on a server, necessitating operation via API mode. I noticed that the API includes functions like refresh-checkpoints / reload-checkpoint. However, I've found there's no API for updating the hypernetwork list. This absence means that when new .pt files are added during service operation, they cannot be immediately read, and a complete service restart is required.

As an aside, I noticed there's a refresh button in the web API, but I couldn't find a corresponding API endpoint. image

Lastly, I apologize as my English is not very strong and my coding skills are somewhat limited. I appreciate any guidance or advice.

Thank you.

my stable-diffusion-webui version : 1.4.1

FEXAQAQ avatar Mar 19 '24 07:03 FEXAQAQ

I found the reload_hypernetworks method in "shared.py".

 def reload_hypernetworks():
    from modules.hypernetworks import hypernetwork
    global hypernetworks
    hypernetworks = hypernetwork.list_hypernetworks(cmd_opts.hypernetwork_dir)

The simplest way is to create a new api route in api.py to call it. step1. add api route :

self.add_api_route("/sdapi/v1/reload-hypernetwork", self.reload_hypernetwork, methods=["POST"])

step2. add reload_hypernetwork function :

    def reload_hypernetwork(self):
        with self.queue_lock:
            shared.reload_hypernetworks()

This method can solve the problem when multiple services are running and all services use unified model resources. When manually adding a hypernetwork model, you can directly use this API to reload it without restarting the service to obtain the latest list.

FEXAQAQ avatar Mar 19 '24 10:03 FEXAQAQ