feat(新功能): pose transform 部署
fix(修复bug): docs(文档变更): refactor(重构): test(增加测试):
This commit is contained in:
68
app/service/generate_image/utils/pose_transform_upload.py
Normal file
68
app/service/generate_image/utils/pose_transform_upload.py
Normal file
@@ -0,0 +1,68 @@
|
||||
import io
|
||||
import logging
|
||||
|
||||
import imageio
|
||||
import numpy as np
|
||||
# import boto3
|
||||
from minio import Minio
|
||||
|
||||
from app.core.config import *
|
||||
from app.service.utils.new_oss_client import oss_upload_image
|
||||
|
||||
minio_client = Minio(MINIO_URL, access_key=MINIO_ACCESS, secret_key=MINIO_SECRET, secure=MINIO_SECURE)
|
||||
|
||||
|
||||
def upload_first_image(image, user_id, category, file_name):
|
||||
try:
|
||||
image_data = io.BytesIO()
|
||||
image.save(image_data, format='PNG')
|
||||
image_data.seek(0)
|
||||
image_bytes = image_data.read()
|
||||
object_name = f'{user_id}/{category}/{file_name}'
|
||||
req = oss_upload_image(oss_client=minio_client, bucket=GI_MINIO_BUCKET, object_name=object_name, image_bytes=image_bytes)
|
||||
image_url = f"aida-users/{object_name}"
|
||||
return image_url
|
||||
except Exception as e:
|
||||
logging.warning(f"upload_png_mask runtime exception : {e}")
|
||||
|
||||
|
||||
def upload_gif(gif_buffer, user_id, category, file_name):
|
||||
try:
|
||||
object_name = f'{user_id}/{category}/{file_name}'
|
||||
req = minio_client.put_object(
|
||||
"aida-users",
|
||||
object_name,
|
||||
gif_buffer,
|
||||
length=gif_buffer.getbuffer().nbytes,
|
||||
content_type="image/gif"
|
||||
)
|
||||
return f"aida-users/{object_name}"
|
||||
except Exception as e:
|
||||
logging.warning(f"upload_gif runtime exception : {e}")
|
||||
|
||||
|
||||
def upload_video(frames, user_id, category, file_name):
|
||||
try:
|
||||
video_buffer = io.BytesIO()
|
||||
with imageio.get_writer(video_buffer, format='mp4', fps=24) as writer:
|
||||
for frame in frames:
|
||||
writer.append_data(frame)
|
||||
video_buffer.seek(0)
|
||||
|
||||
object_name = f'{user_id}/{category}/{file_name}'
|
||||
# 上传视频流到MinIO
|
||||
minio_client.put_object(
|
||||
bucket_name="aida-users",
|
||||
object_name=object_name,
|
||||
data=video_buffer,
|
||||
length=video_buffer.getbuffer().nbytes,
|
||||
content_type='video/mp4'
|
||||
)
|
||||
return f"aida-users/{object_name}"
|
||||
except Exception as e:
|
||||
logging.warning(f"upload_video runtime exception : {e}")
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
images = np.random.randint(0, 256, size=(4, 512, 512, 3), dtype=np.uint8)
|
||||
print(upload_video(images, user_id=89, category='test', file_name="1.mp4"))
|
||||
Reference in New Issue
Block a user