simran0608 commited on
Commit
680620c
·
verified ·
1 Parent(s): b0685ad

Upload 6 files

Browse files
Files changed (6) hide show
  1. 1.jpg +0 -0
  2. 2.jpg +0 -0
  3. 3.jpg +0 -0
  4. app.py +108 -0
  5. ppe-kit.pt +3 -0
  6. requirements.txt +2 -0
1.jpg ADDED
2.jpg ADDED
3.jpg ADDED
app.py ADDED
@@ -0,0 +1,108 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from PIL import Image
3
+ import numpy as np
4
+ import cv2
5
+ from ultralytics import YOLO
6
+
7
+ # Load your PPE detection model
8
+ model = YOLO('ppe-kit.pt') # Replace with your PPE detection model path
9
+
10
+ # Set page configuration
11
+ st.set_page_config(
12
+ page_title="PPE Kit Detection",
13
+ page_icon="🦺",
14
+ layout="wide",
15
+ initial_sidebar_state="expanded",
16
+ )
17
+
18
+ # Sidebar contents
19
+ st.sidebar.title("🦺 PPE Kit Detection")
20
+ st.sidebar.write("Upload an image to detect PPE kits.")
21
+
22
+ # Upload image
23
+ uploaded_file = st.sidebar.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
24
+
25
+ # Main content
26
+ st.title("🦺 PPE Kit Detection")
27
+ st.write(
28
+ """
29
+ This application uses a state-of-the-art YOLO model to detect PPE kits and safety measures in images.
30
+ It identifies items like helmets, masks, safety vests, and more. Upload an image to see the detection in action.
31
+ """
32
+ )
33
+
34
+ if uploaded_file is not None:
35
+ # Display uploaded image
36
+ image = Image.open(uploaded_file)
37
+
38
+ # Create two columns for displaying the image
39
+ col1, col2 = st.columns(2)
40
+
41
+ with col1:
42
+ st.header("Uploaded Image")
43
+ st.image(image, caption='Uploaded Image', use_column_width=True)
44
+
45
+ with col2:
46
+ st.header("Detected PPE and Safety Items")
47
+
48
+ # Convert the image to OpenCV format
49
+ image_cv = np.array(image)
50
+ image_cv = image_cv[:, :, ::-1].copy() # Convert RGB to BGR
51
+
52
+ # Run inference
53
+ results = model(image_cv)
54
+
55
+ # Process the results
56
+ boxes = results[0].boxes
57
+ labels = {
58
+ 0: 'Helmet', 1: 'Mask', 2: 'NO-Helmet', 3: 'NO-Mask', 4: 'NO-Safety Vest',
59
+ 5: 'Person', 6: 'Safety Cone', 7: 'Safety Vest', 8: 'machinery', 9: 'vehicle'
60
+ }
61
+
62
+ detected_items = [] # List to store detected items and accuracy
63
+
64
+ # Define a set of class IDs to skip (machinery, vehicle, and person)
65
+ skip_classes = {5, 8, 9} # Person, machinery, vehicle
66
+
67
+ # Draw bounding boxes and labels on the image
68
+ for box in boxes:
69
+ x1, y1, x2, y2 = map(int, box.xyxy[0])
70
+ confidence = box.conf[0]
71
+ class_id = int(box.cls[0])
72
+ label = labels.get(class_id, 'Unknown')
73
+
74
+ # Skip drawing and storing items if they belong to the skip_classes set
75
+ if class_id in skip_classes:
76
+ continue
77
+
78
+ # Store detected items with accuracy
79
+ detected_items.append(f"{label} ({confidence * 100:.2f}%)")
80
+
81
+ # Draw the box
82
+ cv2.rectangle(image_cv, (x1, y1), (x2, y2), (0, 255, 0), 2)
83
+ # Put the label
84
+ cv2.putText(image_cv, f"{label} {confidence:.2f}", (x1, y1 - 10),
85
+ cv2.FONT_HERSHEY_SIMPLEX, 0.9, (36, 255, 12), 2)
86
+
87
+ # Convert the image back to RGB
88
+ image_cv = image_cv[:, :, ::-1].copy()
89
+ st.image(image_cv, caption='Detected PPE and Safety Items', use_column_width=True)
90
+
91
+ # Centered detected items below the image
92
+ st.markdown("<h2 style='text-align: center;'>Detected Items with Accuracy:</h2>", unsafe_allow_html=True)
93
+
94
+ # Display the detected items in a centered fashion
95
+ for item in detected_items:
96
+ st.markdown(f"<h4 style='text-align: center;'>{item}</h4>", unsafe_allow_html=True)
97
+
98
+ st.success("Detection complete!")
99
+
100
+ else:
101
+ st.info("Please upload an image to start detection.")
102
+
103
+ # Footer
104
+ st.sidebar.markdown("### About")
105
+ st.sidebar.info(
106
+ "This app uses a YOLO model to detect PPE kits like helmets, masks, safety vests, and other safety-related items. "
107
+ "Upload an image and the model will identify these items in the image."
108
+ )
ppe-kit.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:4d07bbd92ca30d5c12dd67ccf52b2f54f533c9ccfef534284124682ef9f56129
3
+ size 6251955
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ ultralytics==8.2.34
2
+ streamlit