forked from AkiyoshiOkano/zuckerberg-detect-ai
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathweb.py
43 lines (37 loc) · 1.24 KB
/
web.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
# -*- coding: utf-8 -*-
import tensorflow as tf
import multiprocessing as mp
from flask import Flask, render_template, request, redirect, url_for
import numpy as np
from werkzeug import secure_filename
import os
import eval
# 自身の名称を app という名前でインスタンス化する
app = Flask(__name__)
app.config['DEBUG'] = True
# 投稿画像の保存先
UPLOAD_FOLDER = './static/images/default'
# ルーティング。/にアクセス時
@app.route('/')
def index():
return render_template('index.html')
# 画像投稿時のアクション
@app.route('/post', methods=['GET','POST'])
def post():
if request.method == 'POST':
if not request.files['file'].filename == u'':
# アップロードされたファイルを保存
f = request.files['file']
img_path = os.path.join(UPLOAD_FOLDER, secure_filename(f.filename))
f.save(img_path)
# eval.pyへアップロードされた画像を渡す
result = eval.evaluation(img_path, './model2.ckpt')
else:
result = []
return render_template('index.html', result=result)
else:
# エラーなどでリダイレクトしたい場合
return redirect(url_for('index'))
if __name__ == '__main__':
app.debug = True
app.run(host='0.0.0.0')