-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathapp.py
More file actions
83 lines (63 loc) · 2.66 KB
/
app.py
File metadata and controls
83 lines (63 loc) · 2.66 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# -*- coding: utf-8 -*-
import os, sys
import matplotlib.pyplot as plt
import style_transfer
from flask import Flask, url_for, redirect, render_template, request
import os
import time
import numpy as np
from PIL import Image
app = Flask(__name__)
UPLOAD_FOLDER = 'SSU_PHOTO/static/image/upload'
STATIC_FOLDER = 'SSU_PHOTO/static'
style =""
@app.route("/")
def home():
return render_template("index.html")
@app.route('/about')
def about():
return render_template('about_page.html')
@app.route('/scrath')
def scrath():
return render_template('scrath_page.html')
@app.route('/artist')
def artist():
return render_template('artist_page.html')
@app.route('/artist_page_scc')
def artist_scc():
return render_template('artist_page_scc.html', target = 'image/upload/target.jpg')
@app.route('/gallery')
def gallery():
return render_template('gallery_page.html')
@app.route("/scrath_out", methods=['POST'])
def scrath_upload_file():
file_1 = request.files['file1']
file_2 = request.files['file2']
file_1_name = file_1.filename
file_2_name = file_2.filename
file_1.save(os.path.join(STATIC_FOLDER+ '/'+'image/'+file_1_name))
file_2.save(os.path.join(STATIC_FOLDER+ '/'+'image/'+file_2_name))
file_width, file_height = Image.open(STATIC_FOLDER+ '/'+'image/'+file_1_name).size
return render_template('scrath_page_scc.html', file_width=file_width, file_height=file_height)
@app.route("/success", methods=['POST'])
def upload_file():
a = str(np.random.randint(1, 100))
content = request.files['imageFile0']
style = request.form.get('value')
content.save(os.path.join(UPLOAD_FOLDER + '/' + a + 'content.jpg'))
# load in content and style image
content = style_transfer.load_image(UPLOAD_FOLDER + '/' + a + 'content.jpg')
vgg = style_transfer.model()
# #Resize style to match content, makes code easier
style = style_transfer.load_image(UPLOAD_FOLDER + '/s' + str(style) + '.jpg', shape=content.shape[-2:])
target = style_transfer.stylize(content, style, vgg)
x = style_transfer.im_convert(target)
plt.imsave(UPLOAD_FOLDER + '/' + a + 'target.png', x)
return render_template('artist_page_scc.html', target='image/upload/' + a + 'target.png')
if __name__ == '__main__':
app.run(host="0.0.0.0", port=5000)
# 참고 1) 파일 저장 위치 (FLASK 문법)
# ㄴ templates -html / static : image, css, js
# 2) 홈페이지는 상단에 동그라미 아이콘 클릭시 시작 : 여러명이 실행 시키면 구동 발생 참고
# 3) input size = 400 x 400 이하, 풍경 사진 추천(차이가 확명하게 보임) test
# pip freeze > requirements.txt