-
Notifications
You must be signed in to change notification settings - Fork 83
/
app.py
95 lines (85 loc) · 3.58 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
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
from flask import Flask, render_template,request
from main import pix2depth, portrait_mode, depth2pix
import json
import os
from config import CONFIG
app = Flask(__name__)
app.config['UPLOAD_FOLDER'] = os.path.join('static/uploads')
@app.route("/",methods=['GET', 'POST'])
def main():
if request.method == 'POST':
file = request.files['image']
model_name = request.form['model']
model = CONFIG['pix2depth'][model_name]
input_path = os.path.join(app.config['UPLOAD_FOLDER'], file.filename)
file.save(input_path)
if not development:
result_path = pix2depth(input_path,model)
else:
result_path = str(input_path)
img_left = str(input_path)
img_right = str(result_path)
else:
img_left = os.path.join(app.config['UPLOAD_FOLDER'], 'pix.jpg')
img_right = os.path.join(app.config['UPLOAD_FOLDER'], 'depth.jpg')
return render_template('client/index.html',image_left=img_left,image_right=img_right,options = CONFIG['pix2depth'])
@app.route("/depth",methods=['GET', 'POST'])
def depth():
if request.method == 'POST':
file = request.files['image']
model_name = request.form['model']
model = CONFIG['depth2pix'][model_name]
input_path = os.path.join(app.config['UPLOAD_FOLDER'], file.filename)
file.save(input_path)
if not development:
result_path = depth2pix(input_path,model)
else:
result_path = str(input_path)
img_left = str(input_path)
img_right = str(result_path)
else:
img_left = os.path.join(app.config['UPLOAD_FOLDER'], 'depth.jpg')
img_right = os.path.join(app.config['UPLOAD_FOLDER'], 'pix.jpg')
return render_template('client/depth.html',image_left=img_left,image_right=img_right,options = CONFIG['depth2pix'])
@app.route("/portrait",methods=['GET', 'POST'])
def portrait():
if request.method == 'POST':
file = request.files['image']
model_name = request.form['model']
model = CONFIG['portrait'][model_name]
input_path= os.path.join(app.config['UPLOAD_FOLDER'], file.filename)
file.save(input_path)
# Perform depth conversion
if not development:
result_path = portrait_mode(input_path, model)
else:
result_path = str(input_path)
img_left = str(input_path)
img_right = str(result_path)
else:
img_left = os.path.join(app.config['UPLOAD_FOLDER'], 'pix.jpg')
img_right = os.path.join(app.config['UPLOAD_FOLDER'], 'pix.jpg')
return render_template('client/potrait.html',image_left=img_left,image_right=img_right,options = CONFIG['portrait'])
@app.route("/examples",methods=['GET','POST'])
def example():
epoch = str(22)
if request.method == 'POST':
epoch = request.form['epoch']
epoch = str(min([32, int(epoch)]))
path = 'http://www.cs.virginia.edu/~ks6cq/cyclegan-1/output/cyclegan/exp_rgb2dep/20171202-023330/imgs/'
img = str(0)
print epoch
populate_page = []
image_types = ['input','fake','cyc']
a2b = ['A','B']
for i in range(0,20):
list_of_images=[]
for img_type in image_types:
for j in a2b:
image = path+img_type+j+'_'+epoch+'_'+str(i)+'.jpg'
list_of_images.append(image)
populate_page.append(list_of_images)
return render_template('client/example.html',path = populate_page)
if __name__ == "__main__":
development = CONFIG['development']
app.run(debug=CONFIG['development'], host=CONFIG['host'], port=CONFIG['port'])