feat generate slogan | to product image | slogan 接口部署

This commit is contained in:
zhouchengrong
2024-05-30 15:01:39 +08:00
parent 1f47d94431
commit 401b76bd95
11 changed files with 280 additions and 174 deletions

View File

@@ -17,14 +17,15 @@ import numpy as np
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
# minio_client = Minio(
# f"{MINIO_IP}:{MINIO_PORT}",
# access_key=MINIO_ACCESS,
# secret_key=MINIO_SECRET,
# secure=MINIO_SECURE)
minio_client = Minio(
MINIO_URL,
access_key=MINIO_ACCESS,
secret_key=MINIO_SECRET,
secure=MINIO_SECURE)
s3 = boto3.client(
's3',
@@ -130,19 +131,19 @@ def synthesis(data, size):
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}"
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 ""
# 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 ""
except Exception as e:
logging.warning(f"synthesis runtime exception : {e}")