File size: 1,006 Bytes
7b33512
 
 
0d4b577
 
 
7b33512
 
af684bb
7b33512
 
 
 
 
 
 
0d4b577
 
 
 
 
 
 
 
 
7b33512
 
 
 
 
37b7ad4
0d4b577
 
7b33512
 
0d4b577
 
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
import gradio as gr
from ultralytics import YOLO
from PIL import Image
import os



# 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)

# Get example images from the images folder
def get_example_images():
    examples = []
    image_folder = "images"
    for filename in os.listdir(image_folder):
        if filename.lower().endswith(('.png', '.jpg', '.jpeg')):
            examples.append(os.path.join(image_folder, filename))
    return examples

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

# Launch the interface
interface.launch(share=True)