forked from kylefriedman17/colorblindApp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
67 lines (52 loc) · 2.29 KB
/
app.py
File metadata and controls
67 lines (52 loc) · 2.29 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
import os
from os import path, walk
import compareImages
from flask import Flask, render_template, url_for, request, redirect
app = Flask(__name__)
APP_ROOT = os.path.dirname(os.path.abspath(__file__))
@app.route("/")
def index():
# Renders the index.html file
return render_template("index.html")
@app.route("/upload/", methods=["POST", "GET"])
def upload():
# Sets the target path for the file to be added to
target = os.path.join(APP_ROOT, 'static')
print(target)
# Creates the path in case it doesn't exist
if not os.path.isdir(target):
os.mkdir(target)
# Finding files in the requests, adding them to the target destination with the name as their filename
file = request.files["file"]
destination = "/".join([target, 'input.jpg'])
file.save(destination)
# Use daltonize
os.system("daltonize.py -s -t p static/input.jpg static/output.jpg")
chosen_type = "Protanopia (Missing red cone)"
mse = compareImages.main()
# Renders the uploaded template, passes the file name that was assigned to the uploaded file and the chosen type
return render_template("uploaded.html", chosen_type=chosen_type, input_filename='input.jpg', output_filename='output.jpg', mse=mse)
# Updates the uploaded.html template with the new select value and the updated output image
@app.route("/display/", methods=["POST"])
def display():
type_value = request.form.get("types")
os.system(f"daltonize.py -s -t {type_value} static/input.jpg static/output.jpg")
print(type_value)
if type_value == 'p':
chosen_type = "Protanopia (Missing red cone)"
elif type_value == 'd':
chosen_type = "Deuteranopia (Missing green cone)"
elif type_value == 't':
chosen_type = "Tritanopia (Missing blue cone)"
else:
chosen_type = "Protanopia (Missing red cone)"
mse = compareImages.main()
return render_template("uploaded.html", chosen_type=chosen_type, input_filename='input.jpg', output_filename='output.jpg', mse=mse)
# Fix for the shift refresh issue where static does not update when render_template is used
@app.after_request
def apply_caching(response):
response.headers['Cache-Control'] = 'no-cache, no-store, must-revalidate'
print('cache changes applied')
return response
if __name__ == "__main__":
app.run()