feat generate 迁移
This commit is contained in:
@@ -1,10 +1,7 @@
|
||||
import io
|
||||
import logging
|
||||
import time
|
||||
from io import BytesIO
|
||||
|
||||
import minio.error
|
||||
import pika
|
||||
import redis
|
||||
import json
|
||||
import cv2
|
||||
@@ -12,10 +9,9 @@ import numpy as np
|
||||
import torch
|
||||
import tritonclient.grpc as grpcclient
|
||||
from minio import Minio
|
||||
from app.core.config import MINIO_IP, MINIO_ACCESS, MINIO_SECRET, MINIO_SECURE, MINIO_PORT, REDIS_HOST, REDIS_PORT, REDIS_DB, SR_MODEL_NAME, RABBITMQ_PARAMS, SR_RABBITMQ_QUEUES, SR_TRITON_URL
|
||||
from app.core.config import *
|
||||
from app.schemas.super_resolution import SuperResolutionModel
|
||||
from app.service.utils.decorator import RunTime
|
||||
from app.service.utils.generate_uuid import generate_uuid
|
||||
|
||||
logger = logging.getLogger()
|
||||
|
||||
@@ -25,6 +21,7 @@ class SuperResolution:
|
||||
self.triton_client = grpcclient.InferenceServerClient(url=SR_TRITON_URL)
|
||||
self.redis_client = redis.StrictRedis(host=REDIS_HOST, port=REDIS_PORT, db=REDIS_DB, decode_responses=True)
|
||||
self.tasks_id = data.sr_tasks_id
|
||||
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(
|
||||
@@ -108,11 +105,11 @@ class SuperResolution:
|
||||
# output_url = self.upload_img_sr(output, generate_uuid())
|
||||
# return output_url
|
||||
|
||||
def upload_img_sr(self, image, object_name):
|
||||
def upload_img_sr(self, image):
|
||||
try:
|
||||
image_bytes = cv2.imencode('.jpg', image)[1].tobytes()
|
||||
image_url = f"test/{self.minio_client.put_object(f'test', f'{object_name}.jpg', io.BytesIO(image_bytes), len(image_bytes), content_type='image/png').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')
|
||||
image_url = f"aida-users/{res.object_name}"
|
||||
return image_url
|
||||
except Exception as e:
|
||||
logger.warning(f"upload_png_mask runtime exception : {e}")
|
||||
@@ -129,7 +126,7 @@ class SuperResolution:
|
||||
if output.ndim == 3:
|
||||
output = np.transpose(output[[2, 1, 0], :, :], (1, 2, 0)) # CHW-RGB to HCW-BGR
|
||||
output = (output * 255.0).round().astype(np.uint8)
|
||||
output_url = self.upload_img_sr(output, generate_uuid())
|
||||
output_url = self.upload_img_sr(output)
|
||||
sr_data = json.dumps({'tasks_id': self.tasks_id, 'status': 'SUCCESS', 'message': 'success', 'data': f'{output_url}'})
|
||||
self.channel.basic_publish(exchange='', routing_key=SR_RABBITMQ_QUEUES, body=sr_data)
|
||||
logger.info(f" [x] Sent {sr_data}")
|
||||
|
||||
Reference in New Issue
Block a user