Spaces:
Runtime error
Runtime error
stphtan94117
commited on
Commit
·
52984a4
1
Parent(s):
12a0fbc
Update app.py
Browse files
app.py
CHANGED
@@ -2,9 +2,9 @@ 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://i.imgur.com/wgZzKIk.jpg',
|
10 |
'https://i.imgur.com/TvIo0Nq.jpg'
|
@@ -27,27 +27,20 @@ for i, url in enumerate(file_urls):
|
|
27 |
file_urls[i],
|
28 |
f"image_{i}.jpg"
|
29 |
)
|
30 |
-
|
31 |
model = YOLO('crack.pt')
|
32 |
path = [['image_0.jpg'], ['image_1.jpg']]
|
33 |
video_path = [['video.mp4']]
|
34 |
-
|
35 |
-
def show_preds_image(
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
(int(det[2]), int(det[3])),
|
45 |
-
color=(0, 0, 255),
|
46 |
-
thickness=2,
|
47 |
-
lineType=cv2.LINE_AA
|
48 |
-
)
|
49 |
-
return cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
|
50 |
-
|
51 |
inputs_image = [
|
52 |
gr.components.Image(type="filepath", label="Input Image"),
|
53 |
]
|
@@ -62,41 +55,7 @@ interface_image = gr.Interface(
|
|
62 |
examples=path,
|
63 |
cache_examples=False,
|
64 |
)
|
65 |
-
|
66 |
-
# def show_preds_video(video_path):
|
67 |
-
# cap = cv2.VideoCapture(video_path)
|
68 |
-
# while(cap.isOpened()):
|
69 |
-
# ret, frame = cap.read()
|
70 |
-
# if ret:
|
71 |
-
# frame_copy = frame.copy()
|
72 |
-
# outputs = model.predict(source=frame)
|
73 |
-
# results = outputs[0].cpu().numpy()
|
74 |
-
# for i, det in enumerate(results.boxes.xyxy):
|
75 |
-
# cv2.rectangle(
|
76 |
-
# frame_copy,
|
77 |
-
# (int(det[0]), int(det[1])),
|
78 |
-
# (int(det[2]), int(det[3])),
|
79 |
-
# color=(0, 0, 255),
|
80 |
-
# thickness=2,
|
81 |
-
# lineType=cv2.LINE_AA
|
82 |
-
# )
|
83 |
-
# yield cv2.cvtColor(frame_copy, cv2.COLOR_BGR2RGB)
|
84 |
-
|
85 |
-
# inputs_video = [
|
86 |
-
# gr.components.Video(type="filepath", label="Input Video"),
|
87 |
-
|
88 |
-
# ]
|
89 |
-
# outputs_video = [
|
90 |
-
# gr.components.Image(type="numpy", label="Output Image"),
|
91 |
-
# ]
|
92 |
-
# interface_video = gr.Interface(
|
93 |
-
# fn=show_preds_video,
|
94 |
-
# inputs=inputs_video,
|
95 |
-
# outputs=outputs_video,
|
96 |
-
# title="Pothole detector",
|
97 |
-
# examples=video_path,
|
98 |
-
# cache_examples=False,
|
99 |
-
# )
|
100 |
|
101 |
gr.TabbedInterface(
|
102 |
[interface_image],
|
|
|
2 |
import cv2
|
3 |
import requests
|
4 |
import os
|
|
|
5 |
from ultralytics import YOLO
|
6 |
|
7 |
+
# ------
|
8 |
file_urls = [
|
9 |
'https://i.imgur.com/wgZzKIk.jpg',
|
10 |
'https://i.imgur.com/TvIo0Nq.jpg'
|
|
|
27 |
file_urls[i],
|
28 |
f"image_{i}.jpg"
|
29 |
)
|
30 |
+
# ------
|
31 |
model = YOLO('crack.pt')
|
32 |
path = [['image_0.jpg'], ['image_1.jpg']]
|
33 |
video_path = [['video.mp4']]
|
34 |
+
# ------
|
35 |
+
def show_preds_image(source):
|
36 |
+
global model
|
37 |
+
res = model(source, conf=.5, iou=.5)
|
38 |
+
res_plotted = res[0].plot()
|
39 |
+
# converting BGR to RGB
|
40 |
+
result = cv2.cvtColor(res_plotted, cv2.COLOR_BGR2RGB)
|
41 |
+
return result
|
42 |
+
|
43 |
+
# ------
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
44 |
inputs_image = [
|
45 |
gr.components.Image(type="filepath", label="Input Image"),
|
46 |
]
|
|
|
55 |
examples=path,
|
56 |
cache_examples=False,
|
57 |
)
|
58 |
+
# ------
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
59 |
|
60 |
gr.TabbedInterface(
|
61 |
[interface_image],
|