enemy7 commited on
Commit
5b41e19
·
1 Parent(s): b593ee5

Upload 3 files

Browse files
Files changed (3) hide show
  1. Dockerfile +9 -0
  2. app.py +53 -0
  3. requirements.txt +4 -0
Dockerfile ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.9
2
+
3
+ WORKDIR /app
4
+
5
+ COPY requirements.txt /app/
6
+ RUN pip3 install -r requirements.txt
7
+ COPY . /app
8
+
9
+ CMD flask run -h 0.0.0.0 -p 10000
app.py ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from flask import Flask
2
+ from PIL import Image
3
+ import numpy as np
4
+ import tensorflow as tf
5
+ import requests
6
+ import io
7
+
8
+ # Initialize the Flask application
9
+ app = Flask(__name__)
10
+
11
+ # Load the trained model
12
+ model = tf.keras.models.load_model('./save_model.h5',compile=False)
13
+
14
+ # Route for object detection
15
+ @app.route('/detect-object/<id>', methods=['POST','GET'])
16
+ def detect_pothole(id):
17
+ # Get the image file from the request
18
+ try :
19
+ image_file = io.BytesIO(requests.get(f"https://firebasestorage.googleapis.com/v0/b/miniproj-2f595.appspot.com/o/{id}.jpg?alt=media&token=eca9d563-f526-4d9f-b443-72eb653b30d0").content)
20
+
21
+ print(f"https://firebasestorage.googleapis.com/v0/b/miniproj-2f595.appspot.com/o/{id}.jpg?alt=media&token=eca9d563-f526-4d9f-b443-72eb653b30d0")
22
+
23
+ # Load and preprocess the image
24
+ image = Image.open(image_file)
25
+ image = image.resize((64, 64))
26
+ image = np.array(image)
27
+ image = image / 255.0
28
+ image = np.expand_dims(image, axis=0)
29
+
30
+ # Debug statements
31
+ print('Image shape:', image.shape)
32
+ print('Image data:', image)
33
+
34
+ # Make predictions
35
+ result = model.predict(image)
36
+
37
+ # Convert the prediction to a label
38
+ if result[0][0] == 1:
39
+ prediction = 'pothole'
40
+ else:
41
+ prediction = 'Normal'
42
+
43
+ except :
44
+ prediction = 'error'
45
+
46
+ # Return the prediction as a JSON response
47
+ response = {'prediction': prediction}
48
+
49
+ return response
50
+
51
+ # Run the Flask application
52
+ if __name__ == '__main__':
53
+ app.run()
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ tensorflow
2
+ Flask
3
+ Pillow
4
+ requests