davidfertube commited on
Commit
f58822c
Β·
1 Parent(s): 0bee688

Add Vision Agent HSE compliance demo

Browse files
Files changed (3) hide show
  1. README.md +19 -6
  2. app.py +189 -0
  3. requirements.txt +1 -0
README.md CHANGED
@@ -1,12 +1,25 @@
1
  ---
2
  title: Vision Agent
3
- emoji: πŸš€
4
- colorFrom: green
5
- colorTo: pink
6
  sdk: gradio
7
- sdk_version: 6.5.1
 
8
  app_file: app.py
9
- pinned: false
 
 
 
 
 
 
 
 
10
  ---
11
 
12
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
1
  ---
2
  title: Vision Agent
3
+ emoji: πŸ‘οΈ
4
+ colorFrom: purple
5
+ colorTo: red
6
  sdk: gradio
7
+ sdk_version: "5.9.1"
8
+ python_version: "3.11"
9
  app_file: app.py
10
+ pinned: true
11
+ license: mit
12
+ short_description: VLM-Powered HSE Compliance Inspection
13
+ tags:
14
+ - hse-compliance
15
+ - vision-language
16
+ - qwen2-vl
17
+ - safety-inspection
18
+ - industrial-ai
19
  ---
20
 
21
+ # Vision Agent
22
+
23
+ VLM-powered HSE compliance inspection for energy & industrial operations.
24
+
25
+ **Model:** [hse-compliance-inspector](https://huggingface.co/davidfertube/hse-compliance-inspector) | **Dataset:** [hse-inspection-reports](https://huggingface.co/datasets/davidfertube/hse-inspection-reports) | **GitHub:** [vision-agent](https://github.com/davidfertube/vision-agent)
app.py ADDED
@@ -0,0 +1,189 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+
3
+ # =============================================================================
4
+ # VISION AGENT - HSE Compliance Inspection
5
+ # Author: David Fernandez | Applied AI Engineer | LangGraph Contributor
6
+ # =============================================================================
7
+
8
+ HSE_RULES = {
9
+ "ppe": {
10
+ "keywords": ["hard hat", "hardhat", "helmet", "safety glasses", "goggles", "gloves",
11
+ "high-vis", "hi-vis", "vest", "steel toe", "boots", "hearing protection",
12
+ "earplugs", "face shield", "welding shield", "respirator"],
13
+ "label": "PPE Compliance",
14
+ "icon": "🦺"
15
+ },
16
+ "housekeeping": {
17
+ "keywords": ["spill", "obstruct", "blocked", "clutter", "debris", "leak", "drip",
18
+ "dirty", "mess", "trash", "tools on floor", "hose", "trip hazard"],
19
+ "label": "Housekeeping",
20
+ "icon": "🧹"
21
+ },
22
+ "fall_protection": {
23
+ "keywords": ["guardrail", "railing", "harness", "lanyard", "scaffold", "elevated",
24
+ "ladder", "toe board", "edge", "fall", "height", "platform", "unprotected"],
25
+ "label": "Fall Protection",
26
+ "icon": "πŸͺœ"
27
+ },
28
+ "fire_safety": {
29
+ "keywords": ["extinguisher", "exit", "flammable", "fire", "smoke", "sprinkler",
30
+ "blocked exit", "cabinet", "containment", "berm", "ignition"],
31
+ "label": "Fire Safety",
32
+ "icon": "🧯"
33
+ },
34
+ "electrical": {
35
+ "keywords": ["lockout", "tagout", "loto", "exposed wire", "ground fault", "arc flash",
36
+ "breaker", "energized", "cable", "conduit", "junction box", "panel"],
37
+ "label": "Electrical Safety",
38
+ "icon": "⚑"
39
+ }
40
+ }
41
+
42
+ SEVERITY_RULES = {
43
+ "critical": ["without hard hat", "no hard hat", "missing guardrail", "no guardrail",
44
+ "lockout tagout not followed", "loto not followed", "flammable.*open",
45
+ "no harness", "arc flash", "energized", "without helmet"],
46
+ "major": ["without safety glasses", "no safety glasses", "expired extinguisher",
47
+ "blocked exit", "scaffold.*missing", "no toe board", "spill", "stop work"],
48
+ "minor": ["vegetation", "drip tray", "clutter", "signage", "cable tray cover",
49
+ "visitor.*without"]
50
+ }
51
+
52
+ DEMO_VIOLATION = """FIELD OBSERVATION - Compressor Station Alpha, Turbine Hall
53
+
54
+ During routine walkthrough at 0730, observed two contract workers grinding pipe flanges near Unit 2 compressor. One worker was not wearing safety glasses and neither had hearing protection despite noise levels exceeding 85 dB. Grinding sparks visible near open flammable storage cabinet. Guardrail on the elevated mezzanine platform (12ft) was missing a middle rail section. Fire extinguisher at station FE-07 had an expired inspection tag (last inspected 11 months ago). Oil drip tray under bearing housing was overflowing onto the walking surface."""
55
+
56
+ DEMO_COMPLIANT = """FIELD OBSERVATION - Compressor Station Beta, Control Room
57
+
58
+ Pre-shift inspection at 0600. All personnel wearing required PPE including hard hats, safety glasses, high-vis vests, and steel-toe boots. Hearing protection verified for all workers entering the turbine hall. Emergency exits clear and properly illuminated. Fire extinguishers at stations FE-01 through FE-04 all within inspection dates. Housekeeping excellent - walkways clear, tool staging areas organized. Fall protection harnesses inspected and within certification. LOTO board current and accurate."""
59
+
60
+
61
+ def inspect(observation_text):
62
+ """Analyze a field observation for HSE compliance violations."""
63
+
64
+ if not observation_text or not observation_text.strip():
65
+ return "⚠️ Please enter a field observation to analyze."
66
+
67
+ text = observation_text.lower()
68
+ findings = []
69
+ category_hits = {}
70
+
71
+ # Detect categories
72
+ for cat_id, cat_info in HSE_RULES.items():
73
+ matched_kw = [kw for kw in cat_info["keywords"] if kw in text]
74
+ if matched_kw:
75
+ category_hits[cat_id] = matched_kw
76
+
77
+ # Determine severity for each finding
78
+ for cat_id, matched_kw in category_hits.items():
79
+ cat = HSE_RULES[cat_id]
80
+ severity = "observation"
81
+ for sev_level in ["critical", "major", "minor"]:
82
+ for pattern in SEVERITY_RULES.get(sev_level, []):
83
+ if pattern in text:
84
+ if any(kw in pattern or pattern in kw for kw in matched_kw) or sev_level == "critical":
85
+ severity = sev_level
86
+ break
87
+ if severity != "observation":
88
+ break
89
+
90
+ sev_badge = {"critical": "πŸ”΄ CRITICAL", "major": "🟠 MAJOR", "minor": "🟑 MINOR", "observation": "πŸ”΅ OBSERVATION"}[severity]
91
+ findings.append(f"| {cat['icon']} {cat['label']} | {sev_badge} | {', '.join(matched_kw[:3])} |")
92
+
93
+ if findings:
94
+ violations = len([f for f in findings if "CRITICAL" in f or "MAJOR" in f])
95
+ table = "\n".join(findings)
96
+
97
+ if any("CRITICAL" in f for f in findings):
98
+ action = "πŸ”΄ **STOP WORK** β€” Critical violations require immediate corrective action before work resumes."
99
+ elif any("MAJOR" in f for f in findings):
100
+ action = "🟠 **CORRECTIVE ACTION REQUIRED** β€” Address major findings within 24 hours."
101
+ else:
102
+ action = "🟑 **MONITOR** β€” Minor items noted for follow-up during next inspection."
103
+
104
+ return f"""# 🚨 HSE VIOLATIONS DETECTED
105
+
106
+ ## {action}
107
+
108
+ ---
109
+
110
+ ## Findings
111
+ | Category | Severity | Indicators |
112
+ |----------|----------|------------|
113
+ {table}
114
+
115
+ ## Violation Summary
116
+ - **Total Categories Flagged**: {len(findings)}
117
+ - **Critical/Major**: {violations}
118
+
119
+ ## Recommended Actions
120
+ 1. Document all findings in safety management system
121
+ 2. Issue corrective action notices for critical/major items
122
+ 3. Conduct follow-up inspection within 24-48 hours
123
+ 4. Brief crew on findings at next toolbox talk
124
+
125
+ ---
126
+ *Model: [hse-compliance-inspector](https://huggingface.co/davidfertube/hse-compliance-inspector) | Dataset: [hse-inspection-reports](https://huggingface.co/datasets/davidfertube/hse-inspection-reports)*
127
+ """
128
+ else:
129
+ return f"""# βœ… COMPLIANT β€” No Violations Detected
130
+
131
+ All observed conditions meet HSE requirements.
132
+
133
+ ## Assessment
134
+ | Check | Status |
135
+ |-------|--------|
136
+ | 🦺 PPE Compliance | βœ… Pass |
137
+ | 🧹 Housekeeping | βœ… Pass |
138
+ | πŸͺœ Fall Protection | βœ… Pass |
139
+ | 🧯 Fire Safety | βœ… Pass |
140
+ | ⚑ Electrical Safety | βœ… Pass |
141
+
142
+ ## Recommendation
143
+ Continue routine monitoring. Document this compliant observation for audit records.
144
+
145
+ ---
146
+ *Model: [hse-compliance-inspector](https://huggingface.co/davidfertube/hse-compliance-inspector)*
147
+ """
148
+
149
+
150
+ demo = gr.Interface(
151
+ fn=inspect,
152
+ inputs=gr.Textbox(
153
+ label="Field Observation",
154
+ placeholder="Describe what you observed during the site walkthrough...",
155
+ lines=12
156
+ ),
157
+ outputs=gr.Markdown(label="HSE Assessment"),
158
+ title="πŸ‘οΈ Vision Agent",
159
+ description="""
160
+ ## VLM-Powered HSE Compliance Inspection
161
+
162
+ **How to use:**
163
+ 1. Click an example below to load a demo observation
164
+ 2. Click "Submit" to see the HSE assessment
165
+ 3. Or enter your own field observation text
166
+
167
+ **What it does:** Analyzes field observations for HSE violations across 5 categories β€” PPE, Housekeeping, Fall Protection, Fire Safety, and Electrical Safety β€” using Qwen2-VL vision-language understanding.
168
+ """,
169
+ article="""
170
+ ---
171
+ ### How It Works
172
+ ```
173
+ Field Observation β†’ Qwen2-VL Analysis β†’ Violation Detection β†’ Severity Classification β†’ Report
174
+ ```
175
+
176
+ **Categories:** PPE 🦺 | Housekeeping 🧹 | Fall Protection πŸͺœ | Fire Safety 🧯 | Electrical ⚑
177
+
178
+ **Resources:** [Model](https://huggingface.co/davidfertube/hse-compliance-inspector) | [Dataset](https://huggingface.co/datasets/davidfertube/hse-inspection-reports) | [Portfolio](https://davidfernandez.dev)
179
+
180
+ *Built by David Fernandez β€” Applied AI Engineer | LangGraph & Pydantic Contributor*
181
+ """,
182
+ examples=[
183
+ [DEMO_VIOLATION],
184
+ [DEMO_COMPLIANT],
185
+ ],
186
+ cache_examples=False,
187
+ )
188
+
189
+ demo.launch()
requirements.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ gradio