Spaces:
Sleeping
Sleeping
this app
Browse files
app.py
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from ultralytics import YOLO
|
| 3 |
+
from PIL import Image
|
| 4 |
+
|
| 5 |
+
# Load the trained YOLOv8 model
|
| 6 |
+
model = YOLO(r"C:\Users\yahya\Downloads\best.pt")
|
| 7 |
+
|
| 8 |
+
# Define the prediction function
|
| 9 |
+
def predict(image):
|
| 10 |
+
results = model(image) # Run YOLOv8 model on the uploaded image
|
| 11 |
+
results_img = results[0].plot() # Get image with bounding boxes
|
| 12 |
+
return Image.fromarray(results_img)
|
| 13 |
+
|
| 14 |
+
# Create Gradio interface
|
| 15 |
+
interface = gr.Interface(
|
| 16 |
+
fn=predict,
|
| 17 |
+
inputs=gr.Image(type="pil"),
|
| 18 |
+
outputs=gr.Image(type="pil"),
|
| 19 |
+
title="Helmet Detection with YOLOv8",
|
| 20 |
+
description="Upload an image to detect helmets."
|
| 21 |
+
)
|
| 22 |
+
|
| 23 |
+
# Launch Gradio app
|
| 24 |
+
interface.launch(share=True)
|