-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathapi.py
217 lines (168 loc) · 5.06 KB
/
api.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
from flask import Flask, request, send_from_directory, request, jsonify, send_file, redirect, url_for
from flask_cors import CORS, cross_origin
import json
import utils.volatile as util
from logging.config import dictConfig
import os
dictConfig({
'version': 1,
'formatters': {'default': {
'format': '[%(asctime)s] %(levelname)s in %(module)s: %(message)s',
}},
'handlers': {'wsgi': {
'class': 'logging.StreamHandler',
'stream': 'ext://flask.logging.wsgi_errors_stream',
'formatter': 'default'
}},
'root': {
'level': 'INFO',
'handlers': ['wsgi']
}
})
app = Flask(__name__, static_url_path='')
app.config["DEBUG"] = True
cors = CORS(app)
app.config['CORS_HEADERS'] = 'Content-Type'
app.config['Access-Control-Allow-Origin'] = 'http://localhost:3000'
@cross_origin()
@app.route("/InitialData/<timestamp>", methods=["GET"])
def getInitialData(timestamp):
json_file = util.create_original_json()
return send_file(json_file)
@cross_origin()
@app.route("/GenerateDataset", methods=["POST"])
def generateDataset():
json_data = request.data
util.transfer_to_modified(json_data)
resp = jsonify(success=True)
return resp
@cross_origin()
@app.route("/SplitData", methods=["POST"])
def splitDataset():
json_data = request.data
util.transfer_to_split(json_data)
resp = jsonify(success=True)
return resp
@cross_origin()
@app.route("/SendSplit/<timestamp>", methods=["GET"])
def getSplitData(timestamp):
json_file = util.create_train_valid_json()
return send_file(json_file)
@cross_origin()
@app.route("/RandomType", methods=["POST"])
def getRandom():
if request.data == None:
pass
else:
json_data = json.loads(request.data)
folder = json_data["type_of_data"]
percent = int(json_data["percentage"])
util.create_random_batch(folder, percent)
resp = jsonify(success=True)
return resp
@cross_origin()
@app.route("/ManualType", methods=["POST"])
def getManual():
if request.data == None:
pass
else:
json_data = request.data
util.create_manual_batch(json_data)
resp = jsonify(success=True)
return resp
@cross_origin()
@app.route("/GetOrg16/<timestamp>", methods=["GET"])
def getOriginal16(timestamp):
json_file = util.create_org16_json()
return send_file(json_file)
@cross_origin()
@app.route("/GetMod16/<timestamp>", methods=["GET"])
def getModified16(timestamp):
json_file = util.create_mod16_json()
return send_file(json_file)
@app.route('/data/<path:path>')
def send_js(path):
return send_from_directory('data/', path)
@cross_origin()
@app.route("/Undo", methods=["POST"])
def undo():
util.undo_last_change()
resp = jsonify(success=True)
return resp
@cross_origin()
@app.route("/SendTransform16", methods=["POST"])
def apply16():
json_data = request.data
util.apply_16(json_data)
resp = jsonify(success=True)
return resp
@cross_origin()
@app.route("/SendTransformBatch", methods=["POST"])
def applybatch():
json_data = request.data
util.apply_batch(json_data)
resp = jsonify(success=True)
return resp
@app.route("/SendHP", methods=["POST"])
@cross_origin()
def start_train():
json_data = json.loads(request.data.decode('utf-8'))
util.start_training(json_data['data'])
resp = jsonify(success=True)
return resp
@ cross_origin()
@ app.route("/GetLink/<timestamp>", methods=["GET"])
def get_tb_link(timestamp):
json_dict = util.get_tensorboard_link()
return jsonify(json_dict)
@cross_origin()
@app.route("/GetGraphs1/<timestamp>", methods=["GET"])
def get_Graphs1(timestamp):
json_dict = util.get_graphs_1()
return jsonify(json_dict)
@cross_origin()
@app.route("/GetGraphs2/<timestamp>", methods=["GET"])
def get_Graphs2(timestamp):
json_dict = util.get_graphs_2()
return jsonify(json_dict)
@cross_origin()
@app.route("/GetGraphs3/<timestamp>", methods=["GET"])
def get_Graphs3(timestamp):
json_dict = util.get_graphs_3()
return jsonify(json_dict)
@cross_origin()
@app.route("/SendData4", methods=["POST"])
def sendData4():
json_data = request.data
util.get_analysis_info(json_data)
json_file = util.get_graphs_4()
return send_file(json_file)
@cross_origin()
@app.route("/GetGraphs5/<timestamp>", methods=["GET"])
def get_Graphs5(timestamp):
json_dict = util.get_graphs_5()
return jsonify(json_dict)
@cross_origin()
@app.route("/sendfile", methods=["POST"])
def sendfile():
print(request.form, request.files['file'])
image = request.files['file']
path = request.form.get('path')
image.save(path)
resp = jsonify(success=True)
return resp
@cross_origin()
@app.route("/newfolder", methods=["POST"])
def createFolder():
print(request.form)
path = request.form.get('path')
os.mkdir(path)
resp = jsonify(success=True)
return resp
@cross_origin()
@app.route("/GetDataStats/<timestamp>", methods=["GET"])
def get_DataStats(timestamp):
json_dict = util.generate_data_stats()
return jsonify(json_dict)
if __name__ == '__main__':
app.run(debug=True)