feat
fix minio and s3
This commit is contained in:
@@ -1,17 +1,15 @@
|
||||
import io
|
||||
import json
|
||||
import logging
|
||||
import time
|
||||
import minio.error
|
||||
import redis
|
||||
import json
|
||||
import cv2
|
||||
import minio.error
|
||||
import numpy as np
|
||||
import redis
|
||||
import torch
|
||||
import tritonclient.grpc as grpcclient
|
||||
from minio import Minio
|
||||
from app.core.config import *
|
||||
from app.schemas.super_resolution import SuperResolutionModel
|
||||
from app.service.utils.decorator import RunTime
|
||||
from app.service.utils.oss_client import oss_get_image, oss_upload_image
|
||||
|
||||
logger = logging.getLogger()
|
||||
|
||||
@@ -24,7 +22,7 @@ class SuperResolution:
|
||||
self.user_id = self.tasks_id[self.tasks_id.rfind('-') + 1:]
|
||||
self.sr_image_url = data.sr_image_url
|
||||
self.sr_xn = data.sr_xn
|
||||
self.minio_client = Minio(MINIO_URL, access_key=MINIO_ACCESS, secret_key=MINIO_SECRET, secure=MINIO_SECURE)
|
||||
# self.minio_client = Minio(MINIO_URL, access_key=MINIO_ACCESS, secret_key=MINIO_SECRET, secure=MINIO_SECURE)
|
||||
self.redis_client.set(self.tasks_id, json.dumps({'status': 'PENDING', 'message': "pending", 'data': ''}))
|
||||
self.redis_client.expire(self.tasks_id, 600)
|
||||
self.connection = pika.BlockingConnection(pika.ConnectionParameters(**RABBITMQ_PARAMS))
|
||||
@@ -33,16 +31,25 @@ class SuperResolution:
|
||||
# @RunTime
|
||||
def read_image(self):
|
||||
try:
|
||||
image_data = self.minio_client.get_object(self.sr_image_url.split("/", 1)[0], self.sr_image_url.split("/", 1)[1])
|
||||
img = oss_get_image(bucket=self.sr_image_url.split("/", 1)[0], object_name=self.sr_image_url.split("/", 1)[1], data_type="cv2")
|
||||
except minio.error.S3Error as e:
|
||||
sr_data = json.dumps({'tasks_id': self.tasks_id, 'status': 'ERROR', 'message': f'{e}'})
|
||||
self.channel.basic_publish(exchange='', routing_key=SR_RABBITMQ_QUEUES, body=sr_data)
|
||||
logger.info(f" [x] Sent {sr_data}")
|
||||
raise FileNotFoundError(f"Image '{self.sr_image_url.split('/', 1)[1]}' not found in bucket '{self.sr_image_url.split('/', 1)[0]}'")
|
||||
img = np.frombuffer(image_data.data, np.uint8) # 转成8位无符号整型
|
||||
img = cv2.imdecode(img, cv2.IMREAD_COLOR).astype(np.float32) / 255. # 解码
|
||||
return img
|
||||
|
||||
# try:
|
||||
# image_data = self.minio_client.get_object(self.sr_image_url.split("/", 1)[0], self.sr_image_url.split("/", 1)[1])
|
||||
# except minio.error.S3Error as e:
|
||||
# sr_data = json.dumps({'tasks_id': self.tasks_id, 'status': 'ERROR', 'message': f'{e}'})
|
||||
# self.channel.basic_publish(exchange='', routing_key=SR_RABBITMQ_QUEUES, body=sr_data)
|
||||
# logger.info(f" [x] Sent {sr_data}")
|
||||
# raise FileNotFoundError(f"Image '{self.sr_image_url.split('/', 1)[1]}' not found in bucket '{self.sr_image_url.split('/', 1)[0]}'")
|
||||
# img = np.frombuffer(image_data.data, np.uint8) # 转成8位无符号整型
|
||||
# img = cv2.imdecode(img, cv2.IMREAD_COLOR).astype(np.float32) / 255. # 解码
|
||||
# return img
|
||||
|
||||
def read_tasks_status(self):
|
||||
status_data = json.loads(self.redis_client.get(self.tasks_id))
|
||||
logging.info(f"{self.tasks_id} ===> {status_data}")
|
||||
@@ -101,8 +108,10 @@ class SuperResolution:
|
||||
def upload_img_sr(self, image):
|
||||
try:
|
||||
image_bytes = cv2.imencode('.jpg', image)[1].tobytes()
|
||||
res = self.minio_client.put_object(f'{SR_MINIO_BUCKET}', f'{self.user_id}/sr/output/{self.tasks_id}.jpg', io.BytesIO(image_bytes), len(image_bytes), content_type='image/png')
|
||||
image_url = f"aida-users/{res.object_name}"
|
||||
# res = self.minio_client.put_object(f'{SR_MINIO_BUCKET}', f'{self.user_id}/sr/output/{self.tasks_id}.jpg', io.BytesIO(image_bytes), len(image_bytes), content_type='image/png')
|
||||
object_name = f'{self.user_id}/sr/output/{self.tasks_id}.jpg'
|
||||
oss_upload_image(bucket=SR_MINIO_BUCKET, object_name=object_name, image_bytes=image_bytes)
|
||||
image_url = f"{SR_MINIO_BUCKET}/{object_name}"
|
||||
return image_url
|
||||
except Exception as e:
|
||||
logger.warning(f"upload_png_mask runtime exception : {e}")
|
||||
|
||||
Reference in New Issue
Block a user