-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.py
40 lines (32 loc) · 1.03 KB
/
server.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
#!/usr/bin/env python3
# coding:utf-8
from flask import Flask, render_template, request
from werkzeug import secure_filename
from classifier import otaku_classifier
import os
app = Flask(__name__)
form_name = 'img'
# ブラウザ用
@app.route('/')
def index():
return render_template('index.html', name=form_name)
# imgフォームに画像をセットしてPOST
@app.route('/post', methods=['GET', 'POST'])
def post():
if request.method != 'POST':
return "error: POST only\n"
if form_name not in request.files:
return "error: Set image to 'img' form\n"
img = request.files[form_name]
if not img.filename:
return "error: Set image to 'img' form\n"
path = os.path.join('images', secure_filename(img.filename))
img.save(path)
return 'yes' if is_otaku(path) else 'no'
# 判別機
def is_otaku(path):
# オタク識別器を通してオタクか判定
return otaku_classifier(path)
if __name__ == '__main__':
app.debug = os.getenv('OTAKU_DEBUG', False)
app.run(host='0.0.0.0')