-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
60 lines (40 loc) · 1.53 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
51
52
53
54
55
56
57
58
59
60
# Import flask Library
from flask import Flask
from flask import render_template, url_for, redirect, request
"""
Import From Packages
"""
from packages._variables import VARIABLES
from packages._utils import UTILS
# Initialize Flask app
app = Flask(__name__)
# Initialize Packages Liabries
variables = VARIABLES()
utils = UTILS()
app.secret_key = variables.SECRET_KEY
# Home route
@app.route('/', methods=["POST", "GET"])
def index():
if request.method == "POST":
print(request.files['color-img'])
bw_img = request.files['color-img']
# get file, name, fileExtensiion
filename, name, file_extension = utils.getFilenameExtension(
bwImageData=bw_img
)
# define filename
bw_filename = f"techAI_image_colorization_{name}_{variables.SUFFIX_FILENAME}.{file_extension}"
bw_img_buf = utils.imgToBuf(bw_img)
__colored_successfully, __colored_buff_img = utils.startColor(bw_img_buf)
print("__colored_successfully: ", __colored_successfully)
if __colored_successfully:
return {
"status":True,
"bw_img":utils.htmlFormat(bw_img_buf),
"colored_img":utils.htmlFormat(__colored_buff_img),
"filename":bw_filename
}
return render_template('index.html', context={'status': 'false'})
# Run the app
if __name__ == '__main__':
app.run()