avanish07 commited on
Commit
25aea8f
1 Parent(s): 05e0276

Upload 4 files

Browse files
Files changed (4) hide show
  1. app.py +46 -0
  2. best.pt +3 -0
  3. pothole_example.jpg +0 -0
  4. pothole_screenshot.png +0 -0
app.py ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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.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
+ results = outputs[0].cpu().numpy()
19
+ for i, det in enumerate(results.boxes.xyxy):
20
+ cv2.rectangle(
21
+ image,
22
+ (int(det[0]), int(det[1])),
23
+ (int(det[2]), int(det[3])),
24
+ color=(0, 0, 255),
25
+ thickness=2,
26
+ lineType=cv2.LINE_AA
27
+ )
28
+ os.remove(image_path) # Remove the temporary image file
29
+ return cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
30
+
31
+ inputs_image = [
32
+ gr.inputs.Image(label="Upload Image"),
33
+ ]
34
+ outputs_image = [
35
+ gr.outputs.Image(type="numpy"),
36
+ ]
37
+ interface_image = gr.Interface(
38
+ fn=show_preds_image,
39
+ inputs=inputs_image,
40
+ outputs=outputs_image,
41
+ title="Pothole detector",
42
+ examples=[],
43
+ cache_examples=False,
44
+ )
45
+
46
+ interface_image.launch()
best.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ce9a23590d666fcca004d3a2330f3e30b229bbe9df0dbf4b0fd390c20fbe67fe
3
+ size 6233272
pothole_example.jpg ADDED
pothole_screenshot.png ADDED