Blaze-bmm commited on
Commit
91d359a
Β·
1 Parent(s): 552070b

first commit

Browse files
.gitattributes CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ venv/
.gitignore ADDED
@@ -0,0 +1 @@
 
 
1
+ venv/
README.md~ ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Pothole Detection App (Powered by YOLOv8 + Gradio)
2
+
3
+ This is a lightweight web app that uses a custom-trained YOLOv8 model to detect potholes in uploaded images and videos. Built using Gradio, it provides a simple interface for end-users to test pothole detection instantly.
4
+
5
+ ## Features
6
+ - πŸ“· Upload images for pothole detection.
7
+ - πŸŽ₯ Upload short videos for pothole detection.
8
+ - πŸ”Š Beep sound when a pothole is detected (in local mode).
9
+ - 🌐 Can be hosted via platforms like Hugging Face Spaces or locally.
10
+
11
+ ## How to Run Locally
12
+
13
+ ```bash
14
+ git clone https://github.com/Blazious/pothole_detection
15
+ cd pothole_inference
16
+ pip install -r requirements.txt
17
+ python app.py
__pycache__/detect.cpython-310.pyc ADDED
Binary file (1.96 kB). View file
 
app.py ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # app.py
2
+ import gradio as gr
3
+ from detect import detect_image, detect_video
4
+
5
+ def handle_image(img):
6
+ result_path, beep_path = detect_image(img)
7
+ return result_path, beep_path
8
+
9
+ def handle_video(video):
10
+ result_path, beep_path = detect_video(video)
11
+ return result_path, beep_path
12
+
13
+ with gr.Blocks() as demo:
14
+ gr.Markdown("## πŸ•³οΈ Pothole Detector")
15
+
16
+ with gr.Tabs():
17
+ with gr.TabItem("Image Detection"):
18
+ with gr.Row():
19
+ img_input = gr.Image(type="pil", label="Upload Image")
20
+ img_output = gr.Image(label="Detection Result")
21
+ audio_output_img = gr.Audio(label="Detection Beep", type="filepath", visible=True)
22
+ img_input.change(fn=handle_image, inputs=[img_input], outputs=[img_output, audio_output_img])
23
+
24
+ with gr.TabItem("Video Detection"):
25
+ with gr.Row():
26
+ video_input = gr.Video(label="Upload Video")
27
+ video_output = gr.Video(label="Detection Result")
28
+ audio_output_vid = gr.Audio(label="Detection Beep", type="filepath", visible=True)
29
+ video_input.change(fn=handle_video, inputs=[video_input], outputs=[video_output, audio_output_vid])
30
+
31
+ gr.Markdown("""
32
+ ### πŸ” About This Tool
33
+
34
+ - Designed for demonstration and educational purposes
35
+ - AI-generated pothole detection may not be 100% accurate
36
+ - Always verify road conditions with physical inspection
37
+
38
+ ---
39
+
40
+ ⏱️ **Processing Note:**
41
+ Video analysis duration varies depending on the video's length and resolution.
42
+ Typical processing can take **5–6 minutes** as the system carefully analyzes individual frames.
43
+ """)
44
+
45
+ demo.launch()
46
+
47
+
detect.py ADDED
@@ -0,0 +1,75 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # detect.py
2
+ import os
3
+ import cv2
4
+ import torch
5
+ from ultralytics import YOLO
6
+ import tempfile
7
+ from PIL import Image
8
+ import numpy as np
9
+
10
+ # Load model once
11
+ model = YOLO('model/best.pt')
12
+
13
+ # Load beep
14
+ beep_path = os.path.join('media', 'beep.wav')
15
+
16
+ def detect_image(img: Image.Image):
17
+ frame = np.array(img)
18
+
19
+ results = model.predict(source=frame, conf=0.4)
20
+ detections = results[0].boxes
21
+
22
+ detected = False
23
+
24
+ for box in detections:
25
+ cls_id = int(box.cls[0])
26
+ conf = float(box.conf[0])
27
+ x1, y1, x2, y2 = map(int, box.xyxy[0])
28
+ cv2.rectangle(frame, (x1, y1), (x2, y2), (0, 0, 255), 2)
29
+ label = f"Pothole: {conf:.2f}"
30
+ cv2.putText(frame, label, (x1, y1 - 10), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 255, 0), 2)
31
+ detected = True
32
+
33
+ # Save to temp file
34
+ result_path = tempfile.mktemp(suffix=".jpg")
35
+ cv2.imwrite(result_path, frame)
36
+
37
+ return result_path, beep_path if detected else None
38
+
39
+ # detect.py (for videos)
40
+ def detect_video(video_path: str):
41
+ cap = cv2.VideoCapture(video_path)
42
+ fourcc = cv2.VideoWriter_fourcc(*'mp4v')
43
+ out_path = tempfile.mktemp(suffix=".mp4")
44
+ out = None
45
+ detected = False
46
+
47
+ while cap.isOpened():
48
+ ret, frame = cap.read()
49
+ if not ret:
50
+ break
51
+
52
+ results = model.predict(source=frame, conf=0.4)
53
+ boxes = results[0].boxes
54
+
55
+ for box in boxes:
56
+ cls_id = int(box.cls[0])
57
+ conf = float(box.conf[0])
58
+ x1, y1, x2, y2 = map(int, box.xyxy[0])
59
+ cv2.rectangle(frame, (x1, y1), (x2, y2), (0, 0, 255), 2)
60
+ label = f"Pothole: {conf:.2f}"
61
+ cv2.putText(frame, label, (x1, y1 - 10), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 255, 0), 2)
62
+ detected = True
63
+
64
+ if out is None:
65
+ height, width, _ = frame.shape
66
+ out = cv2.VideoWriter(out_path, fourcc, 20.0, (width, height))
67
+
68
+ out.write(frame)
69
+
70
+ cap.release()
71
+ if out:
72
+ out.release()
73
+
74
+ return out_path, beep_path if detected else None
75
+
media/beep.wav ADDED
Binary file (95.6 kB). View file
 
model/best.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:9e9841997f0895771b6f2daa6f25560fc59b00905d7cb0ef7bf2622ed3c36f17
3
+ size 6244387
requirements.txt ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ ultralytics
2
+ gradio
3
+ opencv-python
4
+ numpy
5
+ Pillow
6
+ moviepy