Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import PIL.Image as Image
|
3 |
+
from ultralytics import YOLO
|
4 |
+
|
5 |
+
model = YOLO('yolov8n.pt')
|
6 |
+
|
7 |
+
def predict_image(img, conf_threshold, iou_threshold):
|
8 |
+
|
9 |
+
results = model.predict(
|
10 |
+
source=img,
|
11 |
+
conf=conf_threshold,
|
12 |
+
iou=iou_threshold,
|
13 |
+
show_labels=True,
|
14 |
+
show_conf=True,
|
15 |
+
imgsz=640,
|
16 |
+
)
|
17 |
+
|
18 |
+
for r in results:
|
19 |
+
im_array = r.plot()
|
20 |
+
im = Image.fromarray(im_array[..., ::-1])
|
21 |
+
|
22 |
+
return im
|
23 |
+
|
24 |
+
iface = gr.Interface(
|
25 |
+
fn=predict_image,
|
26 |
+
inputs=[
|
27 |
+
gr.Image(type="pil", label="Upload Image"),
|
28 |
+
gr.Slider(minimum=0, maximum=1, value=0.25, label="Confidence threshold"),
|
29 |
+
gr.Slider(minimum=0, maximum=1, value=0.45, label="IoU threshold"),
|
30 |
+
],
|
31 |
+
outputs=gr.Image(type="pil", label="Result"),
|
32 |
+
title="Ultralytics YOLOv8 Object Detection",
|
33 |
+
description="Upload images for inference. The Ultralytics YOLOv8n model is used by default.",
|
34 |
+
examples=[
|
35 |
+
["bus.jpg", 0.25, 0.45],
|
36 |
+
["zidane.jpg", 0.25, 0.45],
|
37 |
+
],
|
38 |
+
)
|
39 |
+
|
40 |
+
if __name__ == "__main__":
|
41 |
+
iface.launch()
|