-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
53 lines (47 loc) · 1.91 KB
/
app.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
from flask import Flask, render_template, redirect, request, url_for
from inference import predict_breed_transfer, face_detector, dog_detector
import os
import io
from PIL import Image
UPLOAD_FOLDER = './static'
ALLOWED_EXTENSIONS = {'png', 'jpg', 'jpeg'}
app = Flask(__name__)
app.config['SECRET_KEY'] = 'super secret key'
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
def allowed_file(filename):
return '.' in filename and \
filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS
@app.route('/')
def hello():
return render_template("index.html")
@app.route('/', methods = ['POST'])
def submit_data():
if request.method == 'POST':
file = request.files['file']
if file and allowed_file(file.filename):
image = file.read()
predicted_breed = predict_breed_transfer(image_bytes = image)
if face_detector(file):
imag = Image.open(io.BytesIO(image))
imag.save(os.path.join(app.config['UPLOAD_FOLDER'], file.filename))
result_dic = {
'im' : file.filename,
'breed' : predicted_breed
}
return render_template('index.html', human=result_dic)
elif dog_detector(image_bytes = image):
imag = Image.open(io.BytesIO(image))
imag.save(os.path.join(app.config['UPLOAD_FOLDER'], file.filename))
result_dic = {
'im' : file.filename,
'breed' : predicted_breed
}
return render_template('index.html', dog=result_dic)
result_dic = {
'im' : file.filename,
'result' : "We can't detect you as Human or Dog"
}
return render_template('index.html', nodoghuman = result_dic)
return render_template('index.html', nodoghuman = result_dic)
if __name__ == '__main__':
app.run()