Repository navigation
Expand file tree
/
Copy pathupload.py
More file actions
78 lines (67 loc) · 2.41 KB
/
Copy pathupload.py
File metadata and controls
78 lines (67 loc) · 2.41 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
import os
import sqlite3
from flask import Flask, render_template, request, redirect, url_for, send_from_directory, session
from werkzeug import secure_filename
import tensorflow as tf
import multiprocessing as mp
import numpy as np
import facetype
app = Flask(__name__)
UPLOAD_FOLDER = './uploads'
ALLOWED_EXTENSIONS = set(['png', 'jpg', 'gif'])
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
app.config['SECRET_KEY'] = os.urandom(24)
def allowed_file(filename):
return '.' in filename and \
filename.rsplit('.', 1)[1] in ALLOWED_EXTENSIONS
@app.route('/')
def index():
"""HTMLページをレンダリングします."""
return render_template('index.html')
# @app.route('/')
# def index():
# if 'username' in session:
# return render_template('index.html')
# return '''
# <p>ログインしてください</p>
# '''
# @app.route('/login', methods=['GET', 'POST'])
# def login():
# if request.method == 'POST':
# username = request.form['username']
# if username == 'admin':
# session['username'] = request.form['username']
# return redirect(url_for('index'))
# else:
# return '''<p>ユーザー名が違います</p>'''
# return '''
# <form action="" method="post">
# <p><input type="text" name="username">
# <p><input type="submit" value="Login">
# </form>
# '''
# @app.route('/logout')
# def logout():
# session.pop('username', None)
# return redirect(url_for('index'))
@app.route('/send', methods=['GET', 'POST'])
def send():
if request.method == 'POST':
img_file = request.files['img_file']
if img_file and allowed_file(img_file.filename):
filename = secure_filename(img_file.filename)
img_path = os.path.join(app.config['UPLOAD_FOLDER'], filename)
img_file.save(img_path)
img_url = '/uploads/' + filename
result = facetype.evaluation(img_path, '/Users/yuni/FaceTypeClassification/model.ckpt')
return render_template('index.html',result=result)
else:
return ''' <p>許可されていない拡張子です</p> '''
else:
return redirect(url_for('index'))
@app.route('/uploads/<filename>')
def uploaded_file(filename):
return send_from_directory(app.config['UPLOAD_FOLDER'], filename)
if __name__ == '__main__':
app.debug = True
app.run()