picobyte / stable-diffusion-webui-wd14-tagger

Labeling extension for Automatic1111's Web UI
539 stars 64 forks source link

Async behavior improvement #69

Open picobyte opened 9 months ago

picobyte commented 9 months ago

The current async api implementation works, or at least passed my tests, except for one: I had a slightly different behavior in mind. I'll describe with shell commands, what behavior I'd like to mimic (bash commands executed in a single terminal, or the 'wait' won't work - you could make it work with pids and ps, but off-topic):

# queue interrogation
curl -X 'POST' \
  "http://127.0.0.1:7860/tagger/v1/interrogate" \
  -H 'accept: application/json' \
  -H 'Content-Type: application/json' \
  -d '{ "image": "'"$(base64 < 1.png)"'", "model": "wd14-vit.v1", "threshold": 0.0, "name_in_queue": "1", "queue": "" }'
# first responds includes the new queue id, e.g. '8v1zyWv25'

# => ideally above command should also go in background and the printing should be instant, but this cannot be replicated in bash in bash (which prints after completion)

# add another image for the same queue, but this and the remainder, except the last in background - note the '&' at the end of the command:
curl -X 'POST' \
  "http://127.0.0.1:7860/tagger/v1/interrogate" \
  -H 'accept: application/json' \
  -H 'Content-Type: application/json' \
  -d '{ "image": "'"$(base64 < 2.png)"'", "model": "wd14-vit.v1", "threshold": 0.0, "name_in_queue": "2", "queue": "8v1zyWv25'A" }'&

# ..and queue many more..
# ..
# .. and finally, end the queue..

# but first make sure all background jobs have finished:
wait

# to print the interrogation results per given name, and close the queue:
curl -X 'POST' \
  "http://127.0.0.1:7860/tagger/v1/interrogate" \
  -H 'accept: application/json' \
  -H 'Content-Type: application/json' \
  -d '{ "image": "", "model": "wd14-vit.v1", "threshold": 0.0, "name_in_queue": "", "queue": "8v1zyWv25'A" }'