img server
This commit is contained in:
@@ -267,8 +267,7 @@ def main_dev(opt):
|
||||
|
||||
# 检查输出目录是否存在
|
||||
os.makedirs(opt.outdir, exist_ok=True)
|
||||
# 绝对路径
|
||||
outpath = os.path.join(opt.outdir)
|
||||
outpath = opt.outdir
|
||||
|
||||
# 创建水印编码器
|
||||
wm = "SDV2"
|
||||
@@ -329,6 +328,7 @@ def main_dev(opt):
|
||||
for x_sample in x_samples:
|
||||
print("Sample count:", sample_count)
|
||||
imge_path = os.path.join(sample_path, f"{base_count:05}.png")
|
||||
imge_path = os.path.abspath(imge_path) # 转换为绝对路径
|
||||
x_sample = 255. * rearrange(x_sample.cpu().numpy(), 'c h w -> h w c')
|
||||
img = Image.fromarray(x_sample.astype(np.uint8))
|
||||
img = put_watermark(img, wm_encoder)
|
||||
|
@@ -2,7 +2,11 @@ export default defineEventHandler(async event => {
|
||||
|
||||
// 获取任务(普通用户只能看到自己的)
|
||||
if (event.node.req.method === 'GET') {
|
||||
return await useStorage().getItem(`task:${event.context.params.id}`)
|
||||
const task = await useStorage().getItem(`task:${event.context.params.id}`)
|
||||
task.data = task.data.map((image_path: any) => {
|
||||
return '/api/img/' + image_path.match(/[^\/]+$/)[0]
|
||||
})
|
||||
return task
|
||||
}
|
||||
|
||||
// 修改任务(只允许BOT写入)
|
||||
|
14
server/api/img/[id].ts
Normal file
14
server/api/img/[id].ts
Normal file
@@ -0,0 +1,14 @@
|
||||
import fs from 'fs'
|
||||
export default defineEventHandler(async event => {
|
||||
|
||||
// 获取图片
|
||||
if (event.node.req.method === 'GET') {
|
||||
// 判断当前执行目录是否存在 outputs 文件夹, 否则在上一级文件夹
|
||||
let path = `outputs/outputs/txt2img-samples/samples/${event.context.params.id}`
|
||||
if (!fs.existsSync('outputs')) {
|
||||
path = `../outputs/outputs/txt2img-samples/samples/${event.context.params.id}`
|
||||
}
|
||||
return await useStorage().getItem(`img:${event.context.params.id}`)
|
||||
}
|
||||
|
||||
})
|
Reference in New Issue
Block a user