skylord commited on
Commit
c6f75b2
·
1 Parent(s): eb29fd8

Upload 3 files

Browse files
Files changed (3) hide show
  1. app.py +59 -0
  2. best.pt +3 -0
  3. requirements.txt +3 -0
app.py ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import cv2
3
+ import requests
4
+ import os
5
+
6
+ from ultralytics import YOLO
7
+
8
+ model = YOLO('best_gd.pt')
9
+ image_paths = ['pothole_example.jpg', 'pothole_screenshot.png']
10
+
11
+ def show_preds_image(image):
12
+ # Save the uploaded image temporarily
13
+ image_path = "uploaded_image.jpg"
14
+ cv2.imwrite(image_path, image[:, :, ::-1]) # Convert BGR to RGB and save the image
15
+
16
+ image = cv2.imread(image_path)
17
+ outputs = model.predict(source=image_path)
18
+ #print("output>>>>>>>>>>>>>>>>>>>>>>>>", outputs)
19
+ results = outputs[0].boxes.xyxy.cpu().numpy()
20
+ for det in results:
21
+ x1, y1, x2, y2 = det[:4]
22
+ label = "Pothole"
23
+ cv2.rectangle(
24
+ image,
25
+ (int(x1), int(y1)),
26
+ (int(x2), int(y2)),
27
+ color=(0, 0, 255),
28
+ thickness=2,
29
+ lineType=cv2.LINE_AA,
30
+ )
31
+ cv2.putText(
32
+ image,
33
+ label,
34
+ (int(x1), int(y1) - 10),
35
+ cv2.FONT_HERSHEY_SIMPLEX,
36
+ 0.9,
37
+ (0, 0, 255),
38
+ 2,
39
+ cv2.LINE_AA,
40
+ )
41
+ os.remove(image_path) # Remove the temporary image file
42
+ return cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
43
+
44
+ inputs_image = [
45
+ gr.inputs.Image(label="Upload Image"),
46
+ ]
47
+ outputs_image = [
48
+ gr.outputs.Image(type="numpy"),
49
+ ]
50
+ interface_image = gr.Interface(
51
+ fn=show_preds_image,
52
+ inputs=inputs_image,
53
+ outputs=outputs_image,
54
+ title="Pothole detector",
55
+ examples=[],
56
+ cache_examples=False,
57
+ )
58
+
59
+ interface_image.launch()
best.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b5840aec4869c6891ac3d9262fc03e930d87af04f32ec077c1c50874b21cba65
3
+ size 52033238
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ opencv-python
2
+ omegaconf
3
+ ultralytics