File size: 645 Bytes
7b33512
 
 
 
 
af684bb
7b33512
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
from ultralytics import YOLO
from PIL import Image

# Load the trained YOLOv8 model
model = YOLO("best.pt")

# Define the prediction function
def predict(image):
    results = model(image)  # Run YOLOv8 model on the uploaded image
    results_img = results[0].plot()  # Get image with bounding boxes
    return Image.fromarray(results_img)

# Create Gradio interface
interface = gr.Interface(
    fn=predict, 
    inputs=gr.Image(type="pil"), 
    outputs=gr.Image(type="pil"),
    title="Helmet Detection with YOLOv8",
    description="Upload an image to detect helmets."
)

# Launch Gradio app
interface.launch(share=True)