Merge branch 'refs/heads/develop'
This commit is contained in:
@@ -129,8 +129,14 @@ GSL_MODEL_NAME = 'stable_diffusion_xl_transparent'
|
||||
GEN_SINGLE_LOGO_RABBITMQ_QUEUES = os.getenv("GEN_SINGLE_LOGO_RABBITMQ_QUEUES", f"GenSingleLogo{RABBITMQ_ENV}")
|
||||
|
||||
# Generate Product service config
|
||||
# GPI_RABBITMQ_QUEUES = os.getenv("GEN_PRODUCT_IMAGE_RABBITMQ_QUEUES", f"ToProductImage{RABBITMQ_ENV}")
|
||||
# GPI_MODEL_NAME_OVERALL = 'sdxl_ensemble_all'
|
||||
# GPI_MODEL_URL = '10.1.1.243:10051'
|
||||
|
||||
# Generate Product service config 旧版product img 模型
|
||||
GPI_RABBITMQ_QUEUES = os.getenv("GEN_PRODUCT_IMAGE_RABBITMQ_QUEUES", f"ToProductImage{RABBITMQ_ENV}")
|
||||
GPI_MODEL_NAME_OVERALL = 'sdxl_ensemble_all'
|
||||
GPI_MODEL_NAME_OVERALL = 'diffusion_ensemble_all'
|
||||
GPI_MODEL_NAME_SINGLE = 'stable_diffusion_1_5_cnet'
|
||||
GPI_MODEL_URL = '10.1.1.243:10051'
|
||||
|
||||
# Generate Single Logo service config
|
||||
|
||||
@@ -226,7 +226,7 @@ class GenerateProductImage:
|
||||
# self.connection = pika.BlockingConnection(pika.ConnectionParameters(**RABBITMQ_PARAMS))
|
||||
# self.channel = self.connection.channel()
|
||||
# self.minio_client = Minio(MINIO_URL, access_key=MINIO_ACCESS, secret_key=MINIO_SECRET, secure=MINIO_SECURE)
|
||||
self.grpc_client = grpcclient.InferenceServerClient(url="10.1.1.243:18001")
|
||||
self.grpc_client = grpcclient.InferenceServerClient(url=GPI_MODEL_URL)
|
||||
self.redis_client = redis.StrictRedis(host=REDIS_HOST, port=REDIS_PORT, db=REDIS_DB, decode_responses=True)
|
||||
self.category = "product_image"
|
||||
self.image_strength = request_data.image_strength
|
||||
@@ -293,9 +293,9 @@ class GenerateProductImage:
|
||||
inputs = [input_text, input_image, input_image_strength]
|
||||
|
||||
if self.product_type == "single":
|
||||
ctx = self.grpc_client.async_infer(model_name="stable_diffusion_1_5_cnet", inputs=inputs, callback=self.callback)
|
||||
ctx = self.grpc_client.async_infer(model_name=GPI_MODEL_NAME_SINGLE, inputs=inputs, callback=self.callback)
|
||||
else:
|
||||
ctx = self.grpc_client.async_infer(model_name="diffusion_ensemble_all", inputs=inputs, callback=self.callback)
|
||||
ctx = self.grpc_client.async_infer(model_name=GPI_MODEL_NAME_OVERALL, inputs=inputs, callback=self.callback)
|
||||
|
||||
time_out = 600
|
||||
while time_out > 0:
|
||||
@@ -331,18 +331,33 @@ def infer_cancel(tasks_id):
|
||||
|
||||
def pre_processing_image(image_url):
|
||||
image = oss_get_image(bucket=image_url.split('/')[0], object_name=image_url[image_url.find('/') + 1:], data_type="PIL")
|
||||
# 调整图片高度为768像素,保持宽高比
|
||||
width, height = image.size
|
||||
new_height = 768
|
||||
new_width = int(width * (new_height / height))
|
||||
# 目标图片的尺寸
|
||||
target_width = 512
|
||||
target_height = 768
|
||||
|
||||
# 原始图片的尺寸
|
||||
original_width, original_height = image.size
|
||||
|
||||
# 计算宽度和高度的缩放比例
|
||||
width_ratio = target_width / original_width
|
||||
height_ratio = target_height / original_height
|
||||
|
||||
# 选择较小的缩放比例,确保图片能完整放入目标图片中
|
||||
scale_ratio = min(width_ratio, height_ratio)
|
||||
|
||||
# 计算调整后的尺寸
|
||||
new_width = int(original_width * scale_ratio)
|
||||
new_height = int(original_height * scale_ratio)
|
||||
|
||||
# 调整图片大小
|
||||
resized_image = image.resize((new_width, new_height))
|
||||
|
||||
# 创建一个512x768的透明图片
|
||||
result_image = Image.new("RGBA", (512, 768), (255, 255, 255, 255))
|
||||
# 创建一个 512x768 的透明图片
|
||||
result_image = Image.new("RGBA", (target_width, target_height), (255, 255, 255, 0))
|
||||
|
||||
# 计算需要粘贴的位置,使图片居中
|
||||
x_offset = (512 - new_width) // 2
|
||||
y_offset = 0
|
||||
x_offset = (target_width - new_width) // 2
|
||||
y_offset = (target_height - new_height) // 2
|
||||
|
||||
# 将调整大小后的图片粘贴到透明图片上
|
||||
result_image.paste(resized_image, (x_offset, y_offset), mask=resized_image.split()[3])
|
||||
@@ -371,8 +386,8 @@ if __name__ == '__main__':
|
||||
tasks_id="123-89",
|
||||
# prompt="",
|
||||
image_strength=0.7,
|
||||
prompt="The best quality, masterpiece, real image.,high quality clothing details,8K realistic,HDR",
|
||||
image_url="aida-results/result_40c7924e-e220-11ef-8ea2-0242ac150003.png",
|
||||
prompt=" The best quality, masterpiece, real image.Outwear,high quality clothing details,8K realistic,HDR",
|
||||
image_url="aida-results/result_40b1a2fe-e220-11ef-9bfa-0242ac150003.png",
|
||||
product_type="single"
|
||||
)
|
||||
server = GenerateProductImage(rd)
|
||||
|
||||
Reference in New Issue
Block a user