UI and Model
Browse files
app.py
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from ultralytics import YOLO
|
| 3 |
+
|
| 4 |
+
model = YOLO("best.pt")
|
| 5 |
+
|
| 6 |
+
PPE_OPTIONS = ["Helmet", "Vest", "Gloves", "Boots"]
|
| 7 |
+
|
| 8 |
+
#function to detect PPE and check compliance
|
| 9 |
+
def detect_ppe(image, required_items):
|
| 10 |
+
if image is None:
|
| 11 |
+
return None, "Image not found. Please upload an image."
|
| 12 |
+
|
| 13 |
+
if not required_items:
|
| 14 |
+
return image, "No PPE requirement selected"
|
| 15 |
+
|
| 16 |
+
results = model(image)
|
| 17 |
+
detected = set() #set to store detected PPE items
|
| 18 |
+
|
| 19 |
+
for r in results:
|
| 20 |
+
for c in r.boxes.cls:
|
| 21 |
+
detected.add(model.names[int(c)]) #add detected PPE item to the set
|
| 22 |
+
annotated = r.plot()
|
| 23 |
+
|
| 24 |
+
required = set(required_items)
|
| 25 |
+
missing = required - detected
|
| 26 |
+
|
| 27 |
+
if len(missing) == 0:
|
| 28 |
+
status = "ACCEPTED - Required PPE detected"
|
| 29 |
+
else:
|
| 30 |
+
status = f"REJECTED - Missing: {', '.join(missing)}, please wear the required PPE."
|
| 31 |
+
|
| 32 |
+
return annotated, status
|
| 33 |
+
|
| 34 |
+
#gradio interface for UI
|
| 35 |
+
demo = gr.Interface(
|
| 36 |
+
fn=detect_ppe,
|
| 37 |
+
inputs=[
|
| 38 |
+
gr.Image(type="numpy", label="Input Image / Webcam"),
|
| 39 |
+
gr.CheckboxGroup(
|
| 40 |
+
choices=PPE_OPTIONS,
|
| 41 |
+
value=PPE_OPTIONS,
|
| 42 |
+
label="Select Required PPE"
|
| 43 |
+
)
|
| 44 |
+
],
|
| 45 |
+
outputs=[
|
| 46 |
+
gr.Image(label="Detection Result"),
|
| 47 |
+
gr.Textbox(label="PPE Compliance Status")
|
| 48 |
+
],
|
| 49 |
+
title="PPE Compliance Detection System",
|
| 50 |
+
description="Detect PPE using YOLOv8 and verify compliance based on selected requirements"
|
| 51 |
+
)
|
| 52 |
+
|
| 53 |
+
demo.launch() #launch the gradio app
|
best.pt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:dde34a4927cf030c7f15f831dd7cab313420a1a92464dabc9348428cf8994a78
|
| 3 |
+
size 6250474
|