add judgeBert & checkBert
Browse files
app.py
CHANGED
|
@@ -127,3 +127,28 @@ def judgePlus(x):
|
|
| 127 |
result.append((result_lstm[i]+result_gru[i]+result_bert[i])/3)
|
| 128 |
|
| 129 |
return (result)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 127 |
result.append((result_lstm[i]+result_gru[i]+result_bert[i])/3)
|
| 128 |
|
| 129 |
return (result)
|
| 130 |
+
|
| 131 |
+
def judgeBert(x):
|
| 132 |
+
|
| 133 |
+
label = ['độc hại', 'cực kì độc hại', 'tục tĩu', 'đe dọa', 'xúc phạm', 'thù ghét cá nhân']
|
| 134 |
+
result = []
|
| 135 |
+
judge_result = []
|
| 136 |
+
|
| 137 |
+
x = ud.normalize('NFKC', x)
|
| 138 |
+
x = word_tokenize(x, format="text")
|
| 139 |
+
|
| 140 |
+
|
| 141 |
+
try:
|
| 142 |
+
bert_pred = BERT_predict(x)
|
| 143 |
+
except:
|
| 144 |
+
bert_pred = [0,0,0,0,0,0]
|
| 145 |
+
|
| 146 |
+
|
| 147 |
+
return_result = 'Result'
|
| 148 |
+
|
| 149 |
+
result_bert = np.round(bert_pred, 2)
|
| 150 |
+
#result_bert = np.round(bert_pred, 2)
|
| 151 |
+
|
| 152 |
+
|
| 153 |
+
|
| 154 |
+
return (result_bert)
|
main.py
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
from flask import Flask, request
|
| 2 |
-
from app import judge, judgePlus
|
| 3 |
from flask_cors import CORS
|
| 4 |
import threading
|
| 5 |
|
|
@@ -30,6 +30,12 @@ def checkPlus():
|
|
| 30 |
result = judgePlus(comment)
|
| 31 |
return result
|
| 32 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
if __name__ == '__main__':
|
| 34 |
|
| 35 |
app.run(debug=False, threaded=True)
|
|
|
|
| 1 |
from flask import Flask, request
|
| 2 |
+
from app import judge, judgePlus, judgeBert
|
| 3 |
from flask_cors import CORS
|
| 4 |
import threading
|
| 5 |
|
|
|
|
| 30 |
result = judgePlus(comment)
|
| 31 |
return result
|
| 32 |
|
| 33 |
+
@app.route("/checkbert", methods=["POST"])
|
| 34 |
+
def checkBert():
|
| 35 |
+
comment = request.json['comment']
|
| 36 |
+
result = judgeBert(comment)
|
| 37 |
+
return result
|
| 38 |
+
|
| 39 |
if __name__ == '__main__':
|
| 40 |
|
| 41 |
app.run(debug=False, threaded=True)
|