forked from ZakariaR1ad/SpamDetectionApis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
49 lines (37 loc) · 1.21 KB
/
main.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
import email
from flask import Flask, request, jsonify
from flask_restful import Api, Resource,reqparse
from sympy import arg
import sys, os
try:
sys.path.append(os.path.join(os.path.dirname(__file__),"Models"))
from LSTM import LSTM_Model
# from BERT import BERT_Model
except:
raise Exception("Server Error")
app = Flask(__name__)
api = Api(app)
# bert = BERT_Model()
lstm = LSTM_Model()
email_put_args = reqparse.RequestParser()
email_put_args.add_argument("header",type=str,help="Error no Header found")
email_put_args.add_argument("content",type=str,help="Error no Content found")
@app.route('/api',methods=['POST'])
def predict():
# Get the data from the POST request.
data = request.get_json(force=True)
# Make prediction using model loaded from disk as per the data.
try:
#print(data["content"],data)
prediction = lstm.Predict(data["content"])
output = prediction
except:
output = {"error":"Server Error"}
# Take the first value of prediction
return jsonify(output)
@app.route('/api',methods=['GET'])
def hello():
return({"res":"hello"})
# if __name__ == "__main__":
# app.run(host="0.0.0.0",port=8085,debug=True)
# # pass