sovitrath commited on
Commit
419e9e5
1 Parent(s): c6b7813

Updated app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -17
app.py CHANGED
@@ -26,21 +26,20 @@ for i, url in enumerate(file_urls):
26
  model = YOLO('best.pt')
27
  path = [['image_0.jpg'], ['image_1.jpg']]
28
 
29
- def show_preds(image_path, video_path=None):
30
  image = cv2.imread(image_path)
31
- outputs = model.predict(source=image_path, return_outputs=True)
32
- for image_id, result in enumerate(outputs):
33
- print(result['det'])
34
- for i, det in enumerate(result['det']):
35
- print(det)
36
- cv2.rectangle(
37
- image,
38
- (int(det[0]), int(det[1])),
39
- (int(det[2]), int(det[3])),
40
- color=(0, 0, 255),
41
- thickness=2,
42
- lineType=cv2.LINE_AA
43
- )
44
  return cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
45
 
46
  inputs_image = [
@@ -51,8 +50,8 @@ inputs_image = [
51
  outputs_image = [
52
  gr.components.Image(type="numpy", label="Output Image"),
53
  ]
54
- interface = gr.Interface(
55
- fn=show_preds,
56
  inputs=inputs_image,
57
  outputs=outputs_image,
58
  title="Pothole detector",
@@ -60,4 +59,22 @@ interface = gr.Interface(
60
  cache_examples=False,
61
  # live=True,
62
  )
63
- interface.launch(debug=True, enable_queue=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
26
  model = YOLO('best.pt')
27
  path = [['image_0.jpg'], ['image_1.jpg']]
28
 
29
+ def show_preds_image(image_path):
30
  image = cv2.imread(image_path)
31
+ outputs = model.predict(source=image_path)
32
+ results = outputs[0].cpu().numpy()
33
+ for i, det in enumerate(results.boxes.xyxy):
34
+ # print(det.xyxy)
35
+ cv2.rectangle(
36
+ image,
37
+ (int(det[0]), int(det[1])),
38
+ (int(det[2]), int(det[3])),
39
+ color=(0, 0, 255),
40
+ thickness=2,
41
+ lineType=cv2.LINE_AA
42
+ )
 
43
  return cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
44
 
45
  inputs_image = [
 
50
  outputs_image = [
51
  gr.components.Image(type="numpy", label="Output Image"),
52
  ]
53
+ interface_image = gr.Interface(
54
+ fn=show_preds_image,
55
  inputs=inputs_image,
56
  outputs=outputs_image,
57
  title="Pothole detector",
 
59
  cache_examples=False,
60
  # live=True,
61
  )
62
+
63
+ inputs_video = [
64
+ gr.components.Video(type="filepath", label="Input Video"),
65
+
66
+ ]
67
+ outputs_video = [
68
+ gr.components.Video(type="mp4", label="Output Image"),
69
+ ]
70
+ interface_video = gr.Interface(
71
+ fn=show_preds_image,
72
+ inputs=inputs_video,
73
+ outputs=outputs_video,
74
+ title="Pothole detector",
75
+ examples=path,
76
+ cache_examples=False,
77
+ # live=True,
78
+ )
79
+ # interface_image.launch(debug=True, enable_queue=True)
80
+ gr.TabbedInterface([interface_image, interface_video]).launch()