-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapp.py
More file actions
66 lines (56 loc) · 2.3 KB
/
Copy pathapp.py
File metadata and controls
66 lines (56 loc) · 2.3 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
import time
from flask import request, render_template, redirect, Flask
import dclp_tool
import json
import os
import shutil
app = Flask(__name__)
@app.route('/', methods=['GET', 'POST'])
def index():
return redirect('/main_page')
@app.route('/main_page', methods=['GET', 'POST'])
def main_page():
# 统计./static/temp文件夹下的文件夹数量
path = './static/temp'
n = []
if os.path.exists(path):
files = os.listdir(path)
for file in files:
if os.path.isdir(path + '/' + file):
files = os.listdir(path + '/' + file)
n.append(len([file for file in files if file.split('.')[-1] in dclp_tool.file_ext]))
if request.method == 'POST':
# 在./static/temp文件夹下创建一个新的文件夹
path = path + '/' + str(len(n))
os.mkdir(path)
image = request.files.getlist('images')
# 将这些图片保存到本地
for i, img in enumerate(image):
img.save(path + '/' + str(i) + '.' + img.filename.split('.')[-1])
n.append(len(image))
return render_template('main_page.html', images=[], diagnosis=[], case_num=n, time='')
else:
image_id = request.args.get('image_id')
if image_id is not None:
begin_time = time.time()
result = dclp_tool.detect_and_classify(path + '/' + str(image_id))
end_time = time.time()
time_ = 'Time: ' + str(round(end_time - begin_time, 3))
return render_template('main_page.html', images=result['images'], diagnosis=list(result['Diagnosis'].values())[0], case_num=n, time=time_)
else:
return render_template('main_page.html', images=[], diagnosis=[], case_num=n,time='')
@app.route('/app_data', methods=['POST'])
def app_data():
# 清空file文件夹
if os.path.exists('./file'):
shutil.rmtree('./file')
os.mkdir('./file')
length = request.form['length']
# 将这些图片保存到本地
for i in range(int(length)):
img = request.files['image' + str(i)]
img.save('./file/' + img.filename)
result = dclp_tool.detect_and_classify('./file')
return json.dumps(result)
if __name__ == '__main__':
app.run(host='0.0.0.0', port=4000, debug=True)