1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- from gevent import monkey; monkey.patch_all()
- import os
- from flask import Flask, request, jsonify
- from flask_apscheduler import APScheduler
- from gevent.pywsgi import WSGIServer
- import config
- from hnsw_model import HNSW
- from log_config import LogConfig
- app = Flask(__name__)
- class APS_Config(object):
- SCHEDULER_API_ENABLED = True
- scheduler = APScheduler()
- # 每周定时刷新日志
- @scheduler.task('cron', id='log_reset', week='*', day_of_week='sun', hour='05', minute='00', second='00', timezone='Asia/Shanghai')
- def log_reset_schedule():
- # hm_LogConfig.log_reset()
- os.popen("nohup python restart_server.py 0 > logs/temp_app.log 2>&1 &")
- # hnsw模型数据检索
- @app.route('/retrieve', methods=['GET', 'POST'])
- def retrieve():
- if request.method == 'POST':
- # 获取post数据
- query_vec = request.get_json()
- # HNSW检索
- query_labels = hnsw.retrieve(query_vec)
- return jsonify(query_labels)
- if __name__ == '__main__':
- # 日志采集初始化
- hm_LogConfig = LogConfig(config.retrieval_path, "hnsw_model")
- hm_logger = hm_LogConfig.get_log()
- # HNSW模型初始化
- hnsw = HNSW(hm_logger)
- # 定时更新HNSW模型增/改/删变化
- app.config.from_object(APS_Config())
- scheduler.init_app(app)
- scheduler.start()
- # app.run(host='0.0.0.0',port='8836')
- server = WSGIServer(('0.0.0.0', 8836), app)
- server.serve_forever()
|