feat generate slogan | to product image | slogan 接口部署
This commit is contained in:
@@ -4,19 +4,24 @@ import boto3
|
|||||||
import cv2
|
import cv2
|
||||||
import numpy as np
|
import numpy as np
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
|
from minio import Minio
|
||||||
|
|
||||||
|
from app.core.config import *
|
||||||
from ..builder import PIPELINES
|
from ..builder import PIPELINES
|
||||||
|
|
||||||
# minio_client = Minio(
|
minio_client = Minio(
|
||||||
# f"{MINIO_IP}:{MINIO_PORT}",
|
MINIO_URL,
|
||||||
# access_key=MINIO_ACCESS,
|
access_key=MINIO_ACCESS,
|
||||||
# secret_key=MINIO_SECRET,
|
secret_key=MINIO_SECRET,
|
||||||
# secure=MINIO_SECURE)
|
secure=MINIO_SECURE)
|
||||||
s3 = boto3.client(
|
|
||||||
's3',
|
|
||||||
aws_access_key_id="AKIAVD3OJIMF6UJFLSHZ",
|
# s3 = boto3.client(
|
||||||
aws_secret_access_key="LNIwFFB27/QedtZ+Q/viVUoX9F5x1DbuM8N0DkD8",
|
# 's3',
|
||||||
region_name="ap-east-1"
|
# aws_access_key_id="AKIAVD3OJIMF6UJFLSHZ",
|
||||||
)
|
# aws_secret_access_key="LNIwFFB27/QedtZ+Q/viVUoX9F5x1DbuM8N0DkD8",
|
||||||
|
# region_name="ap-east-1"
|
||||||
|
# )
|
||||||
|
|
||||||
|
|
||||||
@PIPELINES.register_module()
|
@PIPELINES.register_module()
|
||||||
@@ -57,8 +62,8 @@ class Painting(object):
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_gradient(bucket_name, object_name):
|
def get_gradient(bucket_name, object_name):
|
||||||
# image_data = minio_client.get_object(bucket_name, object_name)
|
image_data = minio_client.get_object(bucket_name, object_name)
|
||||||
image_data = s3.get_object(Bucket=bucket_name, Key=object_name)['Body']
|
# image_data = s3.get_object(Bucket=bucket_name, Key=object_name)['Body']
|
||||||
|
|
||||||
# 从数据流中读取图像
|
# 从数据流中读取图像
|
||||||
image_bytes = image_data.read()
|
image_bytes = image_data.read()
|
||||||
@@ -390,8 +395,8 @@ class PrintPainting(object):
|
|||||||
if not 'IfSingle' in print_dict.keys():
|
if not 'IfSingle' in print_dict.keys():
|
||||||
print_dict['IfSingle'] = False
|
print_dict['IfSingle'] = False
|
||||||
|
|
||||||
# data = minio_client.get_object(print_dict['print_path_list'][0].split("/", 1)[0], print_dict['print_path_list'][0].split("/", 1)[1])
|
data = minio_client.get_object(print_dict['print_path_list'][0].split("/", 1)[0], print_dict['print_path_list'][0].split("/", 1)[1])
|
||||||
data = s3.get_object(Bucket=print_dict['print_path_list'][0].split("/", 1)[0], Key=print_dict['print_path_list'][0].split("/", 1)[1])['Body']
|
# data = s3.get_object(Bucket=print_dict['print_path_list'][0].split("/", 1)[0], Key=print_dict['print_path_list'][0].split("/", 1)[1])['Body']
|
||||||
|
|
||||||
data_bytes = BytesIO(data.read())
|
data_bytes = BytesIO(data.read())
|
||||||
image = Image.open(data_bytes)
|
image = Image.open(data_bytes)
|
||||||
@@ -473,8 +478,8 @@ class PrintPainting(object):
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def read_image(image_url):
|
def read_image(image_url):
|
||||||
# data = minio_client.get_object(image_url.split("/", 1)[0], image_url.split("/", 1)[1])
|
data = minio_client.get_object(image_url.split("/", 1)[0], image_url.split("/", 1)[1])
|
||||||
data = s3.get_object(Bucket=image_url.split("/", 1)[0], Key=image_url.split("/", 1)[1])['Body']
|
# data = s3.get_object(Bucket=image_url.split("/", 1)[0], Key=image_url.split("/", 1)[1])['Body']
|
||||||
|
|
||||||
data_bytes = BytesIO(data.read())
|
data_bytes = BytesIO(data.read())
|
||||||
image = Image.open(data_bytes)
|
image = Image.open(data_bytes)
|
||||||
|
|||||||
@@ -156,20 +156,18 @@ def synthesis_single(front_image, back_image):
|
|||||||
if back_image:
|
if back_image:
|
||||||
result_image.paste(back_image, (0, 0), back_image)
|
result_image.paste(back_image, (0, 0), back_image)
|
||||||
|
|
||||||
with io.BytesIO() as output:
|
# with io.BytesIO() as output:
|
||||||
result_image.save(output, format='PNG')
|
# result_image.save(output, format='PNG')
|
||||||
data = output.getvalue()
|
# data = output.getvalue()
|
||||||
|
# object_name = f'result_{generate_uuid()}.png'
|
||||||
# image_data = io.BytesIO()
|
# response = s3.put_object(Bucket="aida-results", Key=object_name, Body=data, ContentType='image/png')
|
||||||
# result_image.save(image_data, format='PNG')
|
# object_url = f"aida-results/{object_name}"
|
||||||
# image_data.seek(0)
|
# if response['ResponseMetadata']['HTTPStatusCode'] == 200:
|
||||||
# image_bytes = image_data.read()
|
# return object_url
|
||||||
# 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}"
|
# else:
|
||||||
|
# return ""
|
||||||
object_name = f'result_{generate_uuid()}.png'
|
image_data = io.BytesIO()
|
||||||
response = s3.put_object(Bucket="aida-results", Key=object_name, Body=data, ContentType='image/png')
|
result_image.save(image_data, format='PNG')
|
||||||
object_url = f"aida-results/{object_name}"
|
image_data.seek(0)
|
||||||
if response['ResponseMetadata']['HTTPStatusCode'] == 200:
|
image_bytes = image_data.read()
|
||||||
return object_url
|
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}"
|
||||||
else:
|
|
||||||
return ""
|
|
||||||
|
|||||||
Reference in New Issue
Block a user