-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFlask_Server_App.py
More file actions
172 lines (108 loc) · 4.68 KB
/
Copy pathFlask_Server_App.py
File metadata and controls
172 lines (108 loc) · 4.68 KB
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
from flask import Flask, request, jsonify
from werkzeug.utils import secure_filename
import sys
sys.path.append("../../Model/yolov5/classify/")
sys.path.append("../../Model/yolov5/segment/")
import flask_server_predict
import flask_server_predict_seg
import os
import pathlib
from datetime import datetime
from collections import defaultdict
app = Flask(__name__)
# @app.route("/")
@app.route("/always-care/model/eye", methods=["POST"])
def eye_model():
if request.method == "POST":
save_path = "../client-request-log/"
file = request.files["image_file"]
type = request.form["image_type"]
userId = request.form["userId"]
save_path += str(userId)
if pathlib.Path(save_path).exists() == False:
os.mkdir(save_path)
request_time = datetime.today().strftime("%Y%m%d%H%M%S")
save_path += "/"
save_path += request_time
if pathlib.Path(save_path).exists() == False:
os.mkdir(save_path)
save_path += "/"
save_path += secure_filename(file.filename)
file.save(save_path)
# print(file.filename)
# print(info)
res = prediction(type, save_path)
if res == False:
return False
else:
return res
return False
@app.route("/always-care/model/skin", methods=["POST"])
def skin_model():
if request.method == "POST":
save_path = "../client-request-log/"
file = request.files["image_file"]
type = request.form["image_type"]
userId = request.form["userId"]
save_path += str(userId)
if pathlib.Path(save_path).exists() == False:
os.mkdir(save_path)
request_time = datetime.today().strftime("%Y%m%d%H%M%S")
save_path += "/"
save_path += request_time
if pathlib.Path(save_path).exists() == False:
os.mkdir(save_path)
save_path += "/"
save_path += secure_filename(file.filename)
file.save(save_path)
# print(file.filename)
# print(info)
res = prediction(type, save_path)
if res == False:
return False
else:
return res
return False
def prediction(type, path):
eye_model_path = "../../Model/yolov5/runs/train-cls/only_eye_43/weights/best.pt"
# eye_model_path = "../../Model/yolov5/runs/train-cls/only_eye_44/weights/best.pt"
# eye_model_path = "../../Model/yolov5/runs/train-cls/only_eye_44_3/weights/last.pt" # 사용 x
# eye_model_path = "../../Model/yolov5/runs/train-cls/only_eye_44_5/weights/last.pt" # 사용 x
# eye_model_path = "../../Model/yolov5/runs/train-cls/only_eye_43_2/weights/last.pt"
# eye_model_path = "../../Model/yolov5/runs/train-cls/only_eye_43_3/weights/last.pt"
# eye_model_path = "../../Model/yolov5/runs/train-cls/only_eye_43_4/weights/last.pt"
# skin_model_path = "../../Model/yolov5/runs/train-seg/only_skin_1/weights/last.pt"
# skin_model_path = "../../Model/yolov5/runs/train-seg/only_skin_5/weights/best.pt"
skin_model_path = "../../Model/yolov5/runs/train-seg/only_skin_7_2/weights/last.pt"
if pathlib.Path(path).exists() == False:
return False
if type == "eye":
res = flask_server_predict.main(os.path.abspath(eye_model_path), os.path.abspath(path))
response = {
res[0].split(' ')[0] : res[0].split(' ')[1],
res[1].split(' ')[0] : res[1].split(' ')[1],
res[2].split(' ')[0] : res[2].split(' ')[1],
res[3].split(' ')[0] : res[3].split(' ')[1],
res[4].split(' ')[0] : res[4].split(' ')[1]
}
print(res)
return jsonify(response)
elif type == "skin":
res = flask_server_predict_seg.main(os.path.abspath(skin_model_path), os.path.abspath(path))
response = defaultdict(float)
if len(res) > 0:
for data in res:
disease = data.split(' ')[0]
probability = data.split(' ')[1]
if float(probability) > float(response[disease]):
response[disease] = probability
# else:
# response['empty'] = 1
# print(response)
print(res)
return jsonify(response)
else:
return False
return False
if __name__ == "__main__":
app.run(host="0.0.0.0", port=9000)