Spaces:
Sleeping
Sleeping
Upload 4 files
Browse files- Dockerfile.txt +10 -0
- app.py +67 -0
- best.pt +3 -0
- requirements.txt +6 -0
Dockerfile.txt
ADDED
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
FROM python:3.8-slim
|
2 |
+
|
3 |
+
WORKDIR /app
|
4 |
+
|
5 |
+
COPY requirements.txt requirements.txt
|
6 |
+
RUN pip install -r requirements.txt
|
7 |
+
|
8 |
+
COPY . .
|
9 |
+
|
10 |
+
CMD ["python", "app.py"]
|
app.py
ADDED
@@ -0,0 +1,67 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from flask import Flask, request, jsonify
|
2 |
+
import cv2
|
3 |
+
import numpy as np
|
4 |
+
import torch
|
5 |
+
from yolov5 import YOLOv5
|
6 |
+
|
7 |
+
app = Flask(__name__)
|
8 |
+
|
9 |
+
# Load YOLOv5 model
|
10 |
+
model = YOLOv5('yolov5s.pt') # Replace with your model path
|
11 |
+
|
12 |
+
def detect_number_plate(frame):
|
13 |
+
results = model(frame)
|
14 |
+
detections = results.pandas().xyxy[0]
|
15 |
+
plates = []
|
16 |
+
|
17 |
+
for _, row in detections.iterrows():
|
18 |
+
if row['name'] == 'number_plate': # Adjust class name
|
19 |
+
plates.append({
|
20 |
+
'class': row['name'],
|
21 |
+
'confidence': row['confidence'],
|
22 |
+
'x_min': row['xmin'],
|
23 |
+
'y_min': row['ymin'],
|
24 |
+
'x_max': row['xmax'],
|
25 |
+
'y_max': row['ymax']
|
26 |
+
})
|
27 |
+
|
28 |
+
return plates
|
29 |
+
|
30 |
+
def detect_smoke(frame):
|
31 |
+
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
|
32 |
+
blur = cv2.GaussianBlur(gray, (21, 21), 0)
|
33 |
+
_, thresh = cv2.threshold(blur, 200, 255, cv2.THRESH_BINARY)
|
34 |
+
|
35 |
+
smoke_intensity = np.sum(thresh) / (thresh.shape[0] * thresh.shape[1])
|
36 |
+
smoke_detected = smoke_intensity > 0.1 # Adjust this threshold
|
37 |
+
|
38 |
+
return smoke_detected, smoke_intensity
|
39 |
+
|
40 |
+
def process_frame(frame):
|
41 |
+
plates = detect_number_plate(frame)
|
42 |
+
smoke_detected, smoke_intensity = detect_smoke(frame)
|
43 |
+
return {
|
44 |
+
'smoke_detected': smoke_detected,
|
45 |
+
'smoke_intensity': smoke_intensity,
|
46 |
+
'number_plates': plates
|
47 |
+
}
|
48 |
+
|
49 |
+
@app.route('/upload', methods=['POST'])
|
50 |
+
def upload_file():
|
51 |
+
if 'file' not in request.files:
|
52 |
+
return jsonify({'error': 'No file part'}), 400
|
53 |
+
|
54 |
+
file = request.files['file']
|
55 |
+
|
56 |
+
if file.filename == '':
|
57 |
+
return jsonify({'error': 'No selected file'}), 400
|
58 |
+
|
59 |
+
if file:
|
60 |
+
in_memory_file = file.read()
|
61 |
+
np_arr = np.frombuffer(in_memory_file, np.uint8)
|
62 |
+
frame = cv2.imdecode(np_arr, cv2.IMREAD_COLOR)
|
63 |
+
results = process_frame(frame)
|
64 |
+
return jsonify(results)
|
65 |
+
|
66 |
+
if __name__ == '__main__':
|
67 |
+
app.run(port=5000, debug=True)
|
best.pt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:9af13581e91c59e8e2f16ccd179d2f7dbf1cfe16f0e2a6495118dffb9adf0268
|
3 |
+
size 14449320
|
requirements.txt
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
flask
|
2 |
+
opencv-python-headless
|
3 |
+
numpy
|
4 |
+
torch
|
5 |
+
torchvision
|
6 |
+
yolov5
|