File size: 549 Bytes
eecc4a2
 
7c0e86c
 
f8903f8
 
eecc4a2
f8903f8
eecc4a2
f8903f8
 
 
eecc4a2
 
f8903f8
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
from ultralytics import YOLO
from PIL import Image
import gradio as gr

# Load model directly from file in the Space
detection_model = YOLO("best.pt")

# Prediction function
def predict(pilimg):
    results = detection_model.predict(pilimg, conf=0.5, iou=0.6)
    img_bgr = results[0].plot()
    out_pilimg = Image.fromarray(img_bgr[..., ::-1])  # Convert BGR to RGB
    return out_pilimg

# Gradio interface
gr.Interface(
    fn=predict,
    inputs=gr.Image(type="pil"),
    outputs=gr.Image(type="pil"),
    title="Mask Detection Demo"
).launch()