From 12c62c5af9c6fa457b1c54888356012ed2ebb0f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A1=9C=E8=8F=AF?= Date: Sat, 18 Feb 2023 20:26:08 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=84=E7=90=86=E5=AE=8C=E6=88=90=E5=90=8E?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BB=BB=E5=8A=A1=E7=8A=B6=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server.py | 13 ++++++++++--- server/api/drawing.ts | 4 +++- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/server.py b/server.py index 3cff17b..806cf14 100644 --- a/server.py +++ b/server.py @@ -213,6 +213,12 @@ def put_watermark(img, wm_encoder=None): import time import requests +# 对任务状态的修改 +def update_task_status(task:dict, status:str, progress:int): + task["status"] = status + task["progress"] = progress + requests.put(f"http://localhost:3000/api/drawing/{task['id']}", data=task) + def main_dev(opt): model_name = '' # 默认模型 model = None # 默认模型 @@ -303,7 +309,7 @@ def main_dev(opt): start_code = None if opt.fixed_code: start_code = torch.randn([opt.n_samples, opt.C, opt.H // opt.f, opt.W // opt.f], device=device) - # x + # 切换模型 if opt.torchscript or opt.ipex: transformer = model.cond_stage_model.model unet = model.model.diffusion_model @@ -410,8 +416,9 @@ def main_dev(opt): grid = put_watermark(grid, wm_encoder) grid.save(os.path.join(outpath, f'grid-{grid_count:04}.png')) grid_count += 1 - print(f"Your samples are ready and waiting for you here: \n{outpath} \n" - f" \nEnjoy.") + print(f"Your samples are ready and waiting for you here: \n{outpath} \n", f" \nEnjoy.") + # 修改任务状态为完成 + update_task_status(task=item, status='done', progress=1) # 任务结束, 等待20s后退出 print("任务结束, 等待20s后退出..") time.sleep(20) diff --git a/server/api/drawing.ts b/server/api/drawing.ts index cc12ded..01d4092 100644 --- a/server/api/drawing.ts +++ b/server/api/drawing.ts @@ -38,7 +38,6 @@ export default defineEventHandler(async event => { const body = await readBody(event) // 读取body数据到 body.tid = Math.random().toString(36).substring(2, 34) // 生成随机任务ID body.uid = 1234567890 // 用户ID - body.status = 'waiting' // 任务状态 body.createdAt = new Date().getTime() // 设定创建时间 // 验证需要输入的参数 body.model = 'SD2' // 模型 @@ -52,6 +51,9 @@ export default defineEventHandler(async event => { body.sampler = 'pndm' // 扩散采样器 body.prompt_guidance = 0.5 // 提示词权重 body.quality_details = 25 // 质量和细节(步数) + // 输出参数 + body.status = 'waiting' // 任务状态 + body.progress = 0.00 // 任务进度 body.image = '' // 图片数据 body.data = null // 生成结果 console.log('task:', body)