Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -59,7 +59,7 @@ def process_video(video_path):
|
|
59 |
while cap.isOpened():
|
60 |
ret, frame = cap.read()
|
61 |
if not ret:
|
62 |
-
break
|
63 |
|
64 |
start_time = time.time()
|
65 |
|
@@ -109,15 +109,6 @@ def process_image(image):
|
|
109 |
return Image.fromarray(img)
|
110 |
|
111 |
|
112 |
-
def use_example_image():
|
113 |
-
# Function to load the example image
|
114 |
-
example_path = "pexels-hikaique-109919.jpg"
|
115 |
-
if os.path.exists(example_path):
|
116 |
-
return Image.open(example_path)
|
117 |
-
else:
|
118 |
-
print(f"Warning: Example image not found at {example_path}")
|
119 |
-
return None
|
120 |
-
|
121 |
css = """
|
122 |
#title {
|
123 |
text-align: center;
|
@@ -155,11 +146,6 @@ css = """
|
|
155 |
border: none;
|
156 |
}
|
157 |
|
158 |
-
#example-btn {
|
159 |
-
background-color: #27AE60;
|
160 |
-
border: none;
|
161 |
-
}
|
162 |
-
|
163 |
.output-container {
|
164 |
margin-top: 1.5rem;
|
165 |
border: 2px dashed #3498DB;
|
@@ -207,68 +193,47 @@ with gr.Blocks(css=css, title="Real-Time YOLOv5 Video & Image Object Detection")
|
|
207 |
)
|
208 |
|
209 |
with gr.TabItem("Image Detection", elem_classes="tab-item"):
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
inputs=None,
|
248 |
-
outputs=image_input
|
249 |
-
)
|
250 |
-
|
251 |
-
clear_button.click(
|
252 |
-
fn=lambda: None,
|
253 |
-
inputs=None,
|
254 |
-
outputs=image_output
|
255 |
-
)
|
256 |
-
|
257 |
-
example_button.click(
|
258 |
-
fn=use_example_image,
|
259 |
-
inputs=None,
|
260 |
-
outputs=image_input
|
261 |
-
)
|
262 |
-
|
263 |
-
submit_button.click(
|
264 |
-
fn=process_image,
|
265 |
-
inputs=image_input,
|
266 |
-
outputs=image_output
|
267 |
-
)
|
268 |
|
269 |
gr.Markdown("""
|
270 |
### Powered by YOLOv5.
|
271 |
This application allows real-time object detection using the YOLOv5 model.
|
272 |
""", elem_classes="footer")
|
273 |
|
274 |
-
demo.launch()
|
|
|
59 |
while cap.isOpened():
|
60 |
ret, frame = cap.read()
|
61 |
if not ret:
|
62 |
+
break
|
63 |
|
64 |
start_time = time.time()
|
65 |
|
|
|
109 |
return Image.fromarray(img)
|
110 |
|
111 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
112 |
css = """
|
113 |
#title {
|
114 |
text-align: center;
|
|
|
146 |
border: none;
|
147 |
}
|
148 |
|
|
|
|
|
|
|
|
|
|
|
149 |
.output-container {
|
150 |
margin-top: 1.5rem;
|
151 |
border: 2px dashed #3498DB;
|
|
|
193 |
)
|
194 |
|
195 |
with gr.TabItem("Image Detection", elem_classes="tab-item"):
|
196 |
+
with gr.Row():
|
197 |
+
image_input = gr.Image(
|
198 |
+
type="pil",
|
199 |
+
label="Upload Image",
|
200 |
+
interactive=True
|
201 |
+
)
|
202 |
+
|
203 |
+
with gr.Row(elem_classes="button-row"): # Move button row here just below image_input
|
204 |
+
clear_button = gr.Button(
|
205 |
+
"Clear",
|
206 |
+
variant="secondary",
|
207 |
+
elem_id="clear-btn"
|
208 |
+
)
|
209 |
+
submit_button = gr.Button(
|
210 |
+
"Detect Objects",
|
211 |
+
variant="primary",
|
212 |
+
elem_id="submit-btn"
|
213 |
+
)
|
214 |
+
|
215 |
+
# Define image_output below input and buttons
|
216 |
+
image_output = gr.Image(
|
217 |
+
label="Detected Objects",
|
218 |
+
elem_id="image-output"
|
219 |
+
)
|
220 |
+
|
221 |
+
clear_button.click(
|
222 |
+
fn=lambda: None,
|
223 |
+
inputs=None,
|
224 |
+
outputs=image_output
|
225 |
+
)
|
226 |
+
|
227 |
+
submit_button.click(
|
228 |
+
fn=process_image,
|
229 |
+
inputs=image_input,
|
230 |
+
outputs=image_output
|
231 |
+
)
|
232 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
233 |
|
234 |
gr.Markdown("""
|
235 |
### Powered by YOLOv5.
|
236 |
This application allows real-time object detection using the YOLOv5 model.
|
237 |
""", elem_classes="footer")
|
238 |
|
239 |
+
demo.launch()
|