momelam commited on
Commit
e178e5d
1 Parent(s): bcd706c

Upload model

Browse files
Files changed (2) hide show
  1. app.py +72 -0
  2. best.pt +3 -0
app.py ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ def predict_label(img_path ):
2
+
3
+ results = model(img_path)
4
+ return map[results[0].probs.data.argmax().item()]
5
+
6
+
7
+ import gradio as gr
8
+ import cv2
9
+ import requests
10
+ import os
11
+
12
+ from ultralytics import YOLO
13
+
14
+ file_urls = [
15
+ 'https://www.dropbox.com/s/b5g97xo901zb3ds/pothole_example.jpg?dl=1',
16
+ 'https://www.dropbox.com/s/86uxlxxlm1iaexa/pothole_screenshot.png?dl=1',
17
+ 'https://www.dropbox.com/s/7sjfwncffg8xej2/video_7.mp4?dl=1'
18
+ ]
19
+
20
+
21
+ def download_file(url, save_name):
22
+ url = url
23
+ if not os.path.exists(save_name):
24
+ file = requests.get(url)
25
+ open(save_name, 'wb').write(file.content)
26
+
27
+
28
+ for i, url in enumerate(file_urls):
29
+ if 'mp4' in file_urls[i]:
30
+ download_file(
31
+ file_urls[i],
32
+ f"video.mp4"
33
+ )
34
+ else:
35
+ download_file(
36
+ file_urls[i],
37
+ f"image_{i}.jpg"
38
+ )
39
+ model = YOLO('best.pt')
40
+ path = [['image_0.jpg'], ['image_1.jpg']]
41
+ video_path = [['video.mp4']]
42
+
43
+
44
+ def show_preds_image(image_path):
45
+ image = cv2.imread(image_path)
46
+ outputs = model.predict(source=image_path)
47
+ results = outputs[0].cpu().numpy()
48
+ for i, det in enumerate(results.boxes.xyxy):
49
+ cv2.rectangle(
50
+ image,
51
+ (int(det[0]), int(det[1])),
52
+ (int(det[2]), int(det[3])),
53
+ color=(0, 0, 255),
54
+ thickness=2,
55
+ lineType=cv2.LINE_AA
56
+ )
57
+ return cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
58
+
59
+
60
+ inputs_image = [
61
+ gr.components.Image(type="filepath", label="Input Image"),
62
+ ]
63
+ outputs_image = [
64
+ gr.components.Image(type="numpy", label="Output Image"),
65
+ ]
66
+ interface_image = gr.Interface(
67
+ fn=show_preds_image,
68
+ inputs=inputs_image,
69
+ outputs=outputs_image,
70
+ title="Pothole detector",
71
+ examples=path,
72
+ cache_examples=False,
best.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d8cdb33cf67cc48d1cdeb5aa80a8d2bc58f85b02609ec9b13cbd4491f4fa133b
3
+ size 3056513