Vishal47 commited on
Commit
beec8d8
1 Parent(s): 2126077

Upload 9 files

Browse files
Cats_vs_Dogs.model/fingerprint.pb ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:134787d145d753dacf4ca852746b711e7f442c2a8956ba84dd83de85e14a2f60
3
+ size 56
Cats_vs_Dogs.model/keras_metadata.pb ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a5a9283a185b338044e3dcdb2313de9bef6b609d8be8578a8a7576a5b6fb9bd9
3
+ size 23939
Cats_vs_Dogs.model/saved_model.pb ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:184a97c4d95983961884d94fd34261bc41c5dc331e96dd9f1e7a37080a4b423f
3
+ size 201981
Cats_vs_Dogs.model/variables/variables.data-00000-of-00001 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:7a54e9eeeb79d4e0830e2f69be5ed40f1f35246204febefaddde6f449e6fcbfc
3
+ size 2237712
Cats_vs_Dogs.model/variables/variables.index ADDED
Binary file (3 kB). View file
 
app.py ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from flask import Flask, request, render_template, jsonify
2
+ from flask_cors import CORS
3
+ import keras
4
+ import numpy as np
5
+ from keras.preprocessing import image
6
+ import io
7
+
8
+ app = Flask(__name__)
9
+ CORS(app)
10
+
11
+ model = keras.models.load_model('Cats_vs_Dogs.model')
12
+
13
+ @app.route('/')
14
+ def index():
15
+ with open('index.html', 'r') as file:
16
+ html_content = file.read()
17
+ return html_content
18
+
19
+ @app.route('/predict', methods=['POST'])
20
+ def predict():
21
+ imagefile = request.files['imagefile']
22
+
23
+ # Read the image file into memory
24
+ img_stream = imagefile.read()
25
+
26
+ # Convert the image to grayscale and resize
27
+ img = image.load_img(io.BytesIO(img_stream), color_mode='grayscale', target_size=(60, 60))
28
+ img_array = image.img_to_array(img)
29
+ img_array = np.expand_dims(img_array, axis=0)
30
+ img_array /= 255.0
31
+
32
+ prediction = model.predict(img_array)
33
+ predicted_class = "Dog" if prediction[0][1] > prediction[0][0] else "Cat"
34
+
35
+ return jsonify({'prediction': predicted_class})
36
+
37
+ if __name__ == '__main__':
38
+ app.run(debug=True)
index.html ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Image Classifier</title>
5
+ <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-BmbxuPwQa2lc/FVzBcNJ7UAyJxM6wuqIj61tLrc4wSX0szH/Ev+nYRRuWlolflfl" crossorigin="anonymous">
6
+ </head>
7
+ <body>
8
+ <h1 class="text-center">Image Classifier</h1>
9
+
10
+ <form class="p-3 text-center" enctype="multipart/form-data">
11
+ <input class="form-control" type="file" id="imageFile" accept="image/*">
12
+ <button class="btn btn-primary mt-3" type="button" id="predictButton">Predict Image</button>
13
+ </form>
14
+
15
+ <p class="text-center mt-3" id="predictionResult"></p>
16
+
17
+ <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
18
+ <script src="main.js"></script>
19
+ </body>
20
+ </html>
main.js ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ $(document).ready(function() {
2
+ var imageFileInput = document.getElementById('imageFile');
3
+ var predictButton = document.getElementById('predictButton');
4
+ var predictionResult = document.getElementById('predictionResult');
5
+
6
+ predictButton.addEventListener('click', async function() {
7
+ var file = imageFileInput.files[0];
8
+ if (!file) {
9
+ predictionResult.textContent = 'Please select an image.';
10
+ return;
11
+ }
12
+
13
+ var formData = new FormData();
14
+ formData.append('imagefile', file);
15
+
16
+ try {
17
+ var response = await fetch('http://127.0.0.1:5000/predict', {
18
+ method: 'POST',
19
+ body: formData
20
+ });
21
+
22
+ if (response.ok) {
23
+ var prediction = await response.text();
24
+ predictionResult.textContent = 'Prediction: ' + prediction;
25
+ } else {
26
+ var errorMessage = await response.text();
27
+ predictionResult.textContent = 'Error: ' + errorMessage;
28
+ }
29
+ } catch (error) {
30
+ predictionResult.textContent = 'An error occurred.';
31
+ console.error('Error:', error);
32
+ }
33
+ });
34
+ });
requirements.txt ADDED
Binary file (140 Bytes). View file