Skip to content

Commit 6fc094d

Browse files
author
Intesar Haider
committed
initial commit
0 parents  commit 6fc094d

File tree

15 files changed

+823
-0
lines changed

15 files changed

+823
-0
lines changed

.gitignore

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Compiled source #
2+
###################
3+
*.com
4+
*.class
5+
*.dll
6+
*.exe
7+
*.o
8+
*.so
9+
*.pyc
10+
11+
# Packages #
12+
############
13+
# it's better to unpack these files and commit the raw source
14+
# git has its own built in compression methods
15+
*.7z
16+
*.dmg
17+
*.gz
18+
*.iso
19+
*.rar
20+
#*.tar
21+
*.zip
22+
23+
# Logs and databases #
24+
######################
25+
*.log
26+
*.sqlite
27+
28+
# OS generated files #
29+
######################
30+
.DS_Store
31+
ehthumbs.db
32+
Icon
33+
Thumbs.db
34+
.tmtags
35+
.idea
36+
tags
37+
vendor.tags
38+
tmtagsHistory
39+
*.sublime-project
40+
*.sublime-workspace
41+
.bundle
42+
43+
env
44+
models

ModelType.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from enum import Enum
2+
3+
class ModelType(Enum):
4+
car_make = "models/car_make/"
5+
car_model = "models/car_model/"

Procfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
web: gunicorn app:app

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Upload file to predict car from images
2+
======================================
3+
4+
Image classification

app.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#!/usr/bin/python
2+
# -*- coding: utf-8 -*-
3+
4+
import os
5+
from datetime import datetime
6+
from flask import Flask, render_template, jsonify, request
7+
8+
import trained_model as tm
9+
import ModelType
10+
app = Flask(__name__)
11+
app.config.from_object(__name__)
12+
app.config['UPLOAD_FOLDER'] = 'uploads'
13+
14+
ALLOWED_EXTENSIONS = ['jpg', 'jpeg']
15+
16+
carMakeModel, carMakeGraph, carMakeLabel = tm.load_model(ModelType.ModelType.car_make)
17+
carModelModel, carModelGraph, carModelLabel = tm.load_model(ModelType.ModelType.car_model)
18+
19+
@app.route("/")
20+
def index():
21+
return render_template("index.html")
22+
23+
24+
@app.route("/car_make")
25+
def car_make():
26+
return render_template("car_make.html")
27+
28+
29+
@app.route("/car_model")
30+
def car_model():
31+
return render_template("car_model.html")
32+
33+
@app.route('/upload/<string:model_type>', methods=['POST'])
34+
def upload(model_type):
35+
if request.method == 'POST':
36+
file = request.files['file']
37+
if file and allowed_file(file.filename):
38+
now = datetime.now()
39+
filename = os.path.join(app.config['UPLOAD_FOLDER'], "%s.%s" % (now.strftime("%Y-%m-%d-%H-%M-%S-%f"), file.filename.rsplit('.', 1)[1]))
40+
file.save(filename)
41+
42+
if ModelType.ModelType.car_model.name == model_type:
43+
prediction = tm.predict(carModelGraph, carModelModel, filename, carModelLabel)
44+
elif ModelType.ModelType.car_make.name == model_type:
45+
prediction = tm.predict(carMakeGraph, carMakeModel, filename, carMakeLabel)
46+
else:
47+
os.remove(filename)
48+
return jsonify("wrong model type")
49+
50+
os.remove(filename)
51+
52+
return jsonify(prediction)
53+
54+
def allowed_file(filename):
55+
return '.' in filename and filename.rsplit('.', 1)[1] in ALLOWED_EXTENSIONS
56+
57+
if __name__ == "__main__":
58+
app.run(debug=True)

