68 lines
2.0 KiB
Python
68 lines
2.0 KiB
Python
#!/usr/bin/env python
|
||
# -*- coding: UTF-8 -*-
|
||
"""
|
||
@Project :trinity_client
|
||
@File :upload_image.py
|
||
@Author :周成融
|
||
@Date :2023/8/28 13:49:20
|
||
@detail :
|
||
"""
|
||
import io
|
||
import logging
|
||
|
||
import cv2
|
||
from PIL import Image
|
||
from minio import Minio
|
||
|
||
from app.core.config import *
|
||
|
||
minio_client = Minio(MINIO_URL, access_key=MINIO_ACCESS, secret_key=MINIO_SECRET, secure=MINIO_SECURE)
|
||
|
||
|
||
def upload_png_sd(image, user_id, category, object_name):
|
||
try:
|
||
_, img_byte_array = cv2.imencode('.jpg', image)
|
||
minio_req = minio_client.put_object(
|
||
GI_MINIO_BUCKET,
|
||
f'{user_id}/{category}/{object_name}',
|
||
io.BytesIO(img_byte_array),
|
||
len(img_byte_array),
|
||
content_type='image/jpeg'
|
||
)
|
||
image_url = f"aida-users/{minio_req.object_name}"
|
||
return image_url
|
||
except Exception as e:
|
||
logging.warning(f"upload_png_mask runtime exception : {e}")
|
||
|
||
|
||
def upload_stain_png_sd(image, user_id, category, object_name):
|
||
try:
|
||
_, img_byte_array = cv2.imencode('.jpg', image)
|
||
minio_req = minio_client.put_object(
|
||
"test",
|
||
f'generate_result/stain/{user_id}_{category}_{object_name}',
|
||
io.BytesIO(img_byte_array),
|
||
len(img_byte_array),
|
||
content_type='image/jpeg'
|
||
)
|
||
image_url = f"test/{minio_req.object_name}"
|
||
return image_url
|
||
except Exception as e:
|
||
logging.warning(f"upload_png_mask runtime exception : {e}")
|
||
|
||
|
||
def upload_face_png_sd(image, user_id, category, object_name):
|
||
try:
|
||
_, img_byte_array = cv2.imencode('.jpg', image)
|
||
minio_req = minio_client.put_object(
|
||
"test",
|
||
f'generate_result/face/{user_id}_{category}_{object_name}',
|
||
io.BytesIO(img_byte_array),
|
||
len(img_byte_array),
|
||
content_type='image/jpeg'
|
||
)
|
||
image_url = f"test/{minio_req.object_name}"
|
||
return image_url
|
||
except Exception as e:
|
||
logging.warning(f"upload_png_mask runtime exception : {e}")
|