-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
53 lines (43 loc) · 1.23 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
'''
@Author: your name
@Date: 2020-06-28 14:02:35
LastEditTime: 2021-08-26 15:20:40
LastEditors: Please set LastEditors
@Description: In User Settings Edit
@FilePath: /bookClassification(ToDo)/app.py
'''
from flask import Flask, request
from __init__ import *
from src.ML.models import Models
from src.utils import config
import tensorflow as tf
import json
import keras
# sim = Similarity()
tf.get_default_graph()
graph = tf.get_default_graph()
sess = keras.backend.get_session()
model = Models(model_path=config.root_path + '/model/ml_model/lightgbm', train_model=False)
app = Flask(__name__)
@app.route('/predict', methods=["POST"])
def gen_ans():
# TODO
# 1. 接受request 输入 并返回预测结果
result = {}
title = request.form.get('title')
desc = request.form.get('desc')
if not title:
return u'缺失title参数'
if not desc:
return u'缺失desc参数'
with sess.as_default():
with graph.as_default():
label, score = model.predict(title, desc)
result = {
"label": label,
"proba": str(score)
}
return json.dumps(result, ensure_ascii=False)
# python3 -m flask run
if __name__ == '__main__':
app.run(host='0.0.0.0', port=8890, debug=True)