NightPrince commited on
Commit
7b33512
·
verified ·
1 Parent(s): ff58e9c
Files changed (1) hide show
  1. app.py +24 -0
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)