amtechinscribe commited on
Commit
941c7e8
·
verified ·
1 Parent(s): 57a0107

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -0
app.py ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from ultralytics import YOLO
2
+ from PIL import Image
3
+ import numpy as np
4
+ import gradio as gr
5
+
6
+ # Load a YOLOv8 model (YOLOv8n is the smallest and fastest version)
7
+ model = YOLO('yolov8n.pt')
8
+
9
+ def detect_objects(image):
10
+ results = model(image)
11
+ rendered_image = results[0].plot() # This returns a numpy array with the bounding boxes drawn
12
+ return Image.fromarray(rendered_image) # Convert the numpy array back to an image
13
+
14
+ # Define the Gradio interface
15
+ interface = gr.Interface(
16
+ fn=detect_objects, # Function to process the input
17
+ inputs=gr.Image(type="pil"), # Input is an image
18
+ outputs=gr.Image(type="pil"), # Output is an image
19
+ title="YOLOv8 Object Detection",
20
+ description="Upload an image to detect objects using YOLOv8."
21
+ )
22
+
23
+ # Launch the Gradio interface
24
+ interface.launch(share=True)