Spaces:
Runtime error
Runtime error
Commit
·
eee3a62
1
Parent(s):
71336ab
Update app.py
Browse files
app.py
CHANGED
@@ -1,91 +1,13 @@
|
|
1 |
-
from ultralyticsplus import YOLO, render_result
|
2 |
-
import cv2
|
3 |
-
from PIL import Image
|
4 |
-
|
5 |
-
from cv2 import imshow
|
6 |
-
from cv2 import imwrite
|
7 |
-
|
8 |
-
def PPE(image):
|
9 |
-
# load model
|
10 |
-
#model = YOLO('keremberke/yolov8m-protective-equipment-detection')
|
11 |
-
model = YOLO('keremberke/yolov8m-hard-hat-detection')
|
12 |
-
# set model parameters
|
13 |
-
model.overrides['conf'] = 0.25 # NMS confidence threshold
|
14 |
-
model.overrides['iou'] = 0.45 # NMS IoU threshold
|
15 |
-
model.overrides['agnostic_nms'] = False # NMS class-agnostic
|
16 |
-
model.overrides['max_det'] = 1000 # maximum number of detections per image
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
# perform inference
|
21 |
-
results = model.predict(image)
|
22 |
-
|
23 |
-
# observe results
|
24 |
-
print(results[0].boxes)
|
25 |
-
render = render_result(model=model, image=image, result=results[0])
|
26 |
-
render.show()
|
27 |
-
|
28 |
-
def take_photo(image='photo.jpg', quality=0.8):
|
29 |
-
|
30 |
-
# program to capture single image from webcam in python
|
31 |
-
|
32 |
-
# importing OpenCV library
|
33 |
-
from cv2 import imshow
|
34 |
-
from cv2 import imwrite
|
35 |
-
|
36 |
-
# initialize the camera
|
37 |
-
# If you have multiple camera connected with
|
38 |
-
# current device, assign a value in cam_port
|
39 |
-
# variable according to that
|
40 |
-
cam_port = 0
|
41 |
-
cam = cv2.VideoCapture(cam_port)
|
42 |
-
|
43 |
-
# reading the input using the camera
|
44 |
-
result, image = cam.read()
|
45 |
-
|
46 |
-
# If image will detected without any error,
|
47 |
-
# show result
|
48 |
-
if result:
|
49 |
-
|
50 |
-
# showing result, it take frame name and image
|
51 |
-
# output
|
52 |
-
imshow("photo.jpg", image)
|
53 |
-
|
54 |
-
# saving image in local storage
|
55 |
-
imwrite("photo.jpg", image)
|
56 |
-
|
57 |
-
# If keyboard interrupt occurs, destroy image
|
58 |
-
# window
|
59 |
-
cv2.waitKey(0)
|
60 |
-
cv2.destroyAllWindows()
|
61 |
-
# cv2.destroyWindow("photo.jpg")
|
62 |
-
|
63 |
-
|
64 |
-
# If captured image is corrupted, moving to else part
|
65 |
-
else:
|
66 |
-
print("No image detected. Please! try again")
|
67 |
-
|
68 |
-
|
69 |
-
#with open(filename, 'wb') as f:
|
70 |
-
# f.write(binary)
|
71 |
-
return image
|
72 |
-
|
73 |
-
|
74 |
-
#take_photo()
|
75 |
-
|
76 |
-
|
77 |
-
from PIL import Image
|
78 |
-
|
79 |
-
#read the image
|
80 |
-
image = Image.open("photo.jpg")
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
import gradio as gr
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
+
import numpy as np
|
3 |
+
|
4 |
+
def flip(im):
|
5 |
+
return np.flipud(im)
|
6 |
+
|
7 |
+
demo = gr.Interface(
|
8 |
+
flip,
|
9 |
+
gr.Image(source="webcam", streaming=True),
|
10 |
+
"image",
|
11 |
+
live=True
|
12 |
+
)
|
13 |
+
demo.launch()
|