requirements.txt

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
absl-py==0.7.1
2+
astor==0.8.0
3+
Click==7.0
4+
cycler==0.10.0
5+
decorator==4.4.0
6+
Flask==1.1.1
7+
gast==0.2.2
8+
google-pasta==0.1.7
9+
grpcio==1.22.0
10+
gunicorn==19.9.0
11+
h5py==2.9.0
12+
imageio==2.5.0
13+
itsdangerous==1.1.0
14+
Jinja2==2.10.1
15+
Keras==2.2.4
16+
Keras-Applications==1.0.8
17+
Keras-Preprocessing==1.1.0
18+
kiwisolver==1.1.0
19+
Markdown==3.1.1
20+
MarkupSafe==1.1.1
21+
matplotlib==3.1.1
22+
networkx==2.3
23+
numpy==1.16.4
24+
opencv-python==3.3.0.9
25+
Pillow==6.1.0
26+
protobuf==3.9.0
27+
pyparsing==2.4.0
28+
python-dateutil==2.8.0
29+
PyWavelets==1.0.3
30+
PyYAML==5.1.1
31+
scikit-image==0.15.0
32+
scipy==1.3.0
33+
six==1.12.0
34+
tensorboard==1.14.0
35+
tensorflow==1.14.0
36+
tensorflow-estimator==1.14.0
37+
termcolor==1.1.0
38+
Werkzeug==0.15.5
39+
wrapt==1.11.2

static/css/styles.css

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
*{
2+
margin: 0;
3+
padding: 0;
4+
}
5+
6+
html{
7+
min-height: 100%;
8+
position: relative;
9+
10+
}
11+
12+
body{
13+
color: grey;
14+
background-color:#333;
15+
min-height: 600px;
16+
font: 14px/1.3 'Segoe UI',Arial, sans-serif;
17+
}
18+
19+
#dropbox{
20+
border: 1px solid grey;
21+
border-radius: 3px;
22+
position: relative;
23+
margin: 80px auto 90px;
24+
min-height: 290px;
25+
overflow: hidden;
26+
padding-bottom: 40px;
27+
width: 990px;
28+
}
29+
30+
31+
#dropbox .message{
32+
font-size: 11px;
33+
text-align: center;
34+
padding-top: 160px;
35+
display: block;
36+
}
37+
38+
#dropbox:before{
39+
border-radius: 3px 3px 0 0;
40+
}
41+
42+
#dropbox .preview{
43+
width: 245px;
44+
height: 215px;
45+
float: left;
46+
margin: 55px 0 0 60px;
47+
position: relative;
48+
text-align: center;
49+
}
50+
51+
#dropbox .preview img{
52+
max-width: 240px;
53+
max-height: 180px;
54+
border: 3px solid #fff;
55+
display: block;
56+
box-shadow: 0 0 2px #000;
57+
}
58+
59+
#dropbox .imageHolder{
60+
display: inline-block;
61+
position: relative;
62+
}
63+
64+
#dropbox .uploaded{
65+
position: absolute;
66+
top: 0;
67+
left: 0;
68+
height: 100%;
69+
width: 100%;
70+
background: url('../img/done.png') no-repeat center center rgba(255,255,255,0.5);
71+
display: none;
72+
}
73+
74+
#dropbox .preview.done .uploaded{
75+
display: block;
76+
}
77+
78+
#dropbox .progressHolder{
79+
position: absolute;
80+
background-color:#252f38;
81+
height: 12px;
82+
width: 100%;
83+
left: 0;
84+
bottom: 0;
85+
box-shadow: 0 0 2px #000;
86+
}
87+
88+
#dropbox .progress{
89+
background-color:#2586d0;
90+
position: absolute;
91+
height: 100%;
92+
left: 0;
93+
width: 0;
94+
box-shadow: 0 0 1px rgba(255, 255, 255, 0.4) inset;
95+
-moz-transition: 0.25s;
96+
-webkit-transition: 0.25s;
97+
-o-transition: 0.25s;
98+
transition: 0.25s;
99+
}
100+
101+
#dropbox .preview.done .progress{
102+
width: 100% !important;
103+
}

static/img/done.png

3.32 KB
Loading

0 commit comments

Comments
 (0)