-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.py
51 lines (37 loc) · 1.35 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
from flask import Flask, render_template, request, Response, send_from_directory
import os
import tensorflow as tf
from PIL import Image
import numpy as np
from image_preprocessor import preprocess, denormalize
from auto_painter import load_auto_painter_model, generate_image
# If you want to use GPU, Comment out this line.
os.environ["CUDA_VISIBLE_DEVICES"]="-1"
model = load_auto_painter_model()
app = Flask(__name__, template_folder="./templates/",
static_url_path="/images", static_folder="images")
@app.route("/")
def index():
return render_template('index.html')
@app.route("/healthz", methods=['GET'])
def healthCheck():
return "", 200
@app.route("/images", methods=['POST'])
def get_result():
if request.method == "POST":
width, height = 512, 512
try:
source = request.files['source'].read()
adjusted_image = preprocess(source, width, height)
image = denormalize(adjusted_image)
result = generate_image(model, adjusted_image)
image = Image.fromarray(result)
image_path = './images/'
filename = 'result_image.png'
image.save(image_path + filename)
return send_from_directory(image_path, filename, as_attachment=True)
except Exception as e:
print("error : %s" % e)
return Response("fail", status=400)
if __name__ == '__main__':
app.run(host='0.0.0.0', port='80')