20065320rp commited on
Commit
55d5ba5
1 Parent(s): 0407f0a

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +68 -0
app.py ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import numpy as np
3
+
4
+ from ultralyticsplus import YOLO, render_result
5
+ import cv2
6
+ from PIL import Image
7
+
8
+ from cv2 import imshow
9
+ from cv2 import imwrite
10
+
11
+ #image=[gr.Image(label="Input Image", source="webcam")
12
+
13
+
14
+ def PPE(image):
15
+ # load model
16
+ #model = YOLO('keremberke/yolov8m-protective-equipment-detection')
17
+ model = YOLO('keremberke/yolov8m-hard-hat-detection')
18
+ # set model parameters
19
+ model.overrides['conf'] = 0.25 # NMS confidence threshold
20
+ model.overrides['iou'] = 0.45 # NMS IoU threshold
21
+ model.overrides['agnostic_nms'] = False # NMS class-agnostic
22
+ model.overrides['max_det'] = 1000 # maximum number of detections per image
23
+
24
+
25
+
26
+ # perform inference
27
+ results = model.predict(image)
28
+
29
+ # observe results
30
+ print(results[0].boxes)
31
+ render = render_result(model=model, image=image, result=results[0])
32
+ render.show()
33
+
34
+ return render
35
+
36
+
37
+ #demo = gr.Interface(
38
+ # PPE,
39
+ # gr.Image(source="webcam", streaming=True),
40
+ # "image",
41
+ # live=True
42
+ #)
43
+ #demo.launch()
44
+
45
+
46
+
47
+ #def snap(image):
48
+ # return np.flipud(image)
49
+
50
+
51
+ #iface = gr.Interface(PPE, gr.inputs.Image(source="webcam", tool=None), "image")
52
+ #iface.launch()
53
+
54
+
55
+ #demo = gr.Interface(
56
+ # fn=PPE,
57
+ # inputs=gr.inputs.Image(source="webcam", tool=None),
58
+ # outputs="image",
59
+ #)
60
+ #demo.launch()
61
+
62
+ demo = gr.Interface(
63
+ fn=PPE,
64
+ inputs="image",
65
+ outputs="image",
66
+ )
67
+ demo.launch()
68
+