first commit
This commit is contained in:
92
app.py
Normal file
92
app.py
Normal file
@ -0,0 +1,92 @@
|
||||
from flask import Flask, request
|
||||
import requests
|
||||
import json
|
||||
import time
|
||||
import logging
|
||||
from PIL import Image
|
||||
from io import BytesIO
|
||||
from utils.model_init import initModel
|
||||
from detecttracking.stream_pipeline import stream_pipeline
|
||||
from logging.handlers import TimedRotatingFileHandler
|
||||
from llm.qwe_agent import get_product_description
|
||||
import pdb
|
||||
|
||||
app = Flask(__name__)
|
||||
# 配置日志处理器
|
||||
log_handler = TimedRotatingFileHandler('./log/aiReview.log', when='midnight', interval=90, backupCount=1)
|
||||
log_handler.suffix = "%Y-%m-%d"
|
||||
log_handler.setLevel(logging.INFO)
|
||||
log_formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s')
|
||||
log_handler.setFormatter(log_formatter)
|
||||
|
||||
# 获取根日志记录器并添加处理器
|
||||
root_logger = logging.getLogger()
|
||||
root_logger.setLevel(logging.INFO)
|
||||
root_logger.addHandler(log_handler)
|
||||
|
||||
# data = {
|
||||
# "goodsName": "优诺优丝黄桃果粒风味发酵乳",
|
||||
# "measureProperty": 0,
|
||||
# "qty": 1,
|
||||
# "price": 25.9,
|
||||
# "weight": 560, # 单位克
|
||||
# "barcode": "6931806801024",
|
||||
# # "video": "https://resources.cos.yimaogo.com/bl/3203600/54:78:c9:a4:8c:5e/video/411173317367614619680.mp4",
|
||||
# "video": "https://ieemoo-ai.obs.cn-east-3.myhuaweicloud.com/videos/20231009/04/04_20231009-082149_21f2ca35-f2c2-4386-8497-3e7a3b407f03_4901872831197.mp4",
|
||||
# "goodsPic": "https://ieemoo-storage.obs.cn-east-3.myhuaweicloud.com/lhpic/6931806801024.jpg",
|
||||
# "measureUnit": "组",
|
||||
# "goodsSpec": "405g"
|
||||
# }
|
||||
|
||||
|
||||
def item_analysis(stream_dict):
|
||||
assert initModel.resnet_model is not None, "resnetModel is None"
|
||||
assert initModel.yolo_model is not None, "yoloModel is None"
|
||||
track_imgs = stream_pipeline(stream_dict, initModel.resnet_model, initModel.yolo_model)
|
||||
std_img = None
|
||||
if stream_dict['goodsPic'] is not None:
|
||||
response = requests.get(stream_dict['goodsPic'])
|
||||
std_img = Image.open(BytesIO(response.content))
|
||||
description_dict = get_product_description(std_img, track_imgs, initModel.qwen_model, initModel.processor)
|
||||
print(description_dict)
|
||||
return description_dict
|
||||
|
||||
|
||||
@app.route('/ai_review', methods=['POST'])
|
||||
def aiReview(): # put application's code here
|
||||
start = time.time()
|
||||
data = request.get_data()
|
||||
data = json.loads(data)
|
||||
video_url = data['video']
|
||||
goods_pic_url = data['goodsPic']
|
||||
v_reponse = requests.get(video_url)
|
||||
p_reponse = requests.get(goods_pic_url)
|
||||
if v_reponse.status_code == 200:
|
||||
logging.info(f'video:{video_url} download success')
|
||||
else:
|
||||
video_url = None
|
||||
logging.error(f'video:{video_url} download fail')
|
||||
if p_reponse.status_code == 200:
|
||||
logging.info(f'video:{goods_pic_url} download success')
|
||||
else:
|
||||
goods_pic_url = None
|
||||
logging.error(f'video:{goods_pic_url} download fail')
|
||||
|
||||
for key, value in data.items():
|
||||
if not value:
|
||||
data[key] = None
|
||||
logging.error(f'{key} is null')
|
||||
# stream_pipeline(data)
|
||||
item_analysis(data)
|
||||
end = time.time()
|
||||
logging.info(f'aiReview cost {end - start}s')
|
||||
return 0
|
||||
|
||||
|
||||
# def main():
|
||||
# item_analysis(data)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
# main()
|
||||
app.run('0.0.0.0', port=8060)
|
Reference in New Issue
Block a user