Add batch image chooser gate
This commit is contained in:
@@ -8,6 +8,7 @@ from PIL import Image
|
||||
from server import PromptServer
|
||||
|
||||
from .gate_bus import GateBus
|
||||
from .image_chooser import encode_previews, normalize_selection
|
||||
|
||||
routes = PromptServer.instance.routes
|
||||
|
||||
@@ -23,6 +24,22 @@ def send_preview(node_id, image, n_routes):
|
||||
)
|
||||
|
||||
|
||||
def send_image_choices(node_id, token, images):
|
||||
"""Show a lightweight preview of every image to the queuing client."""
|
||||
server = PromptServer.instance
|
||||
server.send_sync(
|
||||
"datasete-image-chooser-show",
|
||||
{
|
||||
"id": str(node_id),
|
||||
"display_id": str(getattr(server, "last_node_id", None) or node_id),
|
||||
"token": token,
|
||||
"images": encode_previews(images),
|
||||
"count": int(images.shape[0]),
|
||||
},
|
||||
getattr(server, "client_id", None),
|
||||
)
|
||||
|
||||
|
||||
@routes.post("/datasete_gate/choice")
|
||||
async def _choice(request):
|
||||
post = await request.post()
|
||||
@@ -44,6 +61,35 @@ async def _mask(request):
|
||||
return web.json_response({})
|
||||
|
||||
|
||||
@routes.post("/datasete_image_chooser/select")
|
||||
async def _image_chooser_select(request):
|
||||
post = await request.post()
|
||||
node_id = post.get("id")
|
||||
token = post.get("token")
|
||||
if node_id is None or token is None:
|
||||
return web.json_response({"error": "missing node id or token"}, status=400)
|
||||
|
||||
batch_size = GateBus.token_context(node_id, token)
|
||||
if batch_size is None:
|
||||
return web.json_response({"error": "chooser run is no longer active"}, status=409)
|
||||
|
||||
if post.get("action") == "cancel":
|
||||
accepted = GateBus.cancel_token(node_id, token)
|
||||
else:
|
||||
selection = post.get("selection")
|
||||
if selection is None:
|
||||
return web.json_response({"error": "missing selection"}, status=400)
|
||||
try:
|
||||
selection = normalize_selection(selection, batch_size)
|
||||
except ValueError as exc:
|
||||
return web.json_response({"error": str(exc)}, status=400)
|
||||
accepted = GateBus.put_token_payload(node_id, token, selection)
|
||||
|
||||
if not accepted:
|
||||
return web.json_response({"error": "chooser run is no longer active"}, status=409)
|
||||
return web.json_response({})
|
||||
|
||||
|
||||
def send_text(node_id, text):
|
||||
PromptServer.instance.send_sync(
|
||||
"datasete-textgate-show", {"id": str(node_id), "text": text or ""}
|
||||
|
||||
Reference in New Issue
Block a user