File size: 545 Bytes
2763e05
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import gradio as gr
from ultralytics import YOLO
import PIL

model = YOLO("yolov8n.pt")

def predict_image(img):
    results = model.predict(source=img)
    annotated_img = results[0].plot()
    annotated_img = PIL.Image.fromarray(annotated_img[...,::-1])
    
    return annotated_img

gradio_app = gr.Interface(
    fn=predict_image,
    inputs=gr.Image(type="pil"),
    outputs=gr.Image(type="pil"),
    title="Object Detection",
    examples=["dog.webp", "zidane.jpg", "huggingface.png"]
)

if __name__ == "__main__":
    gradio_app.launch()