|
|
@@ -9,6 +9,7 @@ from PIL import Image
|
|
|
import io, time
|
|
|
from logger import logger
|
|
|
|
|
|
+
|
|
|
# logger = logging.getLogger(__name__)
|
|
|
|
|
|
class JsonEncoder(json.JSONEncoder):
|
|
|
@@ -38,7 +39,7 @@ def download_image_with_pil(url, save_path):
|
|
|
return save_path
|
|
|
|
|
|
except Exception as e:
|
|
|
- print("保存错误",e)
|
|
|
+ print("保存错误", e)
|
|
|
return "error"
|
|
|
|
|
|
|
|
|
@@ -60,7 +61,7 @@ class AIGCDataRequest(object):
|
|
|
return resultData["data"]["url"]
|
|
|
|
|
|
def center_paste_image(
|
|
|
- self, source_image_path, output_path, width=900, ratio=(3, 4)
|
|
|
+ self, source_image_path, output_path, width=900, ratio=(3, 4)
|
|
|
):
|
|
|
"""
|
|
|
将一张PNG透明图片居中粘贴到指定尺寸和比例的背景上,保持透明度
|
|
|
@@ -115,13 +116,14 @@ class AIGCDataRequest(object):
|
|
|
source_img.close()
|
|
|
return background
|
|
|
|
|
|
- def generateProductScene(self, local_path, prompt, save_path):
|
|
|
+ def generateProductScene(self, local_path, prompt, save_path, product_scene_image):
|
|
|
imageUrl = self.uploadImage(local_path)
|
|
|
print("imageUrl", imageUrl)
|
|
|
data = {
|
|
|
"site": 1,
|
|
|
"base_image": imageUrl,
|
|
|
"keyword": prompt,
|
|
|
+ "reference_image": product_scene_image,
|
|
|
"model_type": 1,
|
|
|
"gemini_model": "gemini-2.5-flash-image-preview",
|
|
|
}
|
|
|
@@ -141,7 +143,7 @@ class AIGCDataRequest(object):
|
|
|
save_image_path = download_image_with_pil(image_url, save_path)
|
|
|
return save_image_path
|
|
|
except:
|
|
|
- raise UnicornException("场景图生成失败")
|
|
|
+ raise UnicornException("场景图生成失败")
|
|
|
|
|
|
def generateProductSceneQW(self, local_path, prompt, save_path):
|
|
|
'''千问生成场景图'''
|
|
|
@@ -208,13 +210,13 @@ class AIGCDataRequest(object):
|
|
|
data_item = data_result[0]
|
|
|
status = data_item.get("status", -1)
|
|
|
result_image = None
|
|
|
-
|
|
|
+
|
|
|
# 只有在完成状态下才返回图片URL
|
|
|
if status == 2: # 完成
|
|
|
result_image_urls = data_item.get("result_image_urls", [])
|
|
|
result_image_urls = [] if result_image_urls is None else result_image_urls
|
|
|
result_image = result_image_urls[0] if len(result_image_urls) > 0 else None
|
|
|
-
|
|
|
+
|
|
|
return status, result_image
|
|
|
except requests.Timeout:
|
|
|
print("查询进度超时")
|
|
|
@@ -267,7 +269,7 @@ class AIGCDataRequest(object):
|
|
|
if status == -1 or (status != 2 and search_times <= 0):
|
|
|
raise UnicornException("模特图生成失败")
|
|
|
save_image_path = download_image_with_pil(result_image, save_path)
|
|
|
- print("上脚图save_image_path",result_image, save_image_path)
|
|
|
+ print("上脚图save_image_path", result_image, save_image_path)
|
|
|
return save_image_path
|
|
|
|
|
|
|
|
|
@@ -587,7 +589,7 @@ class OnlineDataRequest(object):
|
|
|
print("上传商品api==>resultData", resultData)
|
|
|
return resultData
|
|
|
|
|
|
- def sendSocketMessage(self, code=0, msg="", data=None, device_status=2,msg_type="upload_goods_progress"):
|
|
|
+ def sendSocketMessage(self, code=0, msg="", data=None, device_status=2, msg_type="upload_goods_progress"):
|
|
|
data = {
|
|
|
"code": code,
|
|
|
"msg": msg,
|
|
|
@@ -636,12 +638,12 @@ class OnlineDataRequest(object):
|
|
|
mainImagePath = mainImages[0]
|
|
|
imageUrl = self.uploadImage(local_path=mainImagePath)
|
|
|
skuNameJson = []
|
|
|
- skuNameJson.append({"propName":"颜色","propValue":color_name})
|
|
|
- skuNameJson.append({"propName":"尺寸","propValue":size})
|
|
|
+ skuNameJson.append({"propName": "颜色", "propValue": color_name})
|
|
|
+ skuNameJson.append({"propName": "尺寸", "propValue": size})
|
|
|
skuItemData = {
|
|
|
"颜色": color_name,
|
|
|
"尺寸": size,
|
|
|
- "skuPropName":color_name,
|
|
|
+ "skuPropName": color_name,
|
|
|
"skuNo": sku_goods_art_no,
|
|
|
"originalPrice": float(goods_price),
|
|
|
"newSkuWeight": int(1),
|
|
|
@@ -650,7 +652,7 @@ class OnlineDataRequest(object):
|
|
|
"sellingPrice": float(goods_price),
|
|
|
"quantity": int(quantity),
|
|
|
"showOrder": int(skuIdx + 1),
|
|
|
- "skuNameJson":skuNameJson
|
|
|
+ "skuNameJson": skuNameJson
|
|
|
}
|
|
|
skuList.append(skuItemData)
|
|
|
itemImage = {
|
|
|
@@ -681,16 +683,16 @@ class OnlineDataRequest(object):
|
|
|
}
|
|
|
)
|
|
|
itemSkuImageList.append({
|
|
|
- "propName": "尺寸",
|
|
|
- "isImageProp": 0,
|
|
|
- "propShowOrder": 1,
|
|
|
- "showOrder": 0,
|
|
|
+ "propName": "尺寸",
|
|
|
+ "isImageProp": 0,
|
|
|
+ "propShowOrder": 1,
|
|
|
+ "showOrder": 0,
|
|
|
+ "propValue": str(size),
|
|
|
+ "skuPropValueList": [{
|
|
|
"propValue": str(size),
|
|
|
- "skuPropValueList":[{
|
|
|
- "propValue": str(size),
|
|
|
- "showOrder": 1,
|
|
|
- }]
|
|
|
- })
|
|
|
+ "showOrder": 1,
|
|
|
+ }]
|
|
|
+ })
|
|
|
detailImageUrl = self.uploadImage(local_path=detail_path)
|
|
|
category_info = "流行男鞋>>休闲鞋>>时尚休闲鞋"
|
|
|
itemData = {
|