|
@@ -130,41 +130,30 @@ class AiView(View):
|
|
|
ai_server = 'rekognition'
|
|
|
|
|
|
redis_obj = RedisObject(db=6)
|
|
|
- APP_NOTIFY_KEY = f'ASJ:NOTIFY:PUSH:{uid}:{channel}' # 推送间隔缓存KEY
|
|
|
- push_cache_data = redis_obj.get_data(APP_NOTIFY_KEY)
|
|
|
+ app_msg_key = f'ASJ:NOTIFY:PUSH:{uid}:{channel}' # 推送间隔缓存KEY
|
|
|
+ push_cache_data = redis_obj.get_data(app_msg_key)
|
|
|
is_push = False if push_cache_data else True
|
|
|
|
|
|
notify_data = uid_push_qs[0]['uid_set__msg_notify']
|
|
|
|
|
|
# APP推送提醒状态
|
|
|
notify = self.is_ai_push(uid, notify_data) if is_push else is_push
|
|
|
+ params = {
|
|
|
+ 'ai_server': ai_server,
|
|
|
+ 'uid': uid,
|
|
|
+ 'file_list': file_list,
|
|
|
+ 'channel': channel,
|
|
|
+ 'n_time': n_time,
|
|
|
+ 'uid_push_qs': uid_push_qs,
|
|
|
+ 'notify': notify,
|
|
|
+ 'app_msg_key': app_msg_key,
|
|
|
+ 'redis_obj': redis_obj,
|
|
|
+ 'push_cache_data': push_cache_data,
|
|
|
+ 'detect_group': detect_group
|
|
|
+ }
|
|
|
|
|
|
- if ai_server == 'sageMaker': # 自建模型sageMaker AI
|
|
|
- sage_maker = SageMakerAiObject()
|
|
|
- ai_result = sage_maker.sage_maker_ai_server(uid, file_list) # 图片base64识别AI标签
|
|
|
- if ai_result:
|
|
|
- if ai_result == 'imageError':
|
|
|
- return response.json(0)
|
|
|
- res = sage_maker.get_table_name(uid, ai_result, detect_group)
|
|
|
- if not res: # 当前识别结果未匹配
|
|
|
- return response.json(0)
|
|
|
- push_thread = threading.Thread(
|
|
|
- target=self.async_message_push,
|
|
|
- kwargs={'sage_maker': sage_maker, 'uid': uid, 'n_time': n_time, 'uid_push_qs': uid_push_qs,
|
|
|
- 'channel': channel, 'res': res, 'file_list': file_list, 'notify': notify})
|
|
|
- push_thread.start() # AI识别异步存表&推送
|
|
|
- self.add_push_cache(APP_NOTIFY_KEY, redis_obj, push_cache_data,
|
|
|
- uid_push_qs[0]['uid_set__new_detect_interval'])
|
|
|
- return response.json(0)
|
|
|
- TIME_LOGGER.info(f'uid={uid},sagemakerAI识别失败{ai_result}')
|
|
|
-
|
|
|
- push_thread = threading.Thread(target=self.image_label_detection,
|
|
|
- kwargs={'ai_server': ai_server, 'uid': uid, 'file_list': file_list,
|
|
|
- 'detect_group': detect_group, 'n_time': n_time,
|
|
|
- 'uid_push_qs': uid_push_qs,
|
|
|
- 'channel': channel})
|
|
|
- push_thread.start() # AI识别异步存表&推送
|
|
|
-
|
|
|
+ msg_detection = threading.Thread(target=self.ai_table_detection, kwargs=params)
|
|
|
+ msg_detection.start()
|
|
|
return response.json(0)
|
|
|
except Exception as e:
|
|
|
print(e)
|
|
@@ -175,6 +164,37 @@ class AiView(View):
|
|
|
TIME_LOGGER.info(f'rekognition识别errMsg={data}')
|
|
|
return response.json(48, data)
|
|
|
|
|
|
+ def ai_table_detection(self, ai_server, uid, file_list, channel, n_time, uid_push_qs, notify,
|
|
|
+ app_msg_key, redis_obj, push_cache_data, detect_group):
|
|
|
+ """
|
|
|
+ AI标签检测(移动侦测图片)
|
|
|
+ """
|
|
|
+ if ai_server == 'sageMaker': # 自建模型sageMaker AI
|
|
|
+ sage_maker = SageMakerAiObject()
|
|
|
+ ai_result = sage_maker.sage_maker_ai_server(uid, file_list) # 图片base64识别AI标签
|
|
|
+ if ai_result:
|
|
|
+ if ai_result == 'imageError':
|
|
|
+ return
|
|
|
+ res = sage_maker.get_table_name(uid, ai_result, detect_group)
|
|
|
+ if not res: # 当前识别结果未匹配
|
|
|
+ return
|
|
|
+ push_thread = threading.Thread(
|
|
|
+ target=self.async_message_push,
|
|
|
+ kwargs={'sage_maker': sage_maker, 'uid': uid, 'n_time': n_time, 'uid_push_qs': uid_push_qs,
|
|
|
+ 'channel': channel, 'res': res, 'file_list': file_list, 'notify': notify})
|
|
|
+ push_thread.start() # AI识别异步存表&推送
|
|
|
+ self.add_push_cache(app_msg_key, redis_obj, push_cache_data,
|
|
|
+ uid_push_qs[0]['uid_set__new_detect_interval'])
|
|
|
+ return
|
|
|
+ TIME_LOGGER.info(f'uid={uid},sagemakerAI识别失败{ai_result}')
|
|
|
+
|
|
|
+ push_thread = threading.Thread(target=self.image_label_detection,
|
|
|
+ kwargs={'ai_server': ai_server, 'uid': uid, 'file_list': file_list,
|
|
|
+ 'detect_group': detect_group, 'n_time': n_time,
|
|
|
+ 'uid_push_qs': uid_push_qs,
|
|
|
+ 'channel': channel})
|
|
|
+ push_thread.start() # AI识别异步存表&推送
|
|
|
+
|
|
|
def async_message_push(self, sage_maker, uid, n_time, uid_push_qs, channel, res, file_list, notify):
|
|
|
# 保存推送消息
|
|
|
sage_maker.save_push_message(uid, n_time, uid_push_qs, channel, res, file_list, notify)
|