├── .gitattributes ├── Procfile ├── README.md ├── app.py ├── requirements.txt ├── static ├── model.h5 └── style.css └── templates ├── index.html └── prediction.html /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /Procfile: -------------------------------------------------------------------------------- 1 | web: gunicorn app:app 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # cat-dog-flask 2 | cat dog neural network implemented into website using flask 3 | 4 | to run: 5 | just clone or download 6 | open directory in cmd 7 | and type 'app.py' 8 | enjoy 9 | -------------------------------------------------------------------------------- /app.py: -------------------------------------------------------------------------------- 1 | from flask import Flask, render_template, request, send_from_directory 2 | import cv2 3 | import keras 4 | from tensorflow.keras.models import Sequential 5 | from tensorflow.keras.layers import Dense, Dropout, Conv2D, MaxPooling2D, BatchNormalization, Flatten 6 | import numpy as np 7 | 8 | model = Sequential() 9 | 10 | model.add(Conv2D(32, (3, 3), activation='relu', input_shape=(128,128,3))) 11 | model.add(BatchNormalization()) 12 | model.add(MaxPooling2D(pool_size=(2, 2))) 13 | model.add(Dropout(0.25)) 14 | 15 | model.add(Conv2D(64, (3, 3), activation='relu')) 16 | model.add(BatchNormalization()) 17 | model.add(MaxPooling2D(pool_size=(2, 2))) 18 | model.add(Dropout(0.25)) 19 | 20 | model.add(Conv2D(128, (3, 3), activation='relu')) 21 | model.add(BatchNormalization()) 22 | model.add(MaxPooling2D(pool_size=(2, 2))) 23 | model.add(Dropout(0.25)) 24 | 25 | model.add(Flatten()) 26 | model.add(Dense(512, activation='relu')) 27 | model.add(BatchNormalization()) 28 | model.add(Dropout(0.5)) 29 | model.add(Dense(2, activation='softmax')) 30 | model.compile(loss='categorical_crossentropy', optimizer='rmsprop', metrics=['accuracy']) 31 | model.load_weights('static/model.h5') 32 | 33 | 34 | COUNT = 0 35 | app = Flask(__name__) 36 | app.config["SEND_FILE_MAX_AGE_DEFAULT"] = 1 37 | 38 | @app.route('/') 39 | def man(): 40 | return render_template('index.html') 41 | 42 | 43 | @app.route('/home', methods=['POST']) 44 | def home(): 45 | global COUNT 46 | img = request.files['image'] 47 | 48 | img.save('static/{}.jpg'.format(COUNT)) 49 | img_arr = cv2.imread('static/{}.jpg'.format(COUNT)) 50 | 51 | img_arr = cv2.resize(img_arr, (128,128)) 52 | img_arr = img_arr / 255.0 53 | img_arr = img_arr.reshape(1, 128,128,3) 54 | prediction = model.predict(img_arr) 55 | 56 | x = round(prediction[0,0], 2) 57 | y = round(prediction[0,1], 2) 58 | preds = np.array([x,y]) 59 | COUNT += 1 60 | return render_template('prediction.html', data=preds) 61 | 62 | 63 | @app.route('/load_img') 64 | def load_img(): 65 | global COUNT 66 | return send_from_directory('static', "{}.jpg".format(COUNT-1)) 67 | 68 | 69 | if __name__ == '__main__': 70 | app.run(debug=True) 71 | 72 | 73 | 74 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | numpy==1.18.1 2 | tensorflow==2.2.0 3 | Keras==2.3.1 4 | Flask==1.1.1 5 | gunicorn==20.0.4 6 | Werkzeug==0.16.0 7 | Jinja2==2.10.1 8 | itsdangerous==1.1.0 9 | MarkupSafe==1.1.1 10 | -------------------------------------------------------------------------------- /static/model.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pawandeep-prog/cat-dog-flask/2c0dd2533758ec757414829eae4323dabd5ea744/static/model.h5 -------------------------------------------------------------------------------- /static/style.css: -------------------------------------------------------------------------------- 1 | h1{ 2 | font-size: 90px; 3 | font-family: cursive; 4 | font-weight: bold; 5 | color: crimson; 6 | } 7 | 8 | img{ 9 | width: 350px; 10 | border: dotted 8px; 11 | border-color: darkgreen; 12 | } 13 | 14 | body{ 15 | background-color: #8be77fc0; 16 | margin : 0px; 17 | } 18 | 19 | h2{ 20 | font-size: 80px; 21 | color: darkred; 22 | font-family: sans-serif; 23 | margin: 0px; 24 | } 25 | 26 | 27 | 28 | .btn { 29 | background: #3DF6A3; 30 | background-image: -webkit-linear-gradient(top, #3DF6A3, #D0C31E); 31 | background-image: -moz-linear-gradient(top, #3DF6A3, #D0C31E); 32 | background-image: -ms-linear-gradient(top, #3DF6A3, #D0C31E); 33 | background-image: -o-linear-gradient(top, #3DF6A3, #D0C31E); 34 | background-image: linear-gradient(to bottom, #3DF6A3, #D0C31E); 35 | -webkit-border-radius: 20px; 36 | -moz-border-radius: 20px; 37 | border-radius: 20px; 38 | color: #FFFFFF; 39 | font-family: Verdana; 40 | font-size: 15px; 41 | font-weight: 100; 42 | padding: 10px; 43 | box-shadow: 1px 1px 20px 0px #000000; 44 | -webkit-box-shadow: 1px 1px 20px 0px #000000; 45 | -moz-box-shadow: 1px 1px 20px 0px #000000; 46 | text-shadow: 1px 1px 20px #000000; 47 | border: solid #337FED 1px; 48 | text-decoration: none; 49 | display: inline-block; 50 | cursor: pointer; 51 | text-align: center; 52 | } 53 | 54 | .btn:hover { 55 | border: solid #89ED33 1px; 56 | background: #CAD01E; 57 | background-image: -webkit-linear-gradient(top, #CAD01E, #F6EC3D); 58 | background-image: -moz-linear-gradient(top, #CAD01E, #F6EC3D); 59 | background-image: -ms-linear-gradient(top, #CAD01E, #F6EC3D); 60 | background-image: -o-linear-gradient(top, #CAD01E, #F6EC3D); 61 | background-image: linear-gradient(to bottom, #CAD01E, #F6EC3D); 62 | -webkit-border-radius: 20px; 63 | -moz-border-radius: 20px; 64 | border-radius: 20px; 65 | text-decoration: none; 66 | } 67 | 68 | 69 | .cont{ 70 | background-color: #c3ca7e; 71 | margin : 0px; 72 | padding:0px; 73 | height: 300px; 74 | padding-top: 100px; 75 | margin-bottom: 50px; 76 | } 77 | 78 | span{ 79 | color: green; 80 | } 81 | -------------------------------------------------------------------------------- /templates/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 |