notsahil commited on
Commit
6201f5c
·
verified ·
1 Parent(s): cd1032d

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +44 -0
app.py ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import PIL.Image as Image
3
+
4
+ from ultralytics import ASSETS, YOLO
5
+
6
+ model = YOLO("yolo11n.pt")
7
+
8
+
9
+ def predict_image(img, conf_threshold, iou_threshold):
10
+ """Predicts objects in an image."""
11
+ results = model.predict(
12
+ source=img,
13
+ conf=conf_threshold,
14
+ iou=iou_threshold,
15
+ show_labels=True,
16
+ show_conf=True,
17
+ imgsz=640,
18
+ )
19
+
20
+ for r in results:
21
+ im_array = r.plot()
22
+ im = Image.fromarray(im_array[..., ::-1])
23
+
24
+ return im
25
+
26
+
27
+ iface = gr.Interface(
28
+ fn=predict_image,
29
+ inputs=[
30
+ gr.Image(type="pil", label="Upload Image"),
31
+ gr.Slider(minimum=0, maximum=1, value=0.25, label="Confidence threshold"),
32
+ gr.Slider(minimum=0, maximum=1, value=0.45, label="IoU threshold"),
33
+ ],
34
+ outputs=gr.Image(type="pil", label="Result"),
35
+ title="Image",
36
+ description="Upload images for inference",
37
+ # examples=[
38
+ # [ASSETS / "bus.jpg", 0.25, 0.45],
39
+ # [ASSETS / "zidane.jpg", 0.25, 0.45],
40
+ # ],
41
+ )
42
+
43
+ if __name__ == "__main__":
44
+ iface.launch()