-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
100 lines (71 loc) · 3.05 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
from wsgiref import simple_server
from flask import Flask, request, render_template
from flask import Response
import os
from flask_cors import CORS, cross_origin
from prediction_Validation_Insertion import pred_validation
from trainingModel import trainModel
from training_Validation_Insertion import train_validation
import flask_monitoringdashboard as dashboard
from predictFromModel import prediction
os.putenv('LANG', 'en_US.UTF-8')
os.putenv('LC_ALL', 'en_US.UTF-8')
app = Flask(__name__)
dashboard.bind(app)
CORS(app)
@app.route("/", methods=['GET'])
@cross_origin()
def home():
return render_template('index.html')
@app.route("/predict", methods=['POST'])
@cross_origin()
def predictRouteClient():
try:
#this part will be called whenever we are sending a request from postman
if request.json is not None:
path = request.json['filepath']
pred_val = pred_validation(path) #object initialization
pred_val.prediction_validation() #calling the prediction_validation function
pred = prediction(path) #object initialization
# predicting for dataset present in database
path = pred.predictionFromModel()
return Response("Prediction File created at %s!!!" % path)
elif request.form is not None:
#this part will be called whenever we are sending a request (entering file path in web application)
path = request.form['filepath']
pred_val = pred_validation(path) #object initialization
pred_val.prediction_validation() #calling the prediction_validation function
pred = prediction(path) #object initialization
# predicting for dataset present in database
path = pred.predictionFromModel()
return Response("Prediction File created at %s!!!" % path)
except ValueError:
return Response("Error Occurred! %s" %ValueError)
except KeyError:
return Response("Error Occurred! %s" %KeyError)
except Exception as e:
return Response("Error Occurred! %s" %e)
@app.route("/train", methods=['POST'])
@cross_origin()
def trainRouteClient():
try:
if request.json['folderPath'] is not None:
path = request.json['folderPath']
train_valObj = train_validation(path) #object initialization
train_valObj.train_validation()#calling the training_validation function
trainModelObj = trainModel() #object initialization
trainModelObj.trainingModel() #training the model for the files in the table
except ValueError:
return Response("Error Occurred! %s" % ValueError)
except KeyError:
return Response("Error Occurred! %s" % KeyError)
except Exception as e:
return Response("Error Occurred! %s" % e)
return Response("Training successfull!!")
port = int(os.getenv("PORT", 5000))
if __name__ == "__main__":
host = '0.0.0.0'
# port = 5000
httpd = simple_server.make_server(host, port, app)
# print("Serving on %s %d" % (host, port))
httpd.serve_forever()