Fileupload

This commit is contained in:
jiangchaoqing 2025-08-11 09:46:44 +08:00
parent 8e49836d6e
commit d61146f244
1 changed files with 76 additions and 36 deletions

View File

@ -21,8 +21,7 @@ from util.QueUtil import put_queue, get_no_block_queue, clear_queue
import io
from util.LocationUtils import locate_byMqtt
#
from common.YmlConstant import service_yml_path
class FileUpload(Thread):
__slots__ = ('_fb_queue', '_context', '_image_queue', '_analyse_type', '_msg', '_mqtt_list')
@ -35,8 +34,18 @@ class FileUpload(Thread):
# self._algStatus = True # 默认关闭
self._algSwitch = self._context['service']['algSwitch']
self.is_use_llm = True
self.cnt = 0
self.server_ip = self._context['llm']['server_ip']
self.server_port = self._context['llm']['server_port']
self.is_use_llm = self._context['llm']['is_use_llm']
self.cnt = self._context['llm']['cnt']
#0521:
default_enabled = str(self._msg.get("defaultEnabled", "True")).lower() == "true"
@ -64,9 +73,14 @@ class ImageFileUpload(FileUpload):
answers.append(line)
return answers
def get_llm_res(self, image, prompt):
SERVER_IP = "192.168.10.11"
API_URL = f"http://{SERVER_IP}:8000/generate"
def get_llm_res(self, image, prompt,SERVER_IP,API_PORT):
# SERVER_IP = "192.168.10.11"
# API_URL = f"http://{SERVER_IP}:8000/generate"
SERVER_IP = SERVER_IP
API_URL = f"http://{SERVER_IP}:{API_PORT}/generate"
# _, buffer = cv2.imencode('.jpg', image)
# is_success, buffer = cv2.imencode('.png', image)
@ -99,6 +113,11 @@ class ImageFileUpload(FileUpload):
logger.info(f"无法解析服务器返回的响应: {response.text}")
new_result = self.extract_answers(result)
print("###line116",new_result)
new_result = new_result[1] # 获取第二点内容
# flag = "不" in result or ("没" in result and "没错" not in result) or "否" in result or "未" in result or "无" in result
flag = "不存在" in new_result or ("" in new_result and "没错" not in new_result) or (
@ -202,41 +221,60 @@ class ImageFileUpload(FileUpload):
model_info_list = image_result["model_info"]
llm_flag_list = []
msg_list = []
for model_info in model_info_list:
aFrame = model_info["aFrame"]
# aFrame_rgb = cv2.cvtColor(aFrame, cv2.COLOR_BGR2RGB)
fire_flag = model_info.get("modelCode")
print("###line229",fire_flag)
if fire_flag == "008":
aFrame = model_info["aFrame"]
# aFrame_rgb = cv2.cvtColor(aFrame, cv2.COLOR_BGR2RGB)
tar_cls = model_info["detectTargetCode"]
logger.info("目标类别:{}", tar_cls)
tar_cls = model_info["detectTargetCode"]
logger.info("目标类别:{}", tar_cls)
# is_use_llm = True
if tar_cls == '0':
# tar = "明火"
tar = "2. 判断图中是否有明火。3. 如果有,识别火势的大小,比如:[无情况/小/中/大]"
elif tar_cls == '1':
# tar = "某种物质燃烧产生的烟雾"
tar = "2. 判断图中是否有烟雾。3. 如果有,识别烟雾的颜色,比如:[无烟雾/白/灰白/灰黑]"
else:
self.is_use_llm = False
llm_flag = True
if self.is_use_llm:
# prompt = f"我看到图中有{tar},请你判断是否正确。简要回答。"
prompt = f"分点进行输出1. 简短描述图像中的场景。{tar}"
logger.info("检测到目标,大模型提示词:{}", prompt)
llm_flag, llm_res = self.get_llm_res(aFrame, prompt)
llm_flag_list.append(llm_flag)
logger.info("检测到目标,大模型识别图中是否存在目标:{}, 大模型输出:{}", llm_flag, llm_res)
if llm_flag:
logger.info("经大模型筛查,小模型识别正确!!!")
# cv2.imwrite(f"/home/thsw2/wei/image_res/{self.cnt}_{tar_cls}_1.jpg", aFrame, [cv2.IMWRITE_JPEG_QUALITY, 80])
# self.cnt = self.cnt + 1
# 0715 这块也不对因为需要具体到目标才可以否则只看0 1 ,是无法做到判断正确的火情处理,还有大量其他的部分
# is_use_llm = True
if tar_cls == '0':
# tar = "明火"
tar = "2. 判断图中是否有明火。3. 如果有,识别火势的大小,比如:[无情况/小/中/大]"
elif tar_cls == '1':
# tar = "某种物质燃烧产生的烟雾"
tar = "2. 判断图中是否有烟雾。3. 如果有,识别烟雾的颜色,比如:[无烟雾/白/灰白/灰黑]"
else:
logger.info("经大模型筛查,小模型识别错误!!!")
# cv2.imwrite(f"/home/thsw2/wei/image_res/{self.cnt}_{tar_cls}_0.jpg", aFrame, [cv2.IMWRITE_JPEG_QUALITY, 80])
# self.cnt = self.cnt + 1
self.is_use_llm = False
llm_flag = True
if self.is_use_llm:
# prompt = f"我看到图中有{tar},请你判断是否正确。简要回答。"
prompt = f"分点进行输出1. 简短描述图像中的场景。{tar}"
logger.info("检测到目标,大模型提示词:{}", prompt)
# llm_flag, llm_res = self.get_llm_res(aFrame, prompt)
llm_flag, llm_res = self.get_llm_res(aFrame, prompt,self.server_ip,self.server_port)
llm_flag_list.append(llm_flag)
logger.info("检测到目标,大模型识别图中是否存在目标:{}, 大模型输出:{}", llm_flag, llm_res)
if llm_flag:
logger.info("经大模型筛查,小模型识别正确!!!")
# cv2.imwrite(f"/home/thsw2/wei/image_res/{self.cnt}_{tar_cls}_1.jpg", aFrame, [cv2.IMWRITE_JPEG_QUALITY, 80])
# self.cnt = self.cnt + 1
else:
logger.info("经大模型筛查,小模型识别错误!!!")
# cv2.imwrite(f"/home/thsw2/wei/image_res/{self.cnt}_{tar_cls}_0.jpg", aFrame, [cv2.IMWRITE_JPEG_QUALITY, 80])
# self.cnt = self.cnt + 1
else:
llm_flag_list.append(llm_flag)
ai_image = cv2.imencode(".jpg", aFrame)[1]
ai_image_name = build_image_name(image_result["current_frame"],
@ -271,6 +309,7 @@ class ImageFileUpload(FileUpload):
remote_image_list.append( tk.result() )
for ii, model_info in enumerate(model_info_list):
if llm_flag_list[ii]:
msg_list.append( message_feedback(request_id,
AnalysisStatus.RUNNING.value,
@ -282,6 +321,7 @@ class ImageFileUpload(FileUpload):
longitude=model_info['gps'][0],
latitude=model_info['gps'][1],
) )
if (not self._algSwitch) or ( self._algStatus and self._algSwitch):
for msg in msg_list: