-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.py
100 lines (76 loc) · 2.71 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 flask import Flask, render_template, request, redirect, url_for, send_from_directory, abort, make_response, current_app, jsonify
import numpy as np
import cv2
from datetime import datetime
import os
import string
import random
from predict_kao import predict_kao
from predict_PC import predict_PC
import sys
import json
out="UDN_Ver_1.0"
SAVE_DIR = "./images"
if not os.path.isdir(SAVE_DIR):
os.mkdir(SAVE_DIR)
app = Flask(__name__, static_url_path="")
def random_str(n):
return ''.join([random.choice(string.ascii_letters + string.digits) for i in range(n)])
@app.route('/')
def index():
#return render_template('index.html', images=os.listdir(SAVE_DIR)[::-1],out=out)
return render_template('index.html')
@app.route('/images/<path:path>')
def send_js(path):
return send_from_directory(SAVE_DIR, path)
@app.route('/upload', methods=['POST'])
def upload():
if request.files['image']:
# 画像として読み込み
stream = request.files['image'].stream
img_array = np.asarray(bytearray(stream.read()), dtype=np.uint8)
img = cv2.imdecode(img_array, 1)
# 保存
#dt_now = datetime.now().strftime("test") + random_str(5)
dt_now='image'
save_path = os.path.join(SAVE_DIR, dt_now + ".png")
cv2.imwrite(save_path, img)
print("save", save_path)
print("ok----------------")
pk1,pk2,pk3,pk4,pk5,kname,km=predict_kao(save_path)
pp1,pp2,pp3,pp4,pname,pm=predict_PC(save_path)
#return redirect('/')
return render_template('ans.html',kname=kname,pk1=pk1,pk2=pk2,pk3=pk3,pk4=pk4,pk5=pk5,pp1=pp1,km=km,pname=pname,pp2=pp2,pp3=pp3,pp4=pp4,pm=pm)
else:
return render_template('index.html')
#元ans2
'''
@app.route('/upload2', methods=['POST'])
def upload2():
if request.files['image']:
# 画像として読み込み
stream = request.files['image'].stream
img_array = np.asarray(bytearray(stream.read()), dtype=np.uint8)
img = cv2.imdecode(img_array, 1)
# 保存
#dt_now = datetime.now().strftime("test") + random_str(5)
dt_now='image2'
save_path = os.path.join(SAVE_DIR, dt_now + ".png")
cv2.imwrite(save_path, img)
print("save", save_path)
print("ok---------------")
name,pasent=predict2(save_path)
#return redirect('/')
return render_template('ans2.html',name=name,p=pasent)
else:
return render_template('index2.html')
'''
@app.route('/ans', methods=['POST'])
def post():
return render_template('index.html')
@app.route('/re', methods=['POST'])
def post3():
#return render_template('home.html')
return redirect('/')
if __name__ == '__main__':
app.run()