-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
61 lines (45 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
61
from flask import Flask, render_template, request
from flask_socketio import SocketIO, send, emit
#import logging
import os
import numpy as np
import cv2
from artsfer import artsfer
import os
from PIL import Image
'''log = logging.getLogger('werkzeug')
log.setLevel(logging.ERROR)'''
UPLOAD_FOLDER = '/upload'
app = Flask(__name__)
socketio = SocketIO(app)
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
@app.after_request
def add_header(r):
"""
Add headers to both force latest IE rendering engine or Chrome Frame,
and also to cache the rendered page for 10 minutes.
"""
r.headers["Cache-Control"] = "no-cache, no-store, must-revalidate"
r.headers["Pragma"] = "no-cache"
r.headers["Expires"] = "0"
r.headers['Cache-Control'] = 'public, max-age=0'
return r
@app.route('/', methods=['GET'])
def home():
return render_template('index.html')
@socketio.on('upload')
def handle_message(data):
print('Upload arrived')
epochs = data['epochs']
contentImageStr = data['contentImage']
styleImageStr = data['styleImage']
contentImage = cv2.imdecode(np.fromstring(
contentImageStr, np.uint8), cv2.IMREAD_UNCHANGED)
contentImage = cv2.cvtColor(contentImage, cv2.COLOR_BGR2RGB)
styleImage = cv2.imdecode(np.fromstring(
styleImageStr, np.uint8), cv2.IMREAD_UNCHANGED)
styleImage = cv2.cvtColor(styleImage, cv2.COLOR_BGR2RGB)
artsfer(contentImage, styleImage, epochs, emit,
os.path.join(app.root_path, 'static/results'))
if __name__ == '__main__':
socketio.run(app)