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