From dee29292682deecbeddd10f9d7ebfd631c4ee201 Mon Sep 17 00:00:00 2001 From: jingrow Date: Tue, 20 May 2025 20:13:09 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96jupscale?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/jupscale/service.py | 47 ++++++++-------------------------------- 1 file changed, 9 insertions(+), 38 deletions(-) diff --git a/apps/jupscale/service.py b/apps/jupscale/service.py index 3b08386..55236a4 100644 --- a/apps/jupscale/service.py +++ b/apps/jupscale/service.py @@ -29,47 +29,26 @@ workflow_template = """ "inputs": { "model_name": "" }, - "class_type": "UpscaleModelLoader", - "_meta": { - "title": "Load Upscale Model" - } + "class_type": "UpscaleModelLoader" }, "14": { "inputs": { - "upscale_model": [ - "13", - 0 - ], - "image": [ - "15", - 0 - ] + "upscale_model": ["13", 0], + "image": ["15", 0] }, - "class_type": "ImageUpscaleWithModel", - "_meta": { - "title": "Upscale Image (using Model)" - } + "class_type": "ImageUpscaleWithModel" }, "15": { "inputs": { "url_or_path": "" }, - "class_type": "LoadImageFromUrlOrPath", - "_meta": { - "title": "LoadImageFromUrlOrPath" - } + "class_type": "LoadImageFromUrlOrPath" }, "16": { "inputs": { - "images": [ - "14", - 0 - ] + "images": ["14", 0] }, - "class_type": "SaveImageWebsocket", - "_meta": { - "title": "SaveImageWebsocket" - } + "class_type": "SaveImageWebsocket" } } """ @@ -131,8 +110,7 @@ class ImageUpscaleService: p = {"prompt": prompt, "client_id": client_id} data = json.dumps(p).encode('utf-8') req = urllib.request.Request(f"http://{comfyui_server_address}/prompt", data=data) - response = json.loads(urllib.request.urlopen(req).read()) - return response + return json.loads(urllib.request.urlopen(req).read()) def get_images(self, ws: websocket.WebSocket, workflow: Dict, comfyui_server_address: str, client_id: str) -> Dict: """从 ComfyUI 获取生成的图像""" @@ -261,15 +239,8 @@ class ImageUpscaleService: """异步放大图像,返回图片URL""" try: # 在这种情况下,我们需要手动运行同步生成器并收集结果 - urls = [] - - # 在执行器中运行同步代码 - def run_sync(): - return list(self.upscale_image_sync(image_url, config)) - - # 获取所有URL loop = asyncio.get_event_loop() - urls = await loop.run_in_executor(None, run_sync) + urls = await loop.run_in_executor(None, lambda: list(self.upscale_image_sync(image_url, config))) # 逐个返回结果 for url in urls: