From db3d86204fa28b232555ee52f4a3d86bd47ef4e3 Mon Sep 17 00:00:00 2001 From: zhouchengrong Date: Tue, 25 Jun 2024 16:58:17 +0800 Subject: [PATCH] =?UTF-8?q?feat=20=E6=96=B0=E5=A2=9E=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E6=8F=8F=E8=BF=B0=20docs=E9=A1=B5=E9=9D=A2=20=EF=BC=8C?= =?UTF-8?q?=E6=96=B0=E5=A2=9ES3=20=E5=9B=BE=E7=89=87get=20upload=20?= =?UTF-8?q?=E6=93=8D=E4=BD=9C=EF=BC=8C=E6=95=B4=E7=90=86=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fix --- app/api/api_attribute_retrieve.py | 31 + app/api/api_chat_robot.py | 18 +- app/api/api_design.py | 120 +++ app/api/api_design_pre_processing.py | 18 + app/api/api_generate_image.py | 58 ++ app/api/api_prompt_generation.py | 10 + app/api/api_super_resolution.py | 13 + app/service/design/design_request.json | 101 --- app/service/design/design_request_2.json | 684 -------------- app/service/design/fastapi_request.json | 836 ++++++++++++++++-- app/service/design/items/pipelines/split.py | 2 - app/service/design/utils/synthesis_item.py | 12 +- app/service/design/utils/upload_image.py | 133 +-- app/service/design_pre_processing/service.py | 17 + .../generate_image/service_generate_image.py | 19 +- app/service/super_resolution/service.py | 1 - app/service/utils/oss_client.py | 10 +- 17 files changed, 1087 insertions(+), 996 deletions(-) delete mode 100644 app/service/design/design_request.json delete mode 100644 app/service/design/design_request_2.json diff --git a/app/api/api_attribute_retrieve.py b/app/api/api_attribute_retrieve.py index 7a14e9d..d9b210c 100644 --- a/app/api/api_attribute_retrieve.py +++ b/app/api/api_attribute_retrieve.py @@ -1,5 +1,6 @@ import json import logging + from fastapi import APIRouter, HTTPException from app.core.config import DEBUG @@ -16,6 +17,22 @@ logger = logging.getLogger() # 属性识别 @router.post("/attribute_recognition", response_model=ResponseModel) def attribute_recognition(request_item: list[AttributeRecognitionModel]): + """ + 获取sketch的属性,collar sleeve_length 等等 + 创建一个具有以下参数的请求体: + - **category**: sketch的类别 ,Dress + - **colony**: 服装类别,男装或女装 + - **sketch_img_url**: 被提取属性的S3或minio url地址 + + 示例参数: + [ + { + "category": "Dress", + "colony": "Female", + "sketch_img_url": "aida-users/89/sketchboard/female/Dress/ae976103-d7ec-4eed-b5d1-3e5f04d8be26.jpg" + } + ] + """ try: logger.info(f"attribute_recognition request item is : @@@@@@:{request_item}") if DEBUG: @@ -33,6 +50,20 @@ def attribute_recognition(request_item: list[AttributeRecognitionModel]): # 类别识别 @router.post("/category_recognition") def category_recognition(request_item: list[CategoryRecognitionModel]): + """ + 获取sketch的类别,dress blouse 等等 + 创建一个具有以下参数的请求体: + - **colony**: 服装类别,male或Female + - **sketch_img_url**: 被提取sketch类别的S3或minio url地址 + + 示例参数: + [ + { + "colony": "Female", + "sketch_img_url": "aida-users/89/sketchboard/female/Dress/ae976103-d7ec-4eed-b5d1-3e5f04d8be26.jpg" + } + ] + """ try: logger.info(f"category_recognition request item is : @@@@@@:{request_item}") service = CategoryRecognition(request_data=request_item) diff --git a/app/api/api_chat_robot.py b/app/api/api_chat_robot.py index dccba9a..6f3da16 100644 --- a/app/api/api_chat_robot.py +++ b/app/api/api_chat_robot.py @@ -1,6 +1,6 @@ import json import logging -import time + from fastapi import APIRouter, HTTPException from app.schemas.chat_robot import ChatRobotModel @@ -13,6 +13,22 @@ logger = logging.getLogger() @router.post("/chat_robot") def chat_robot(request_data: ChatRobotModel): + """ + 对话机器人 + 创建一个具有以下参数的请求体: + - **gender**: 服装类别 + - **message**: 消息 + - **session_id**: 会话id + - **user_id**: 用户id + + 示例参数: + { + "gender": "male", + "message": "你好", + "session_id": "string-89", + "user_id": 89 + } + """ try: logger.info(f"chat_robot request item is : @@@@@@:{request_data}") data = chat(post_data=request_data) diff --git a/app/api/api_design.py b/app/api/api_design.py index ef0e085..c056c39 100644 --- a/app/api/api_design.py +++ b/app/api/api_design.py @@ -15,6 +15,106 @@ logger = logging.getLogger() @router.post("/design") def design(request_data: DesignModel): + """ + 创建一个具有以下参数的请求体: + 示例参数: + { + "objects": [ + { + "basic": { + "body_point_test": { + "waistband_right": [ + 336, + 264 + ], + "hand_point_right": [ + 350, + 303 + ], + "waistband_left": [ + 245, + 274 + ], + "hand_point_left": [ + 219, + 315 + ], + "shoulder_left": [ + 227, + 155 + ], + "shoulder_right": [ + 338, + 149 + ] + }, + "layer_order": false, + "scale_bag": 0.7, + "scale_earrings": 0.16, + "self_template": true, + "single_overall": "overall", + "switch_category": "" + }, + "items": [ + { + "color": "229 214 200", + "icon": "none", + "image_id": 110205, + "offset": [ + 1, + 1 + ], + "path": "aida-sys-image/images/female/trousers/0916000217.jpg", + "print": { + "IfSingle": false, + "print_path_list": [] + }, + "resize_scale": [ + 1.0, + 1.0 + ], + "type": "Trousers" + }, + { + "businessId": 493825, + "color": "209 125 29", + "elementId": 493825, + "icon": "none", + "image_id": 107101, + "offset": [ + 1, + 1 + ], + "path": "aida-users/31/sketchboard/female/Blouse/de8f5656-d7ae-4642-bc90-f7f9d85da09b.jpg", + "print": { + "IfSingle": false, + "print_path_list": [] + }, + "resize_scale": [ + 1.0, + 1.0 + ], + "type": "Blouse" + }, + { + "body_path": "aida-users/31/models/female/845046c7-4f62-4f54-a4a9-c26d49c6969335b5b3a9-d335-4871-a46c-3cc3caf07da259629dfd1f1f555a2e2a9def7e719366.png", + "image_id": 82966, + "offset": [ + 1, + 1 + ], + "resize_scale": [ + 1.0, + 1.0 + ], + "type": "Body" + } + ] + } + ], + "process_id": "6878547032381675" + } + """ try: logger.info(f"design request item is : @@@@@@:{request_data.dict()}") data = generate(request_data=request_data) @@ -27,6 +127,16 @@ def design(request_data: DesignModel): @router.post('/get_progress') def get_progress(request_data: DesignProgressModel): + """ + 获取design 进度 + 创建一个具有以下参数的请求体: + - **process_id**: 进度id + + 示例参数: + { + "process_id": "6878547032381675" + } + """ try: logger.info(f"get_progress request item is : @@@@@@:{request_data.dict()}") process_id = request_data.process_id @@ -43,6 +153,16 @@ def get_progress(request_data: DesignProgressModel): @router.post('/model_process') def model_process(request_data: ModelProgressModel): + """ + 获取模特图片预处理 + 创建一个具有以下参数的请求体: + - **model_path**: 模特图片的minio或s3 url地址 + + 示例参数: + { + "model_path": "aida-users/10/models/female/9c788f5b-b8c7-424c-b149-025aeb0bda51model.jpg" + } + """ try: logger.info(f"model_process request item is : @@@@@@:{request_data.dict()}") diff --git a/app/api/api_design_pre_processing.py b/app/api/api_design_pre_processing.py index bd87e00..f6946dc 100644 --- a/app/api/api_design_pre_processing.py +++ b/app/api/api_design_pre_processing.py @@ -1,6 +1,8 @@ import json import logging + from fastapi import APIRouter, HTTPException + from app.schemas.pre_processing import DesignPreProcessingModel from app.schemas.response_template import ResponseModel from app.service.design_pre_processing.service import DesignPreprocessing @@ -11,6 +13,22 @@ logger = logging.getLogger() @router.post("/design_pre_processing") def design_pre_processing(request_data: DesignPreProcessingModel): + """ + design 预处理 获取sketch的基本信息 + 创建一个具有以下参数的请求体: + - **sketches**: sketch url等信息 + + 示例参数: + { + "sketches": [ + { + "image_category": "dress", + "image_id": "107903", + "image_url": "aida-sys-image/images/female/dress/0628000000.jpg" + } + ] + } + """ try: logger.info(f"design_pre_processing request item is : @@@@@@:{request_data}") server = DesignPreprocessing() diff --git a/app/api/api_generate_image.py b/app/api/api_generate_image.py index 23fbb7f..2da5554 100644 --- a/app/api/api_generate_image.py +++ b/app/api/api_generate_image.py @@ -18,6 +18,25 @@ logger = logging.getLogger() @router.post("/generate_image") def generate_image(request_item: GenerateImageModel, background_tasks: BackgroundTasks): + """ + 创建一个具有以下参数的请求体: + - **tasks_id**: 任务id 用于取消生成任务和获取生成结果 + - **prompt**: 想要生成图片的描述词 + - **image_url**: 图生图的输入,minio或S3 url 地址 + - **mode**: 生成模式,img2img或者txt2img + - **category**: 生成图片的类别,sketch print 等等 + - **gender**: 生成sketch专用,服装类别 + + 示例参数: + { + "tasks_id": "123-89", + "prompt": "skeleton sitting by the side of a river looking soulful, concert poster, 4k, artistic", + "image_url": "aida-collection-element/87/Printboard/842c09cf-7297-42d9-9e6e-9c17d4a13cb5.jpg", + "mode": "img2img", + "category": "sketch", + "gender": "male" + } + """ try: logger.info(f"generate_image request item is : @@@@@@:{request_item}") service = GenerateImage(request_item) @@ -45,6 +64,19 @@ def generate_image(tasks_id: str): @router.post("/generate_single_logo") def generate_single_logo(request_item: GenerateSingleLogoImageModel, background_tasks: BackgroundTasks): + """ + 创建一个具有以下参数的请求体: + - **tasks_id**: 任务id 用于取消生成任务和获取生成结果 + - **prompt**: 想要生成图片的描述词 + - **seed**: 固定的prompt和固定的seed 每次的生成结果都是一样的 + + 示例参数: + { + "tasks_id": "123-89", + "prompt": "an apple", + "seed": "2" + } + """ try: logger.info(f"generate_single_logo request item is : @@@@@@:{request_item}") service = GenerateSingleLogoImage(request_item) @@ -72,6 +104,19 @@ def generate_single_logo_image(tasks_id: str): @router.post("/generate_product_image") def generate_product_image(request_item: GenerateProductImageModel, background_tasks: BackgroundTasks): + """ + 创建一个具有以下参数的请求体: + - **tasks_id**: 任务id 用于取消生成任务和获取生成结果 + - **prompt**: 想要生成图片的描述词 + - **image_url**: 被生成图片的S3或minio url地址 + + 示例参数: + { + "tasks_id": "123-89", + "prompt": "the best quality, masterpiece. detailed, high-res, simple background, studio photography, extremely detailed, updo, detailed face, face, close-up, HDR, UHD, 8K realistic, Highly detailed, simple background, Studio lighting", + "image_url": "aida-results/result_00097282-ebb2-11ee-a822-b48351119060.png" + } + """ try: logger.info(f"generate_product_image request item is : @@@@@@:{request_item}") service = GenerateProductImage(request_item) @@ -99,6 +144,19 @@ def generate_product_image(tasks_id: str): @router.post("/generate_relight_image") def generate_relight_image(request_item: GenerateProductImageModel, background_tasks: BackgroundTasks): + """ + 创建一个具有以下参数的请求体: + - **tasks_id**: 任务id 用于取消生成任务和获取生成结果 + - **prompt**: 想要生成图片的描述词 + - **image_url**: 被生成图片的S3或minio url地址 + + 示例参数: + { + "tasks_id": "123-89", + "prompt": "beautiful woman, detailed face, sunshine, outdoor, warm atmosphere", + "image_url": "aida-sys-image/images/female/blouse/0628000098.jpg" + } + """ try: logger.info(f"generate_relight_image request item is : @@@@@@:{request_item}") service = GenerateRelightImage(request_item) diff --git a/app/api/api_prompt_generation.py b/app/api/api_prompt_generation.py index 292ad2e..c7bcbcd 100644 --- a/app/api/api_prompt_generation.py +++ b/app/api/api_prompt_generation.py @@ -14,6 +14,16 @@ logger = logging.getLogger() @router.post("/translateToEN") def prompt_generation(request_data: PromptGenerationImageModel): + """ + 翻译prompt接口 + 创建一个具有以下参数的请求体: + - **text**: 待翻译语句 + + 示例参数: + { + "text": "你好" + } + """ try: logger.info(f"prompt_generation request item is : @@@@@@:{request_data}") data = translate_to_en(request_data.text) diff --git a/app/api/api_super_resolution.py b/app/api/api_super_resolution.py index 7928309..82b58f4 100644 --- a/app/api/api_super_resolution.py +++ b/app/api/api_super_resolution.py @@ -13,6 +13,19 @@ logger = logging.getLogger() @router.post("/super_resolution") def super_resolution(request_item: SuperResolutionModel, background_tasks: BackgroundTasks): + """ + 创建一个具有以下参数的请求体: + - **sr_image_url**: 超分图片的minio或s3 url地址 + - **sr_xn**: 超分的倍数,只接受2或4 + - **sr_tasks_id**: 任务id 用于取消超分任务和获取超分结果 + + 示例参数: + { + "sr_image_url": "aida-sys-image/images/female/blouse/0628000098.jpg", + "sr_xn": 2, + "sr_tasks_id": "12341556-89" + } + """ try: logger.info(f"super_resolution request item is : @@@@@@:{request_item}") service = SuperResolution(request_item) diff --git a/app/service/design/design_request.json b/app/service/design/design_request.json deleted file mode 100644 index 5551b82..0000000 --- a/app/service/design/design_request.json +++ /dev/null @@ -1,101 +0,0 @@ -{ - "objects": [ - { - "basic": { - "body_point": { - "waistband_right": [ - 1081, - 1318 - ], - "hand_point_right": [ - 1200, - 1857 - ], - "waistband_left": [ - 639, - 1315 - ], - "hand_point_left": [ - 493, - 1808 - ], - "shoulder_left": [ - 556, - 582 - ], - "shoulder_right": [ - 1130, - 576 - ] - }, - "layer_order": false, - "scale_bag": 0.7, - "scale_earrings": 0.16, - "self_template": true, - "single_overall": "overall", - "switch_category": "" - }, - "items": [ - { - "color": "151 78 78", - "icon": "none", - "image_id": 67315, - "offset": [ - 1, - 1 - ], - "path": "aida-sys-image/images/female/trousers/0628000325.jpg", - "print": { - "IfSingle": false, - "print_path_list": [] - }, - "resize_scale": 1.0, - "type": "Trousers" - }, - { - "color": "151 78 78", - "icon": "none", - "image_id": 92912, - "offset": [ - 1, - 1 - ], - "path": "aida-sys-image/images/female/blouse/0825001943.jpg", - "print": { - "IfSingle": false, - "print_path_list": [] - }, - "resize_scale": 1.0, - "type": "Blouse" - }, - { - "color": "151 78 78", - "icon": "none", - "image_id": 91430, - "offset": [ - 1, - 1 - ], - "path": "aida-sys-image/images/female/outwear/0825000856.jpg", - "print": { - "IfSingle": false, - "print_path_list": [] - }, - "resize_scale": 1.0, - "type": "Outwear" - }, - { - "body_path": "aida-users/89/models/female/5d39394e-9809-43c2-80b8-4e96497b1974.png", - "image_id": 69331, - "offset": [ - 1, - 1 - ], - "resize_scale": 1.0, - "type": "Body" - } - ] - } - ], - "process_id": "7296013643475027" -} \ No newline at end of file diff --git a/app/service/design/design_request_2.json b/app/service/design/design_request_2.json deleted file mode 100644 index 51b607a..0000000 --- a/app/service/design/design_request_2.json +++ /dev/null @@ -1,684 +0,0 @@ -{ - "objects": [ - { - "basic": { - "body_point_test": { - "waistband_right": [ - 1081, - 1318 - ], - "hand_point_right": [ - 1200, - 1857 - ], - "waistband_left": [ - 639, - 1315 - ], - "hand_point_left": [ - 493, - 1808 - ], - "shoulder_left": [ - 556, - 582 - ], - "shoulder_right": [ - 1130, - 576 - ] - }, - "layer_order": false, - "scale_bag": 0.7, - "scale_earrings": 0.16, - "self_template": true, - "single_overall": "overall", - "switch_category": "" - }, - "items": [ - { - "color": "151 78 78", - "icon": "none", - "image_id": 67315, - "offset": [ - 1, - 1 - ], - "path": "aida-sys-image/images/female/trousers/0628000325.jpg", - "print": { - "IfSingle": false, - "print_path_list": [] - }, - "resize_scale": 1.0, - "type": "Trousers" - }, - { - "color": "151 78 78", - "icon": "none", - "image_id": 92912, - "offset": [ - 1, - 1 - ], - "path": "aida-sys-image/images/female/blouse/0825001943.jpg", - "print": { - "IfSingle": false, - "print_path_list": [] - }, - "resize_scale": 1.0, - "type": "Blouse" - }, - { - "color": "151 78 78", - "icon": "none", - "image_id": 91430, - "offset": [ - 1, - 1 - ], - "path": "aida-sys-image/images/female/outwear/0825000856.jpg", - "print": { - "IfSingle": false, - "print_path_list": [] - }, - "resize_scale": 1.0, - "type": "Outwear" - }, - { - "body_path": "aida-users/89/models/female/5d39394e-9809-43c2-80b8-4e96497b1974.png", - "image_id": 69331, - "offset": [ - 1, - 1 - ], - "resize_scale": 1.0, - "type": "Body" - } - ] - } - , - { - "basic": { - "body_point_test": { - "waistband_right": [ - 1081, - 1318 - ], - "hand_point_right": [ - 1200, - 1857 - ], - "waistband_left": [ - 639, - 1315 - ], - "hand_point_left": [ - 493, - 1808 - ], - "shoulder_left": [ - 556, - 582 - ], - "shoulder_right": [ - 1130, - 576 - ] - }, - "layer_order": false, - "scale_bag": 0.7, - "scale_earrings": 0.16, - "self_template": true, - "single_overall": "overall", - "switch_category": "" - }, - "items": [ - { - "color": "151 78 78", - "icon": "none", - "image_id": 92913, - "offset": [ - 1, - 1 - ], - "path": "aida-sys-image/images/female/dress/826000033.jpg", - "print": { - "IfSingle": false, - "print_path_list": [] - }, - "resize_scale": 1.0, - "type": "Dress" - }, - { - "body_path": "aida-users/89/models/female/5d39394e-9809-43c2-80b8-4e96497b1974.png", - "image_id": 69331, - "offset": [ - 1, - 1 - ], - "resize_scale": 1.0, - "type": "Body" - } - ] - } - , - { - "basic": { - "body_point_test": { - "waistband_right": [ - 1081, - 1318 - ], - "hand_point_right": [ - 1200, - 1857 - ], - "waistband_left": [ - 639, - 1315 - ], - "hand_point_left": [ - 493, - 1808 - ], - "shoulder_left": [ - 556, - 582 - ], - "shoulder_right": [ - 1130, - 576 - ] - }, - "layer_order": false, - "scale_bag": 0.7, - "scale_earrings": 0.16, - "self_template": true, - "single_overall": "overall", - "switch_category": "" - }, - "items": [ - { - "color": "151 78 78", - "icon": "none", - "image_id": 92914, - "offset": [ - 1, - 1 - ], - "path": "aida-sys-image/images/female/skirt/0902001788.jpg", - "print": { - "IfSingle": false, - "print_path_list": [] - }, - "resize_scale": 1.0, - "type": "Skirt" - }, - { - "color": "151 78 78", - "icon": "none", - "image_id": 92915, - "offset": [ - 1, - 1 - ], - "path": "aida-sys-image/images/female/blouse/0902003817.jpg", - "print": { - "IfSingle": false, - "print_path_list": [] - }, - "resize_scale": 1.0, - "type": "Blouse" - }, - { - "body_path": "aida-users/89/models/female/5d39394e-9809-43c2-80b8-4e96497b1974.png", - "image_id": 69331, - "offset": [ - 1, - 1 - ], - "resize_scale": 1.0, - "type": "Body" - } - ] - } - , - { - "basic": { - "body_point_test": { - "waistband_right": [ - 1081, - 1318 - ], - "hand_point_right": [ - 1200, - 1857 - ], - "waistband_left": [ - 639, - 1315 - ], - "hand_point_left": [ - 493, - 1808 - ], - "shoulder_left": [ - 556, - 582 - ], - "shoulder_right": [ - 1130, - 576 - ] - }, - "layer_order": false, - "scale_bag": 0.7, - "scale_earrings": 0.16, - "self_template": true, - "single_overall": "overall", - "switch_category": "" - }, - "items": [ - { - "color": "151 78 78", - "icon": "none", - "image_id": 92916, - "offset": [ - 1, - 1 - ], - "path": "aida-sys-image/images/female/skirt/skirt_p4_838.jpg", - "print": { - "IfSingle": false, - "print_path_list": [] - }, - "resize_scale": 1.0, - "type": "Skirt" - }, - { - "color": "151 78 78", - "icon": "none", - "image_id": 84210, - "offset": [ - 1, - 1 - ], - "path": "aida-sys-image/images/female/blouse/0916000703.jpg", - "print": { - "IfSingle": false, - "print_path_list": [] - }, - "resize_scale": 1.0, - "type": "Blouse" - }, - { - "body_path": "aida-users/89/models/female/5d39394e-9809-43c2-80b8-4e96497b1974.png", - "image_id": 69331, - "offset": [ - 1, - 1 - ], - "resize_scale": 1.0, - "type": "Body" - } - ] - } - , - { - "basic": { - "body_point_test": { - "waistband_right": [ - 1081, - 1318 - ], - "hand_point_right": [ - 1200, - 1857 - ], - "waistband_left": [ - 639, - 1315 - ], - "hand_point_left": [ - 493, - 1808 - ], - "shoulder_left": [ - 556, - 582 - ], - "shoulder_right": [ - 1130, - 576 - ] - }, - "layer_order": false, - "scale_bag": 0.7, - "scale_earrings": 0.16, - "self_template": true, - "single_overall": "overall", - "switch_category": "" - }, - "items": [ - { - "color": "151 78 78", - "icon": "none", - "image_id": 62041, - "offset": [ - 1, - 1 - ], - "path": "aida-sys-image/images/female/outwear/0902000232.jpg", - "print": { - "IfSingle": false, - "print_path_list": [] - }, - "resize_scale": 1.0, - "type": "Outwear" - }, - { - "color": "151 78 78", - "icon": "none", - "image_id": 67039, - "offset": [ - 1, - 1 - ], - "path": "aida-sys-image/images/female/blouse/0902002591.jpg", - "print": { - "IfSingle": false, - "print_path_list": [] - }, - "resize_scale": 1.0, - "type": "Blouse" - }, - { - "color": "151 78 78", - "icon": "none", - "image_id": 78016, - "offset": [ - 1, - 1 - ], - "path": "aida-sys-image/images/female/trousers/trousers_p4_302.jpg", - "print": { - "IfSingle": false, - "print_path_list": [] - }, - "resize_scale": 1.0, - "type": "Trousers" - }, - { - "body_path": "aida-users/89/models/female/5d39394e-9809-43c2-80b8-4e96497b1974.png", - "image_id": 69331, - "offset": [ - 1, - 1 - ], - "resize_scale": 1.0, - "type": "Body" - } - ] - } - , - { - "basic": { - "body_point_test": { - "waistband_right": [ - 1081, - 1318 - ], - "hand_point_right": [ - 1200, - 1857 - ], - "waistband_left": [ - 639, - 1315 - ], - "hand_point_left": [ - 493, - 1808 - ], - "shoulder_left": [ - 556, - 582 - ], - "shoulder_right": [ - 1130, - 576 - ] - }, - "layer_order": false, - "scale_bag": 0.7, - "scale_earrings": 0.16, - "self_template": true, - "single_overall": "overall", - "switch_category": "" - }, - "items": [ - { - "color": "151 78 78", - "icon": "none", - "image_id": 92917, - "offset": [ - 1, - 1 - ], - "path": "aida-sys-image/images/female/trousers/0902001403.jpg", - "print": { - "IfSingle": false, - "print_path_list": [] - }, - "resize_scale": 1.0, - "type": "Trousers" - }, - { - "color": "151 78 78", - "icon": "none", - "image_id": 92306, - "offset": [ - 1, - 1 - ], - "path": "aida-sys-image/images/female/blouse/0902001766.jpg", - "print": { - "IfSingle": false, - "print_path_list": [] - }, - "resize_scale": 1.0, - "type": "Blouse" - }, - { - "body_path": "aida-users/89/models/female/5d39394e-9809-43c2-80b8-4e96497b1974.png", - "image_id": 69331, - "offset": [ - 1, - 1 - ], - "resize_scale": 1.0, - "type": "Body" - } - ] - } - , - { - "basic": { - "body_point_test": { - "waistband_right": [ - 1081, - 1318 - ], - "hand_point_right": [ - 1200, - 1857 - ], - "waistband_left": [ - 639, - 1315 - ], - "hand_point_left": [ - 493, - 1808 - ], - "shoulder_left": [ - 556, - 582 - ], - "shoulder_right": [ - 1130, - 576 - ] - }, - "layer_order": false, - "scale_bag": 0.7, - "scale_earrings": 0.16, - "self_template": true, - "single_overall": "overall", - "switch_category": "" - }, - "items": [ - { - "color": "151 78 78", - "icon": "none", - "image_id": 86564, - "offset": [ - 1, - 1 - ], - "path": "aida-sys-image/images/female/blouse/0916000038.jpg", - "print": { - "IfSingle": false, - "print_path_list": [] - }, - "resize_scale": 1.0, - "type": "Blouse" - }, - { - "color": "151 78 78", - "icon": "none", - "image_id": 92918, - "offset": [ - 1, - 1 - ], - "path": "aida-sys-image/images/female/trousers/0628001561.jpeg", - "print": { - "IfSingle": false, - "print_path_list": [] - }, - "resize_scale": 1.0, - "type": "Trousers" - }, - { - "color": "151 78 78", - "icon": "none", - "image_id": 92919, - "offset": [ - 1, - 1 - ], - "path": "aida-sys-image/images/female/outwear/outwear_p3186.jpg", - "print": { - "IfSingle": false, - "print_path_list": [] - }, - "resize_scale": 1.0, - "type": "Outwear" - }, - { - "body_path": "aida-users/89/models/female/5d39394e-9809-43c2-80b8-4e96497b1974.png", - "image_id": 69331, - "offset": [ - 1, - 1 - ], - "resize_scale": 1.0, - "type": "Body" - } - ] - } - , - { - "basic": { - "body_point_test": { - "waistband_right": [ - 1081, - 1318 - ], - "hand_point_right": [ - 1200, - 1857 - ], - "waistband_left": [ - 639, - 1315 - ], - "hand_point_left": [ - 493, - 1808 - ], - "shoulder_left": [ - 556, - 582 - ], - "shoulder_right": [ - 1130, - 576 - ] - }, - "layer_order": false, - "scale_bag": 0.7, - "scale_earrings": 0.16, - "self_template": true, - "single_overall": "overall", - "switch_category": "" - }, - "items": [ - { - "color": "151 78 78", - "icon": "none", - "image_id": 67009, - "offset": [ - 1, - 1 - ], - "path": "aida-sys-image/images/female/blouse/0902002051.jpg", - "print": { - "IfSingle": false, - "print_path_list": [] - }, - "resize_scale": 1.0, - "type": "Blouse" - }, - { - "color": "151 78 78", - "icon": "none", - "image_id": 85028, - "offset": [ - 1, - 1 - ], - "path": "aida-sys-image/images/female/skirt/903000142.jpg", - "print": { - "IfSingle": false, - "print_path_list": [] - }, - "resize_scale": 1.0, - "type": "Skirt" - }, - { - "body_path": "aida-users/89/models/female/5d39394e-9809-43c2-80b8-4e96497b1974.png", - "image_id": 69331, - "offset": [ - 1, - 1 - ], - "resize_scale": 1.0, - "type": "Body" - } - ] - } - ], - "process_id": "7296013643475027" -} \ No newline at end of file diff --git a/app/service/design/fastapi_request.json b/app/service/design/fastapi_request.json index f578079..8c27a56 100644 --- a/app/service/design/fastapi_request.json +++ b/app/service/design/fastapi_request.json @@ -1,69 +1,771 @@ { - "basic": { - "body_point": { - "waistband_right": [ - 1081, - 1318 - ], - "hand_point_right": [ - 1200, - 1857 - ], - "waistband_left": [ - 639, - 1315 - ], - "hand_point_left": [ - 493, - 1808 - ], - "shoulder_left": [ - 556, - 582 - ], - "shoulder_right": [ - 1130, - 576 - ] - }, - "layer_order": false, - "scale_bag": 0.7, - "scale_earrings": 0.16, - "self_template": true, - "single_overall": "single", - "switch_category": "Trousers", - "body_path": "aida-users/89/models/female/5d39394e-9809-43c2-80b8-4e96497b1974.png" - }, - "item": [ - { - "color": "151 78 78", - "image_id": "67315", - "offset": [ - 1, - 1 - ], - "path": "aida-sys-image/images/female/trousers/0628000325.jpg", - "print": { - "if_single": false, - "print_path_list": [] - }, - "resize_scale": 1.0, - "type": "Trousers" - }, - { - "color": "151 78 78", - "path": "aida-users/89/models/female/5d39394e-9809-43c2-80b8-4e96497b1974.png", - "image_id": 69331, - "offset": [ - 1, - 1 - ], - "print": { - "if_single": false, - "print_path_list": [] - }, - "resize_scale": 1.0, - "type": "Body" - } - ] + "objects": [ + { + "basic": { + "body_point_test": { + "waistband_right": [ + 336, + 264 + ], + "hand_point_right": [ + 350, + 303 + ], + "waistband_left": [ + 245, + 274 + ], + "hand_point_left": [ + 219, + 315 + ], + "shoulder_left": [ + 227, + 155 + ], + "shoulder_right": [ + 338, + 149 + ] + }, + "layer_order": false, + "scale_bag": 0.7, + "scale_earrings": 0.16, + "self_template": true, + "single_overall": "overall", + "switch_category": "" + }, + "items": [ + { + "businessId": 493827, + "color": "127 61 21", + "elementId": 493827, + "icon": "none", + "image_id": 110201, + "offset": [ + 1, + 1 + ], + "path": "aida-users/31/sketch/62302527-2910-4740-808d-2cb8221daa34-3-31.png", + "print": { + "IfSingle": false, + "print_path_list": [] + }, + "resize_scale": [ + 1.0, + 1.0 + ], + "type": "Dress" + }, + { + "body_path": "aida-users/31/models/female/845046c7-4f62-4f54-a4a9-c26d49c6969335b5b3a9-d335-4871-a46c-3cc3caf07da259629dfd1f1f555a2e2a9def7e719366.png", + "image_id": 82966, + "offset": [ + 1, + 1 + ], + "resize_scale": [ + 1.0, + 1.0 + ], + "type": "Body" + } + ] + }, + { + "basic": { + "body_point_test": { + "waistband_right": [ + 336, + 264 + ], + "hand_point_right": [ + 350, + 303 + ], + "waistband_left": [ + 245, + 274 + ], + "hand_point_left": [ + 219, + 315 + ], + "shoulder_left": [ + 227, + 155 + ], + "shoulder_right": [ + 338, + 149 + ] + }, + "layer_order": false, + "scale_bag": 0.7, + "scale_earrings": 0.16, + "self_template": true, + "single_overall": "overall", + "switch_category": "" + }, + "items": [ + { + "color": "27 25 23", + "icon": "none", + "image_id": 110202, + "offset": [ + 1, + 1 + ], + "path": "aida-sys-image/images/female/skirt/0916000602.jpg", + "print": { + "IfSingle": false, + "print_path_list": [] + }, + "resize_scale": [ + 1.0, + 1.0 + ], + "type": "Skirt" + }, + { + "businessId": 493825, + "color": "229 214 200", + "elementId": 493825, + "icon": "none", + "image_id": 107101, + "offset": [ + 1, + 1 + ], + "path": "aida-users/31/sketchboard/female/Blouse/de8f5656-d7ae-4642-bc90-f7f9d85da09b.jpg", + "print": { + "IfSingle": false, + "print_path_list": [] + }, + "resize_scale": [ + 1.0, + 1.0 + ], + "type": "Blouse" + }, + { + "businessId": 493824, + "color": "76 124 124", + "elementId": 493824, + "icon": "none", + "image_id": 104522, + "offset": [ + 1, + 1 + ], + "path": "aida-users/31/sketch/3e82214a-0191-11ef-96d2-b48351119060_1.png", + "print": { + "IfSingle": false, + "print_path_list": [] + }, + "resize_scale": [ + 1.0, + 1.0 + ], + "type": "Outwear" + }, + { + "body_path": "aida-users/31/models/female/845046c7-4f62-4f54-a4a9-c26d49c6969335b5b3a9-d335-4871-a46c-3cc3caf07da259629dfd1f1f555a2e2a9def7e719366.png", + "image_id": 82966, + "offset": [ + 1, + 1 + ], + "resize_scale": [ + 1.0, + 1.0 + ], + "type": "Body" + } + ] + }, + { + "basic": { + "body_point_test": { + "waistband_right": [ + 336, + 264 + ], + "hand_point_right": [ + 350, + 303 + ], + "waistband_left": [ + 245, + 274 + ], + "hand_point_left": [ + 219, + 315 + ], + "shoulder_left": [ + 227, + 155 + ], + "shoulder_right": [ + 338, + 149 + ] + }, + "layer_order": false, + "scale_bag": 0.7, + "scale_earrings": 0.16, + "self_template": true, + "single_overall": "overall", + "switch_category": "" + }, + "items": [ + { + "color": "229 214 200", + "icon": "none", + "image_id": 110203, + "offset": [ + 1, + 1 + ], + "path": "aida-sys-image/images/female/blouse/0825001576.jpg", + "print": { + "IfSingle": false, + "print_path_list": [] + }, + "resize_scale": [ + 1.0, + 1.0 + ], + "type": "Blouse" + }, + { + "color": "76 124 124", + "icon": "none", + "image_id": 96071, + "offset": [ + 1, + 1 + ], + "path": "aida-sys-image/images/female/skirt/903000097.jpg", + "print": { + "IfSingle": false, + "print_path_list": [] + }, + "resize_scale": [ + 1.0, + 1.0 + ], + "type": "Skirt" + }, + { + "color": "209 125 29", + "icon": "none", + "image_id": 93798, + "offset": [ + 1, + 1 + ], + "path": "aida-sys-image/images/female/outwear/outwear_p4_561.jpg", + "print": { + "IfSingle": false, + "print_path_list": [] + }, + "resize_scale": [ + 1.0, + 1.0 + ], + "type": "Outwear" + }, + { + "body_path": "aida-users/31/models/female/845046c7-4f62-4f54-a4a9-c26d49c6969335b5b3a9-d335-4871-a46c-3cc3caf07da259629dfd1f1f555a2e2a9def7e719366.png", + "image_id": 82966, + "offset": [ + 1, + 1 + ], + "resize_scale": [ + 1.0, + 1.0 + ], + "type": "Body" + } + ] + }, + { + "basic": { + "body_point_test": { + "waistband_right": [ + 336, + 264 + ], + "hand_point_right": [ + 350, + 303 + ], + "waistband_left": [ + 245, + 274 + ], + "hand_point_left": [ + 219, + 315 + ], + "shoulder_left": [ + 227, + 155 + ], + "shoulder_right": [ + 338, + 149 + ] + }, + "layer_order": false, + "scale_bag": 0.7, + "scale_earrings": 0.16, + "self_template": true, + "single_overall": "overall", + "switch_category": "" + }, + "items": [ + { + "businessId": 493824, + "color": "209 125 29", + "elementId": 493824, + "icon": "none", + "image_id": 104522, + "offset": [ + 1, + 1 + ], + "path": "aida-users/31/sketch/3e82214a-0191-11ef-96d2-b48351119060_1.png", + "print": { + "IfSingle": false, + "print_path_list": [] + }, + "resize_scale": [ + 1.0, + 1.0 + ], + "type": "Outwear" + }, + { + "color": "118 123 115", + "icon": "none", + "image_id": 110204, + "offset": [ + 1, + 1 + ], + "path": "aida-sys-image/images/female/blouse/0902000457.jpg", + "print": { + "IfSingle": false, + "print_path_list": [] + }, + "resize_scale": [ + 1.0, + 1.0 + ], + "type": "Blouse" + }, + { + "color": "118 123 115", + "icon": "none", + "image_id": 79259, + "offset": [ + 1, + 1 + ], + "path": "aida-sys-image/images/female/trousers/826000094.jpg", + "print": { + "IfSingle": false, + "print_path_list": [] + }, + "resize_scale": [ + 1.0, + 1.0 + ], + "type": "Trousers" + }, + { + "body_path": "aida-users/31/models/female/845046c7-4f62-4f54-a4a9-c26d49c6969335b5b3a9-d335-4871-a46c-3cc3caf07da259629dfd1f1f555a2e2a9def7e719366.png", + "image_id": 82966, + "offset": [ + 1, + 1 + ], + "resize_scale": [ + 1.0, + 1.0 + ], + "type": "Body" + } + ] + }, + { + "basic": { + "body_point_test": { + "waistband_right": [ + 336, + 264 + ], + "hand_point_right": [ + 350, + 303 + ], + "waistband_left": [ + 245, + 274 + ], + "hand_point_left": [ + 219, + 315 + ], + "shoulder_left": [ + 227, + 155 + ], + "shoulder_right": [ + 338, + 149 + ] + }, + "layer_order": false, + "scale_bag": 0.7, + "scale_earrings": 0.16, + "self_template": true, + "single_overall": "overall", + "switch_category": "" + }, + "items": [ + { + "color": "127 61 21", + "icon": "none", + "image_id": 96038, + "offset": [ + 1, + 1 + ], + "path": "aida-sys-image/images/female/dress/0902003549.jpg", + "print": { + "IfSingle": false, + "print_path_list": [] + }, + "resize_scale": [ + 1.0, + 1.0 + ], + "type": "Dress" + }, + { + "body_path": "aida-users/31/models/female/845046c7-4f62-4f54-a4a9-c26d49c6969335b5b3a9-d335-4871-a46c-3cc3caf07da259629dfd1f1f555a2e2a9def7e719366.png", + "image_id": 82966, + "offset": [ + 1, + 1 + ], + "resize_scale": [ + 1.0, + 1.0 + ], + "type": "Body" + } + ] + }, + { + "basic": { + "body_point_test": { + "waistband_right": [ + 336, + 264 + ], + "hand_point_right": [ + 350, + 303 + ], + "waistband_left": [ + 245, + 274 + ], + "hand_point_left": [ + 219, + 315 + ], + "shoulder_left": [ + 227, + 155 + ], + "shoulder_right": [ + 338, + 149 + ] + }, + "layer_order": false, + "scale_bag": 0.7, + "scale_earrings": 0.16, + "self_template": true, + "single_overall": "overall", + "switch_category": "" + }, + "items": [ + { + "businessId": 493822, + "color": "127 61 21", + "elementId": 493822, + "icon": "none", + "image_id": 62309, + "offset": [ + 1, + 1 + ], + "path": "aida-users/31/sketchboard/female/trousers/c37c2ea6-8955-4b40-8339-c737e672ca3d.jpg", + "print": { + "IfSingle": false, + "print_path_list": [] + }, + "resize_scale": [ + 1.0, + 1.0 + ], + "type": "Trousers" + }, + { + "businessId": 493825, + "color": "118 123 115", + "elementId": 493825, + "icon": "none", + "image_id": 107101, + "offset": [ + 1, + 1 + ], + "path": "aida-users/31/sketchboard/female/Blouse/de8f5656-d7ae-4642-bc90-f7f9d85da09b.jpg", + "print": { + "IfSingle": false, + "print_path_list": [] + }, + "resize_scale": [ + 1.0, + 1.0 + ], + "type": "Blouse" + }, + { + "body_path": "aida-users/31/models/female/845046c7-4f62-4f54-a4a9-c26d49c6969335b5b3a9-d335-4871-a46c-3cc3caf07da259629dfd1f1f555a2e2a9def7e719366.png", + "image_id": 82966, + "offset": [ + 1, + 1 + ], + "resize_scale": [ + 1.0, + 1.0 + ], + "type": "Body" + } + ] + }, + { + "basic": { + "body_point_test": { + "waistband_right": [ + 336, + 264 + ], + "hand_point_right": [ + 350, + 303 + ], + "waistband_left": [ + 245, + 274 + ], + "hand_point_left": [ + 219, + 315 + ], + "shoulder_left": [ + 227, + 155 + ], + "shoulder_right": [ + 338, + 149 + ] + }, + "layer_order": false, + "scale_bag": 0.7, + "scale_earrings": 0.16, + "self_template": true, + "single_overall": "overall", + "switch_category": "" + }, + "items": [ + { + "businessId": 493826, + "color": "127 61 21", + "elementId": 493826, + "icon": "none", + "image_id": 107105, + "offset": [ + 1, + 1 + ], + "path": "aida-users/31/sketchboard/female/Skirt/58710352-6301-450d-b69a-fb2922b5429a.png", + "print": { + "IfSingle": false, + "print_path_list": [] + }, + "resize_scale": [ + 1.0, + 1.0 + ], + "type": "Skirt" + }, + { + "color": "118 123 115", + "icon": "none", + "image_id": 79114, + "offset": [ + 1, + 1 + ], + "path": "aida-sys-image/images/female/blouse/903000169.jpg", + "print": { + "IfSingle": false, + "print_path_list": [] + }, + "resize_scale": [ + 1.0, + 1.0 + ], + "type": "Blouse" + }, + { + "color": "229 214 200", + "icon": "none", + "image_id": 90573, + "offset": [ + 1, + 1 + ], + "path": "aida-sys-image/images/female/outwear/0628000541.jpg", + "print": { + "IfSingle": false, + "print_path_list": [] + }, + "resize_scale": [ + 1.0, + 1.0 + ], + "type": "Outwear" + }, + { + "body_path": "aida-users/31/models/female/845046c7-4f62-4f54-a4a9-c26d49c6969335b5b3a9-d335-4871-a46c-3cc3caf07da259629dfd1f1f555a2e2a9def7e719366.png", + "image_id": 82966, + "offset": [ + 1, + 1 + ], + "resize_scale": [ + 1.0, + 1.0 + ], + "type": "Body" + } + ] + }, + { + "basic": { + "body_point_test": { + "waistband_right": [ + 336, + 264 + ], + "hand_point_right": [ + 350, + 303 + ], + "waistband_left": [ + 245, + 274 + ], + "hand_point_left": [ + 219, + 315 + ], + "shoulder_left": [ + 227, + 155 + ], + "shoulder_right": [ + 338, + 149 + ] + }, + "layer_order": false, + "scale_bag": 0.7, + "scale_earrings": 0.16, + "self_template": true, + "single_overall": "overall", + "switch_category": "" + }, + "items": [ + { + "color": "229 214 200", + "icon": "none", + "image_id": 110205, + "offset": [ + 1, + 1 + ], + "path": "aida-sys-image/images/female/trousers/0916000217.jpg", + "print": { + "IfSingle": false, + "print_path_list": [] + }, + "resize_scale": [ + 1.0, + 1.0 + ], + "type": "Trousers" + }, + { + "businessId": 493825, + "color": "209 125 29", + "elementId": 493825, + "icon": "none", + "image_id": 107101, + "offset": [ + 1, + 1 + ], + "path": "aida-users/31/sketchboard/female/Blouse/de8f5656-d7ae-4642-bc90-f7f9d85da09b.jpg", + "print": { + "IfSingle": false, + "print_path_list": [] + }, + "resize_scale": [ + 1.0, + 1.0 + ], + "type": "Blouse" + }, + { + "body_path": "aida-users/31/models/female/845046c7-4f62-4f54-a4a9-c26d49c6969335b5b3a9-d335-4871-a46c-3cc3caf07da259629dfd1f1f555a2e2a9def7e719366.png", + "image_id": 82966, + "offset": [ + 1, + 1 + ], + "resize_scale": [ + 1.0, + 1.0 + ], + "type": "Body" + } + ] + } + ], + "process_id": "6878547032381675" } \ No newline at end of file diff --git a/app/service/design/items/pipelines/split.py b/app/service/design/items/pipelines/split.py index e46a3e1..897e49a 100644 --- a/app/service/design/items/pipelines/split.py +++ b/app/service/design/items/pipelines/split.py @@ -48,7 +48,6 @@ class Split(object): result_front_image_pil = Image.fromarray(cvtColor(result_front_image, COLOR_BGR2RGBA)) front_new_size = (int(result_front_image_pil.width * result["scale"] * result["resize_scale"][0]), int(result_front_image_pil.height * result["scale"] * result["resize_scale"][1])) result_front_image_pil = result_front_image_pil.resize(front_new_size, Image.LANCZOS) - # TODO 多线程外部上传图片到minio # result['front_mask_image'] = cv2.resize(front_mask, front_new_size) # result['front_image'] = result_front_image_pil front_mask = cv2.resize(front_mask, front_new_size) @@ -61,7 +60,6 @@ class Split(object): result_back_image_pil = Image.fromarray(cvtColor(result_back_image, COLOR_BGR2RGBA)) back_new_size = (int(result_back_image_pil.width * result["scale"] * result["resize_scale"][0]), int(result_back_image_pil.height * result["scale"] * result["resize_scale"][1])) result_back_image_pil = result_back_image_pil.resize(back_new_size, Image.LANCZOS) - # TODO 多线程外部上传图片到minio # result['back_mask_image'] = cv2.resize(back_mask, back_new_size) # result['back_image'] = result_back_image_pil diff --git a/app/service/design/utils/synthesis_item.py b/app/service/design/utils/synthesis_item.py index caf3fcb..e447018 100644 --- a/app/service/design/utils/synthesis_item.py +++ b/app/service/design/utils/synthesis_item.py @@ -9,7 +9,6 @@ """ import io import logging -import time # import boto3 import cv2 @@ -18,8 +17,8 @@ from PIL import Image from minio import Minio from app.core.config import * -from app.service.utils.decorator import RunTime from app.service.utils.generate_uuid import generate_uuid +from app.service.utils.oss_client import oss_upload_image minio_client = Minio( MINIO_URL, @@ -27,6 +26,7 @@ minio_client = Minio( secret_key=MINIO_SECRET, secure=MINIO_SECURE) + # s3 = boto3.client( # 's3', # aws_access_key_id=S3_ACCESS_KEY, @@ -134,8 +134,14 @@ def synthesis(data, size): image_data = io.BytesIO() result_image.save(image_data, format='PNG') image_data.seek(0) + + # oss upload image_bytes = image_data.read() - return f"aida-results/{minio_client.put_object('aida-results', f'result_{generate_uuid()}.png', io.BytesIO(image_bytes), len(image_bytes), content_type='image/png').object_name}" + bucket_name = 'aida-results' + object_name = f'result_{generate_uuid()}.png' + req = oss_upload_image(bucket=bucket_name, object_name=object_name, image_bytes=image_bytes) + return f"{bucket_name}/{object_name}" + # return f"aida-results/{minio_client.put_object('aida-results', f'result_{generate_uuid()}.png', io.BytesIO(image_bytes), len(image_bytes), content_type='image/png').object_name}" # object_name = f'result_{generate_uuid()}.png' # response = s3.put_object(Bucket="aida-results", Key=object_name, Body=data, ContentType='image/png') diff --git a/app/service/design/utils/upload_image.py b/app/service/design/utils/upload_image.py index a4195f7..3571816 100644 --- a/app/service/design/utils/upload_image.py +++ b/app/service/design/utils/upload_image.py @@ -9,99 +9,15 @@ """ import io import logging -import time -# import boto3 import cv2 -from minio import Minio from app.core.config import * -from app.service.utils.decorator import RunTime - -minio_client = Minio( - f"{MINIO_URL}", - access_key=MINIO_ACCESS, - secret_key=MINIO_SECRET, - secure=MINIO_SECURE) - -"""S3 上传""" -# s3 = boto3.client('s3', aws_access_key_id=S3_ACCESS_KEY, aws_secret_access_key=S3_AWS_SECRET_ACCESS_KEY, region_name=S3_REGION_NAME) - - -# -# @RunTime -# def upload_png_mask(front_image, object_name, mask=None): -# mask_url = None -# if mask is not None: -# # 反转掩模 -# mask_inverted = cv2.bitwise_not(mask) -# # 将掩模转换为 RGBA 格式 -# rgba_image = cv2.cvtColor(mask_inverted, cv2.COLOR_BGR2BGRA) -# rgba_image[rgba_image[:, :, 0] == 0] = [0, 0, 0, 0] -# # 将图像数据保存到内存中的 BytesIO 对象中 -# image_bytes = io.BytesIO() -# image_bytes.write(cv2.imencode('.png', rgba_image)[1].tobytes()) -# image_bytes.seek(0) -# try: -# key = f"mask/mask_{object_name}.png" -# mask_url = f"{AIDA_CLOTHING}/{key}" -# s3.put_object(Bucket=AIDA_CLOTHING, Key=key, Body=image_bytes, ContentType='image/png') -# except Exception as e: -# print(f'上传到 S3 失败: {e}') -# with io.BytesIO() as output: -# front_image.save(output, format='PNG') -# data = output.getvalue() -# # 创建一个 S3 客户端 -# try: -# key = f"image/image_{object_name}.png" -# image_url = f"{AIDA_CLOTHING}/{key}" -# s3.put_object(Bucket=AIDA_CLOTHING, Key=key, Body=data, ContentType='image/png') -# return front_image, image_url, mask_url -# except Exception as e: -# print(f'上传到 S3 失败: {e}') -# -# -# @RunTime -# def upload_layer_image(image, object_name): -# with io.BytesIO() as output: -# image.save(output, format='PNG') -# data = output.getvalue() -# # 创建一个 S3 客户端 -# try: -# key = f"image/image_{object_name}.png" -# image_url = f"{AIDA_CLOTHING}/{key}" -# s3.put_object(Bucket=AIDA_CLOTHING, Key=key, Body=data, ContentType='image/png') -# return image_url -# except Exception as e: -# print(f'上传到 S3 失败: {e}') -# -# -# @RunTime -# def upload_mask_image(mask, object_name): -# # 反转掩模 -# mask_inverted = cv2.bitwise_not(mask) -# # 将掩模转换为 RGBA 格式 -# rgba_image = cv2.cvtColor(mask_inverted, cv2.COLOR_BGR2BGRA) -# rgba_image[rgba_image[:, :, 0] == 0] = [0, 0, 0, 0] -# # 将图像数据保存到内存中的 BytesIO 对象中 -# image_bytes = io.BytesIO() -# image_bytes.write(cv2.imencode('.png', rgba_image)[1].tobytes()) -# image_bytes.seek(0) -# try: -# key = f"mask/mask_{object_name}.png" -# mask_url = f"{AIDA_CLOTHING}/{key}" -# s3.put_object(Bucket=AIDA_CLOTHING, Key=key, Body=image_bytes, ContentType='image/png') -# return mask_url -# except Exception as e: -# print(f'上传到 S3 失败: {e}') - - -"""minio 上传""" +from app.service.utils.oss_client import oss_upload_image # @RunTime def upload_png_mask(front_image, object_name, mask=None): - start_time = time.time() try: mask_url = None if mask is not None: @@ -109,48 +25,21 @@ def upload_png_mask(front_image, object_name, mask=None): # 将掩模的3通道转换为4通道,白色部分不透明,黑色部分透明 rgba_image = cv2.cvtColor(mask_inverted, cv2.COLOR_BGR2BGRA) rgba_image[rgba_image[:, :, 0] == 0] = [0, 0, 0, 0] - image_bytes = io.BytesIO() - image_bytes.write(cv2.imencode('.png', rgba_image)[1].tobytes()) - - image_bytes.seek(0) - mask_url = f"{AIDA_CLOTHING}/{minio_client.put_object('aida-clothing', f'mask/mask_{object_name}.png', image_bytes, len(image_bytes.getvalue()), content_type='image/png').object_name}" + # image_bytes = io.BytesIO() + # image_bytes.write(cv2.imencode('.png', rgba_image)[1].tobytes()) + # image_bytes.seek(0) + # mask_url = f"{AIDA_CLOTHING}/{minio_client.put_object('aida-clothing', f'mask/mask_{object_name}.png', image_bytes, len(image_bytes.getvalue()), content_type='image/png').object_name}" + # oss upload #################### + req = oss_upload_image(bucket=AIDA_CLOTHING, object_name=f"mask/mask_{object_name}.png", image_bytes=cv2.imencode('.png', rgba_image)[1]) + mask_url = f"{AIDA_CLOTHING}/mask/mask_{object_name}.png" image_data = io.BytesIO() front_image.save(image_data, format='PNG') image_data.seek(0) image_bytes = image_data.read() - image_url = f"{AIDA_CLOTHING}/{minio_client.put_object('aida-clothing', f'image/image_{object_name}.png', io.BytesIO(image_bytes), len(image_bytes), content_type='image/png').object_name}" - # print(f"upload_png_mask {object_name} = {time.time() - start_time}") + # image_url = f"{AIDA_CLOTHING}/{minio_client.put_object('aida-clothing', f'image/image_{object_name}.png', io.BytesIO(image_bytes), len(image_bytes), content_type='image/png').object_name}" + req = oss_upload_image(bucket=AIDA_CLOTHING, object_name=f"image/image_{object_name}.png", image_bytes=image_bytes) + image_url = f"{AIDA_CLOTHING}/image/image_{object_name}.png" return front_image, image_url, mask_url except Exception as e: logging.warning(f"upload_png_mask runtime exception : {e}") - - -@RunTime -def upload_layer_image(image, object_name): - try: - image_data = io.BytesIO() - image.save(image_data, format='PNG') - image_data.seek(0) - image_bytes = image_data.read() - image_url = f"{AIDA_CLOTHING}/{minio_client.put_object('aida-clothing', f'image/image_{object_name}.png', io.BytesIO(image_bytes), len(image_bytes), content_type='image/png').object_name}" - return image_url - except Exception as e: - logging.warning(f"upload_png_mask runtime exception : {e}") - - -@RunTime -def upload_mask_image(mask, object_name): - try: - mask_inverted = cv2.bitwise_not(mask) - # 将掩模的3通道转换为4通道,白色部分不透明,黑色部分透明 - rgba_image = cv2.cvtColor(mask_inverted, cv2.COLOR_BGR2BGRA) - rgba_image[rgba_image[:, :, 0] == 0] = [0, 0, 0, 0] - image_bytes = io.BytesIO() - image_bytes.write(cv2.imencode('.png', rgba_image)[1].tobytes()) - - image_bytes.seek(0) - mask_url = f"{AIDA_CLOTHING}/{minio_client.put_object('aida-clothing', f'mask/mask_{object_name}.png', image_bytes, len(image_bytes.getvalue()), content_type='image/png').object_name}" - return mask_url - except Exception as e: - logging.warning(f"upload_png_mask runtime exception : {e}") diff --git a/app/service/design_pre_processing/service.py b/app/service/design_pre_processing/service.py index f6f239a..f69c3ee 100644 --- a/app/service/design_pre_processing/service.py +++ b/app/service/design_pre_processing/service.py @@ -8,6 +8,7 @@ import tritonclient.grpc as grpcclient from urllib3.exceptions import ResponseError from app.core.config import * +from app.schemas.pre_processing import DesignPreProcessingModel from app.service.design.utils.design_ensemble import get_keypoint_result from app.service.utils.oss_client import oss_get_image, oss_upload_image @@ -355,3 +356,19 @@ class DesignPreprocessing: except Exception as e: logging.info(f"save keypoint cache milvus error : {e}") return dict(zip(KEYPOINT_RESULT_TABLE_FIELD_SET, result.reshape(12, 2).astype(int).tolist())) + + +if __name__ == '__main__': + data = { + "sketches": [ + { + "image_category": "dress", + "image_id": "107903", + "image_url": "aida-sys-image/images/female/dress/0628000000.jpg" + } + ] + } + request_data = DesignPreProcessingModel(sketches=data["sketches"]) + server = DesignPreprocessing() + data = server.pipeline(image_list=request_data.sketches) + print(data) diff --git a/app/service/generate_image/service_generate_image.py b/app/service/generate_image/service_generate_image.py index f3dff16..1bc1c91 100644 --- a/app/service/generate_image/service_generate_image.py +++ b/app/service/generate_image/service_generate_image.py @@ -10,15 +10,17 @@ import json import logging import time + import cv2 import minio +import numpy as np import redis import tritonclient.grpc as grpcclient -import numpy as np from tritonclient.utils import np_to_triton_dtype + from app.core.config import * from app.schemas.generate_image import GenerateImageModel -from app.service.generate_image.utils.image_processing import remove_background, stain_detection, generate_category_recognition, autoLevels, luminance_adjust, face_detect_pic +from app.service.generate_image.utils.image_processing import remove_background, stain_detection, generate_category_recognition, autoLevels, luminance_adjust from app.service.generate_image.utils.upload_sd_image import upload_png_sd from app.service.utils.oss_client import oss_get_image @@ -120,13 +122,6 @@ class GenerateImage: status_data = self.redis_client.get(self.tasks_id) return json.loads(status_data), status_data - def infer(self, inputs): - return self.grpc_client.async_infer( - model_name=GI_MODEL_NAME, - inputs=inputs, - callback=self.callback - ) - def get_result(self): try: prompts = [self.prompt] * self.batch_size @@ -146,7 +141,7 @@ class GenerateImage: input_mode.set_data_from_numpy(mode_obj) inputs = [input_text, input_image, input_mode] - ctx = self.infer(inputs) + ctx = self.grpc_client.async_infer(model_name=GI_MODEL_NAME, inputs=inputs, callback=self.callback) time_out = 600 generate_data = None while time_out > 0: @@ -186,10 +181,10 @@ if __name__ == '__main__': rd = GenerateImageModel( tasks_id="123-89", prompt='skeleton sitting by the side of a river looking soulful, concert poster, 4k, artistic', - image_url="", + image_url="aida-collection-element/87/Printboard/842c09cf-7297-42d9-9e6e-9c17d4a13cb5.jpg", mode='txt2img', category="test", gender="male" ) server = GenerateImage(rd) - print(server.get_result()) \ No newline at end of file + print(server.get_result()) diff --git a/app/service/super_resolution/service.py b/app/service/super_resolution/service.py index 1dfe9dd..c2cf39d 100644 --- a/app/service/super_resolution/service.py +++ b/app/service/super_resolution/service.py @@ -64,7 +64,6 @@ class SuperResolution: if self.sr_xn == 2: new_shape = (sample.shape[0] // self.sr_xn, sample.shape[1] // self.sr_xn) sample = cv2.resize(sample, new_shape) - print(new_shape) sample = np.transpose(sample if sample.shape[2] == 1 else sample[:, :, [2, 1, 0]], (2, 0, 1)) sample = torch.from_numpy(sample).float().unsqueeze(0).numpy() inputs = [ diff --git a/app/service/utils/oss_client.py b/app/service/utils/oss_client.py index 7ebeb3f..11e7911 100644 --- a/app/service/utils/oss_client.py +++ b/app/service/utils/oss_client.py @@ -44,7 +44,7 @@ def oss_upload_image(bucket, object_name, image_bytes): req = oss_client.put_object(bucket_name=bucket, object_name=object_name, data=io.BytesIO(image_bytes), length=len(image_bytes), content_type='image/png') else: oss_client = boto3.client('s3', aws_access_key_id=S3_ACCESS_KEY, aws_secret_access_key=S3_AWS_SECRET_ACCESS_KEY, region_name=S3_REGION_NAME) - req = oss_client.put_object(Bucket=AIDA_CLOTHING, Key=object_name, Body=image_bytes, ContentType='image/png') + req = oss_client.put_object(Bucket=bucket, Key=object_name, Body=io.BytesIO(image_bytes), ContentType='image/png') except Exception as e: logger.warning(f"{OSS} | 上传图片出现异常 ######: {e}") return req @@ -55,12 +55,16 @@ if __name__ == '__main__': # url = "aida-collection-element/11523/Moodboard/f60af0d2-94c2-48f9-90ff-74b8e8a481b5.jpg" # url = "aida-sys-image/images/female/outwear/0628000054.jpg" # url = "aida-users/89/product_image/string-89.png" - url = "test/845046c7-4f62-4f54-a4a9-c26d49c6969335b5b3a9-d335-4871-a46c-3cc3caf07da259629dfd1f1f555a2e2a9def7e719366.png" + # url = "test/845046c7-4f62-4f54-a4a9-c26d49c6969335b5b3a9-d335-4871-a46c-3cc3caf07da259629dfd1f1f555a2e2a9def7e719366.png" # url = 'aida-users/89/relight_image/123-89.png' # url = 'aida-users/89/relight_image/123-89.png' # url = 'aida-users/89/relight_image/123-89.png' # url = "aida-users/89/sketchboard/female/Dress/e6724ab7-8d3f-4677-abe0-c3e42ab7af85.jpeg" - read_type = "PIL " + # url = "aida-users/87/print/956614a2-7e75-4fbe-9ed0-c1831e37a2c9-4-87.png" + # url = "aida-users/89/single_logo/123-89.png" + # url = "aida-users/89/product_image/string-89.png" + url = "aida-users/10/models/female/9c788f5b-b8c7-424c-b149-025aeb0bda51model.png" + read_type = "PIL" if read_type == "cv2": img = oss_get_image(bucket=url.split('/')[0], object_name=url[url.find('/') + 1:], data_type=read_type) cv2.imshow("", img)