-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
58 lines (46 loc) · 1.5 KB
/
Copy pathapp.py
File metadata and controls
58 lines (46 loc) · 1.5 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
from flask import Flask
from flask import render_template
from flask import request
from flask import url_for
import os, subprocess
try:
from werkzeug.utils import secure_filename
except:
from werkzeug import secure_filename
app = Flask(__name__)
#app.config['MAX_CONTENT_LENGTH'] = 16 * 1024 * 1024 #파일 업로드 용량 제한 단위:바이트
#필터링
@app.route('/filtering')
def filtering():
result = subprocess.run(['python', 'testinput.py'], capture_output=True, text=True)
return render_template('check.html')
#HTML 렌더링
@app.route('/')
def home_page():
return render_template('home.html')
# 파일 리스트
@app.route('/list')
def list_page():
file_list = os.listdir("./static/results")
if file_list:
images = [f for f in file_list if f.endswith('.jpg')]
html = """<center><a href="/">홈페이지</a><br><br>"""
for image in images:
html += f'<img src="{url_for("static", filename="results/" + image)}" width="300" height="300" alt="Images">'
html += "<br><br>file_list: {}".format(file_list) + "</center>"
return html
#업로드 HTML 렌더링
@app.route('/upload')
def upload_page():
return render_template('upload.html')
#파일 업로드 처리
@app.route('/fileUpload', methods = ['GET', 'POST'])
def upload_file():
if request.method == 'POST':
f = request.files['file']
#저장할 경로 + 파일명
f.save('./uploads/' + secure_filename(f.filename))
return filtering()
#서버 실행
if __name__ == '__main__':
app.run(host='0.0.0.0', port=8080, debug = True)