-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
50 lines (38 loc) · 1.45 KB
/
app.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
import os
from flask import Flask, Response, request
from PIL import Image
from predict import get_model, evaluate
app = Flask(__name__)
files_folder = os.path.join(os.getcwd(), "files")
model = get_model()
@app.after_request
def after_request(response):
response.headers.add('Access-Control-Allow-Origin', '*')
response.headers.add('Access-Control-Allow-Headers', 'Content-Type,Authorization')
response.headers.add('Access-Control-Allow-Methods', 'GET,POST')
return response
@app.route('/')
def index():
return Response(open('static/index.html').read(), mimetype="text/html")
@app.route('/anomalyDetection', methods=['POST'])
def anomaly_detection():
image_file = request.files['image']
image_object = Image.open(image_file).convert('L')
return evaluate(model, image_object)
@app.route('/recordingImage', methods=['POST'])
def image():
image_file = request.files['image']
uuid = request.form.get('uuid')
count = request.form.get('count')
image_object = Image.open(image_file).convert('L')
images_folder = os.path.join(files_folder, uuid)
if not os.path.exists(images_folder):
try:
os.mkdir(images_folder)
except:
print("Ignore")
file_name = os.path.join(images_folder, str(count) + ".tif")
image_object.save(file_name)
return "save"
if __name__ == '__main__':
app.run(host="192.168.0.14", port=9000, debug=False, ssl_context=('ssl/server.crt', 'ssl/server.key'))