forked from mrecachinas/beer-to-cats
-
Notifications
You must be signed in to change notification settings - Fork 0
/
yolocups.py
72 lines (50 loc) · 2.05 KB
/
yolocups.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import os
from flask import Flask, redirect, render_template, request, url_for, send_from_directory
from werkzeug.utils import secure_filename
from PIL import Image
from skimage import io
from classify_func import classify
app = Flask(__name__)
# This is the path to the upload directory
app.config['UPLOAD_FOLDER'] = 'uploads/'
# These are the extension that we are accepting to be uploaded
app.config['ALLOWED_EXTENSIONS'] = set(['png', 'jpg', 'jpeg', 'gif'])
def allowed_file(filename):
return '.' in filename and filename.rsplit('.', 1)[1] in app.config['ALLOWED_EXTENSIONS']
@app.route('/')
def yolocups():
return render_template('index.html')
@app.route('/uploads', methods=['POST'])
def upload_file():
if request.method == 'POST':
file = request.files['file']
if file and allowed_file(file.filename) and file.filename.split('.')[-1] in app.config['ALLOWED_EXTENSIONS']:
filename = secure_filename(file.filename)
# Work with file here, redirect to a results page with processed image in template
print "Hello"
img = io.imread(file.stream)
new_img = classify(img)
new_img.save(app.config['UPLOAD_FOLDER']+"test-"+filename)
# file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
return redirect(url_for('uploaded_file', filename="test-"+filename))
return redirect(url_for('yolocups'))
@app.route('/show/<filename>')
def uploaded_file(filename):
return render_template('classified.html', filename=filename)
@app.route('/uploads/<filename>')
def send_file(filename):
return send_from_directory(app.config['UPLOAD_FOLDER'], filename)
@app.route('/demo')
def demo():
return render_template('demo.html')
@app.route('/theory')
def theory():
return render_template('theory.html')
@app.route('/yolo')
def yolo():
return redirect("http://www.youtube.com/watch?v=z5Otla5157c", code=302)
@app.errorhandler(404)
def page_not_found(e):
return render_template('index.html'), 404
if __name__ == '__main__':
app.run(debug=True)