Samp21 commited on
Commit
0c3390c
·
verified ·
1 Parent(s): 484ba5a

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -0
app.py ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ import gradio as gr
3
+ from PIL import Image
4
+
5
+ # Load pre-trained YOLOv5 model from ultralytics
6
+ model = torch.hub.load('ultralytics/yolov5', 'yolov5s')
7
+
8
+ def detect_objects(image):
9
+ # Perform inference
10
+ results = model(image)
11
+ results.render() # updates results.imgs with boxes and labels
12
+ detected_image = Image.fromarray(results.imgs[0])
13
+ return detected_image
14
+
15
+ # Define Gradio interface
16
+ iface = gr.Interface(
17
+ fn=detect_objects,
18
+ inputs=gr.inputs.Image(type="pil"),
19
+ outputs=gr.outputs.Image(type="pil"),
20
+ title="Object Detection with YOLOv5",
21
+ description="Upload an image and get the detected objects with their names."
22
+ )
23
+
24
+ # Launch the interface
25
+ iface.launch()