from flask import Flask, request from app import judge, judgePlus, judgeBert, tokenize, lstm_predict, gru_predict from phoBERT import BERT_predict from flask_cors import CORS import threading import time app = Flask(__name__) CORS(app) @app.route("/") def hello(): return {"hello":"Deploy success"} @app.route("/test") def test(): return "Test success" @app.route("/test/") def returnText(text): return f'The text is {text}' @app.route("/check", methods=["POST"]) def check(): comment = request.json['comment'] result = judge(comment) return result @app.route("/checkplus", methods=["POST"]) def checkPlus(): comment = request.json['comment'] result = judgePlus(comment) return result @app.route("/checkbert", methods=["POST"]) def checkBert(): comment = request.json['comment'] result = judgeBert(comment) return result @app.route("/check_time") def time(): l10 = [] l100 = [] l200 = [] t_lstm_10 = [] t_lstm_100 = [] t_lstm_200 = [] t_gru_10 = [] t_gru_100 = [] t_gru_200 = [] t_bert_10 = [] t_bert_100 = [] t_bert_200 = [] #LSTM for com in l10: com = tokenize(com) t1 = time.time() lstm_predict(com) t2 = time.time() t = t2-t1 t_lstm_10.append(t) for com in l100: com = tokenize(com) t1 = time.time() lstm_predict(com) t2 = time.time() t = t2-t1 t_lstm_100.append(t) for com in l200: com = tokenize(com) t1 = time.time() lstm_predict(com) t2 = time.time() t = t2-t1 t_lstm_200.append(t) #GRU for com in l10: com = tokenize(com) t1 = time.time() gru_predict(com) t2 = time.time() t = t2-t1 t_gru_10.append(t) for com in l100: com = tokenize(com) t1 = time.time() gru_predict(com) t2 = time.time() t = t2-t1 t_gru_100.append(t) for com in l200: com = tokenize(com) t1 = time.time() gru_predict(com) t2 = time.time() t = t2-t1 t_gru_200.append(t) #BERT for com in l10: com = tokenize(com) t1 = time.time() BERT_predict(com) t2 = time.time() t = t2-t1 t_bert_10.append(t) for com in l100: com = tokenize(com) t1 = time.time() BERT_predict(com) t2 = time.time() t = t2-t1 t_bert_100.append(t) for com in l200: com = tokenize(com) t1 = time.time() BERT_predict(com) t2 = time.time() t = t2-t1 t_bert_200.append(t) return 'ok' if __name__ == '__main__': app.run(debug=False, threaded=True)