-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
88 lines (68 loc) · 2.48 KB
/
app.py
File metadata and controls
88 lines (68 loc) · 2.48 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
84
85
86
87
88
# -*- coding: utf-8 -*-
"""
Created on Wed Jun 17 18:44:27 2020
@author: Stone
"""
import os
from flask import Flask, render_template, request, session, flash
from flask_session import Session
from werkzeug.utils import secure_filename
app = Flask(__name__)
app.config["SESSION_PERMANENT"] = False
app.config["SESSION_TYPE"] = "filesystem"
Session(app)
Body = None
Face = None
ALLOWED_EXTENSIONS = {'jpg', 'jpeg', 'gif'}
app.config['UPLOAD_FOLDER'] = "static"
@app.route("/")
def index():
return render_template("index.html")
@app.route("/photos", methods = ["GET","POST"])
def photos(msg = None):
if msg != None:
flash(msg)
return render_template("photos.html")
def allowed_file(filename):
return '.' in filename and \
filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS
@app.route("/check", methods = ["GET" , "POST"])
def check():
if request.method == "POST":
if 'Body_pic' not in request.files:
msg = 'No file part'
return photos(msg)
global Body
Body = request.files['Body_pic']
global Face
Face = request.files['Face_pic']
if Body.filename == '':
msg = 'No selected file in Body'
return photos(msg)
if Face.filename == '':
msg = 'No selected file in Face'
return photos(msg)
if Body and Face:
if not allowed_file(Body.filename):
msg = 'Invalid data type in Body'
return photos(msg)
if not allowed_file(Face.filename):
msg = 'Invalid data type in Face'
return photos(msg)
Bodyname = secure_filename(Face.filename)
Body.save(os.path.join(app.config['UPLOAD_FOLDER'], Bodyname))
Facename = secure_filename(Face.filename)
Face.save(os.path.join(app.config['UPLOAD_FOLDER'], Facename))
return processing()
return photos(None)
else:
return render_template("Error.html")
@app.route("/processing", methods = ["GET","POST"])
def processing():
if request.method == "POST":
return render_template("processing.html", Body = os.path.join(app.config['UPLOAD_FOLDER'], secure_filename(Body.filename)), Face = os.path.join(app.config['UPLOAD_FOLDER'], secure_filename(Face.filename)))
elif Body == None or Face == None:
return render_template("Error.html")
@app.route("/Sample3D")
def Sample3D():
return render_template("Sample3D.html")