From e027179ee4efde0cecc5f077fc6a3c8b2330d4bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E9=9B=AA=E5=B3=B0?= Date: Wed, 3 Jan 2024 15:40:02 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=8E=A5=E5=8F=A3=EF=BC=9A?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BC=A0prompt=5Fid=E7=9A=84=E4=B8=AD?= =?UTF-8?q?=E6=96=AD=E4=BB=BB=E5=8A=A1=E6=8E=A5=E5=8F=A3=E5=92=8C/prompt?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- easyapi/api.py | 55 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) diff --git a/easyapi/api.py b/easyapi/api.py index def8051..bfac97c 100644 --- a/easyapi/api.py +++ b/easyapi/api.py @@ -1,5 +1,7 @@ import os import json + +import nodes from server import PromptServer from aiohttp import web import execution @@ -62,8 +64,59 @@ def register_routes(): return web.json_response({"maxSize": maxSize}) + @PromptServer.instance.routes.post("/easyapi/prompt") + async def post_prompt(request): + print("got prompt") + json_data = await request.json() + json_data = PromptServer.instance.trigger_on_prompt(json_data) + prompt_id = json_data["prompt_id"] + print("prompt_id={}".format(json_data["prompt_id"])) + + if "number" in json_data: + number = float(json_data['number']) + else: + number = PromptServer.instance.number + if "front" in json_data: + if json_data['front']: + number = -number + + PromptServer.instance.number += 1 + + if "prompt" in json_data: + prompt = json_data["prompt"] + valid = execution.validate_prompt(prompt) + extra_data = {} + if "extra_data" in json_data: + extra_data = json_data["extra_data"] + + if "client_id" in json_data: + extra_data["client_id"] = json_data["client_id"] + if valid[0]: + outputs_to_execute = valid[2] + PromptServer.instance.prompt_queue.put((number, prompt_id, prompt, extra_data, outputs_to_execute)) + response = {"prompt_id": prompt_id, "number": number, "node_errors": valid[3]} + return web.json_response(response) + else: + print("invalid prompt:", valid[1]) + return web.json_response({"error": valid[1], "node_errors": valid[3]}, status=400) + else: + return web.json_response({"error": "no prompt", "node_errors": []}, status=400) + + @PromptServer.instance.routes.post("/easyapi/interrupt") + async def post_interrupt(request): + json_data = await request.json() + prompt_id = json_data["prompt_id"] + current_queue = PromptServer.instance.prompt_queue.get_current_queue() + queue_running = current_queue[0] + if queue_running is not None: + if queue_running[1] == prompt_id: + nodes.interrupt_processing() + + delete_func = lambda a: a[1] == prompt_id + PromptServer.instance.prompt_queue.delete_queue_item(delete_func) + return web.Response(status=200) + def init(): reset_history_size(isStart=True) register_routes() -