Spaces:
Sleeping
Sleeping
File size: 956 Bytes
82af0f3 f3593a1 82af0f3 64e917c 82af0f3 f3593a1 be12284 e42da1b 82af0f3 f3593a1 e42da1b 26beddf e42da1b 5208152 82af0f3 e42da1b 82af0f3 e42da1b be12284 e42da1b 64e917c f3593a1 82af0f3 be12284 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
import PIL.Image as Image
import gradio as gr
from ultralytics import ASSETS, YOLO
model = YOLO("./best.pt")
def predict_image(img):
# Set your default confidence and IoU thresholds here if needed
conf_threshold = 0.25
iou_threshold = 0.45
results = model.predict(
source=img,
conf=conf_threshold,
iou=iou_threshold,
show_labels=True,
show_conf=True,
imgsz=640,
)
for r in results:
im_array = r.plot()
im = Image.fromarray(im_array[..., ::-1])
return im
iface = gr.Interface(
fn=predict_image,
inputs=[
gr.Image(type="pil", label="Upload Image"),
],
outputs=gr.Image(type="pil", label="Result"),
title="Ultralytics Gradio",
description="Upload images for inference. The Ultralytics YOLOv8n model is used by default.",
examples=[
["1.jpg"],
["2.jpg"],
]
)
if __name__ == '__main__':
iface.launch()
|