This commit is contained in:
lichen
2022-06-01 17:12:45 +08:00
parent a79ed4db47
commit e2682956ca
3 changed files with 69 additions and 5 deletions

View File

@ -24,6 +24,22 @@ from flask import request, Flask, jsonify, request
#from ocr_system.predict_all import *
import logging
import logging.config
from skywalking import agent, config
SW_SERVER = os.environ.get('SW_AGENT_COLLECTOR_BACKEND_SERVICES')
SW_SERVICE_NAME = os.environ.get('SW_AGENT_NAME')
if SW_SERVER and SW_SERVICE_NAME:
config.init() #采集服务的地址,给自己的服务起个名称
#config.init(collector="123.60.56.51:11800", service='ieemoo-ai-search') #采集服务的地址,给自己的服务起个名称
agent.start()
def setup_logging(path):
if os.path.exists(path):
with open(path, 'r') as f:
config = json.load(f)
logging.config.dictConfig(config)
logger = logging.getLogger("root")
return logger
logger = setup_logging('utils/logging.json')
app = Flask(__name__)
# 日志系统配置
@ -178,7 +194,7 @@ def predict():
if request.method == 'POST':
try:
data = request.get_data()
print(data)
#print(data)
data_str = data.decode("utf-8")
json_data = json.loads(data_str)
pic = json_data.get("file")
@ -204,10 +220,12 @@ def predict():
ocr_res = {"Ocr": {"barcode_rst": "", "barcode_success": "false", "ocr_rst": "", "ocr_success": False}}
ocr_res.update(tar_res)
os.remove(os.sep.join(['../module/ieemoo-ai-predict/imgs',code+'.jpg']))
logger.info(ocr_res)
return ocr_res
except:
return {"Ocr": {"barcode_rst": "", "barcode_success": "false", "ocr_rst": "", "ocr_success": False}, "TargetDetect": {""}, "tag": False}
except Exception as e:
logger.warning(e)
return {"Ocr": {"barcode_rst": "", "barcode_success": "false", "ocr_rst": "", "ocr_success": False}, "TargetDetect": {""}, "tag": False}
if __name__ == '__main__':
#http_server = WSGIServer(('0.0.0.0', 8000), app)
#http_server.serve_forever()
app.run()
app.run(host='192.168.1.142', port=8000)

View File

@ -4,7 +4,7 @@ gevent==21.1.2
matplotlib==3.4.1
numpy==1.20.2
esdk-obs-python --trusted-host pypi.org
opencv_python==4.5.1.48
opencv_python==4.5.5.64
opencv-contrib-python==4.5.5.64
Pillow==9.1.0
scipy==1.6.2

46
utils/logging.json Normal file
View File

@ -0,0 +1,46 @@
{
"version":1,
"disable_existing_loggers":false,
"formatters":{
"simple":{
"format":"%(asctime)s - %(module)s - %(thread)d - %(levelname)s : %(message)s"
}
},
"handlers":{
"console":{
"class":"logging.StreamHandler",
"level":"DEBUG",
"formatter":"simple",
"stream":"ext://sys.stdout"
},
"info_file_handler":{
"class":"logging.handlers.RotatingFileHandler",
"level":"INFO",
"formatter":"simple",
"filename":"../log/ieemoo-ai-predict-biz.log",
"maxBytes":10485760,
"backupCount":20,
"encoding":"utf8"
},
"error_file_handler":{
"class":"logging.handlers.RotatingFileHandler",
"level":"ERROR",
"formatter":"simple",
"filename":"../log/ieemoo-ai-predict-biz.log",
"maxBytes":10485760,
"backupCount":20,
"encoding":"utf8"
}
},
"loggers":{
"my_module":{
"level":"ERROR",
"handlers":["info_file_handler"],
"propagate":"no"}
},
"root":{
"level":"INFO",
"handlers":["console","info_file_handler","error_file_handler"]
}
}