Commit b63dcce9 by lichenggang

新增品牌异常检测服务

parent ae700280
......@@ -11,3 +11,5 @@ if ENVIRONMENT == 'test':
model_config['modextr_path'] = project_path + r'/' + 'models_and_extractors/'
else:
model_config['modextr_path'] = project_path + r'/' + 'models_and_extractors/'
redis_config = {'host': '192.168.1.235', 'port': 6379, 'decode_responses': True, 'password': 'icDb29mLy2s'}
#!/usr/bin/env python
# -*- coding:utf-8 -*-
import redis
from config import redis_config
redis_cli = redis.Redis(**redis_config)
#!/usr/bin/env python
# -*- coding:utf-8 -*-
import json
from urllib.parse import unquote
import tornado.web
import tornado.ioloop
from utils.redis_cli import redis_cli
from predict.kw_predict import KwPredict
from utils.status import code2msg
class BrandKwHandler(tornado.web.RequestHandler):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.predic = KwPredict('validSingle')
self.redis_cli = redis_cli
async def get(self):
target = unquote(self.get_argument('keyword', ''))
brand_set = redis_cli.smembers('brand_set')
if not target:
code = '100001'
res = code2msg(code)
else:
code = 1
res = {}
if len(target) == 1 or target.isdigit() or len(target) >= 50:
score = 0
elif target in brand_set:
score = 1
else:
resp1 = self.predic.predict(target, 'all')
resp2 = self.predic.predict(target, 'brand')
if resp1['result'] == '品牌' and resp2['result']:
score = 0.9
elif resp1['result'] != '品牌' and resp2['result']:
score = 0.7
elif resp1['result'] == '品牌' and not resp2['result']:
score = 0.7
else:
score = 0.1
res['status'] = code
res['score'] = score
self.write(res)
async def post(self):
target = self.request.body
list_data = json.loads(self.request.body)
def gen_app():
return tornado.web.Application(handlers=[(k, v) for k, v in register_tornado_handlers.items()])
register_tornado_handlers = {'/brandkw': BrandKwHandler}
def http_server(port):
app = gen_app()
app.listen(port)
tornado.ioloop.IOLoop.current().start()
if __name__ == '__main__':
port = 50053
http_server(port)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment