momelam commited on
Commit
ac2269e
1 Parent(s): 2394b5c

Upload model

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