AUTOMATIC1111 / stable-diffusion-webui

Stable Diffusion web UI
GNU Affero General Public License v3.0
140.63k stars 26.61k forks source link

[Feature Request]: Add an API endpoint for refreshing Embeddings #13994

Open chevyriet opened 10 months ago

chevyriet commented 10 months ago

Is there an existing issue for this?

What would your feature do ?

I am currently running 2 instances of the WebUI locally, and that (for performance reasons) both use different hardware for different tasks. I interact with those via a backend communicating with the API. When I create an embedding on one instance it needs a manual refresh (e.g. refreshing the browser window, using the button in the UI etc) before the other instance can use it.

As far as I know its currently possible to do something like refreshing via the API only for Checkpoints and VAE's, not for embeddings.

An API endpoint for refreshing the embeddings would be a big problem solver for not only my use-case but lots of others in terms of automation.

Proposed workflow

In my case:

  1. Perform an operation on an embedding that needs a refresh to be accessed somewhere else (e.g. another instance)
  2. Make a request to the corresponding URL for refreshing embeddings as shown in the API docs
  3. Use the newly available embedding any way you want in your preferred location

Additional information

No response

chevyriet commented 10 months ago

Bad practice temporary solution I used for this:

MagicReader commented 9 months ago

Here's how I built it(sdapi/v1/refresh-embeddings)in api.py, after refreshing the query in the api updated(sdapi/v1/embeddings), but the ui content is not updated.All this is for reference only:

  1. self.add_api_route("/sdapi/v1/refresh-embeddings", self.refresh_embeddings, methods=["POST"])

  2. def refresh_embeddings(self): sd_hijack.model_hijack.embedding_db.load_textual_inversion_embeddings(force_reload=True)

image

image

image

stefanbenten commented 7 months ago

This should be fine to close as done now. @AUTOMATIC1111 @chevyriet