-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.py
49 lines (37 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
41
42
43
44
45
46
47
48
49
import flask
from flask import render_template
import os
import facedb
app = flask.Flask(__name__)
here = os.getcwd()
db = None
@app.route("/")
def index():
global db
return render_template('index.html', image_name=db.rand_img_name())
@app.route("/user/<username>")
def user(username):
return render_template('user.html', username=username, img_list = db.pos_faces_for_user(username))
@app.route("/img/<path>")
def images(path):
fullpath = here + "/10kfaces/" + path
resp = flask.make_response(open(fullpath).read())
resp.content_type = "image/jpeg"
return resp
@app.route("/rating", methods=['POST'])
def rating():
global db
r = flask.request
if r.method=='POST':
#print r.form['img_name'], r.form['rating']
img_name = r.form['img_name']
rating = 0
if r.form['rating'] == 'yes':
rating = 1
username = r.form['username']
if username:
db.add_rating(username, img_name, rating)
return "okay"
if __name__ == "__main__":
db = facedb.FaceDB('10kfaces/', 'server.db')
app.run(port=80, host='0.0.0.0', debug=True)