|
import gradio as gr
|
|
from ultralytics import YOLO
|
|
from PIL import Image
|
|
import os
|
|
|
|
|
|
|
|
|
|
model = YOLO("best.pt")
|
|
|
|
|
|
def predict(image):
|
|
results = model(image)
|
|
results_img = results[0].plot()
|
|
return Image.fromarray(results_img)
|
|
|
|
|
|
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
|
|
|
|
|
|
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()
|
|
)
|
|
|
|
|
|
interface.launch(share=True) |