capradeepgujaran
commited on
Commit
•
92928c5
1
Parent(s):
519704e
Update app.py
Browse files
app.py
CHANGED
@@ -91,7 +91,7 @@ class SafetyMonitor:
|
|
91 |
"""Perform safety analysis on the frame."""
|
92 |
if frame is None:
|
93 |
return "No frame received", {}
|
94 |
-
|
95 |
frame = self.preprocess_image(frame)
|
96 |
image_url = self.encode_image(frame)
|
97 |
|
@@ -104,23 +104,7 @@ class SafetyMonitor:
|
|
104 |
"content": [
|
105 |
{
|
106 |
"type": "text",
|
107 |
-
"text": "
|
108 |
-
1. Specify the precise location in the image
|
109 |
-
2. Describe the safety concern or violation
|
110 |
-
3. Indicate the potential risk
|
111 |
-
|
112 |
-
Format each finding as:
|
113 |
-
- <location>position:detailed safety concern</location>
|
114 |
-
|
115 |
-
Look for all types of safety issues:
|
116 |
-
- PPE compliance
|
117 |
-
- Ergonomic risks
|
118 |
-
- Equipment safety
|
119 |
-
- Environmental hazards
|
120 |
-
- Material handling
|
121 |
-
- Work procedures
|
122 |
-
- Access and egress
|
123 |
-
- Housekeeping"""
|
124 |
},
|
125 |
{
|
126 |
"type": "image_url",
|
@@ -129,9 +113,17 @@ class SafetyMonitor:
|
|
129 |
}
|
130 |
}
|
131 |
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
132 |
}
|
133 |
],
|
134 |
-
temperature=0.
|
135 |
max_tokens=500,
|
136 |
stream=False
|
137 |
)
|
@@ -186,7 +178,7 @@ class SafetyMonitor:
|
|
186 |
font_scale = 0.5
|
187 |
thickness = 2
|
188 |
padding = 10
|
189 |
-
|
190 |
for idx, obs in enumerate(observations):
|
191 |
color = self.colors[idx % len(self.colors)]
|
192 |
|
@@ -225,6 +217,7 @@ class SafetyMonitor:
|
|
225 |
try:
|
226 |
# Get analysis
|
227 |
analysis, _ = self.analyze_frame(frame)
|
|
|
228 |
display_frame = frame.copy()
|
229 |
|
230 |
# Parse observations
|
@@ -243,6 +236,8 @@ class SafetyMonitor:
|
|
243 |
'description': description.strip()
|
244 |
})
|
245 |
|
|
|
|
|
246 |
# Draw observations
|
247 |
if observations:
|
248 |
annotated_frame = self.draw_observations(display_frame, observations)
|
|
|
91 |
"""Perform safety analysis on the frame."""
|
92 |
if frame is None:
|
93 |
return "No frame received", {}
|
94 |
+
|
95 |
frame = self.preprocess_image(frame)
|
96 |
image_url = self.encode_image(frame)
|
97 |
|
|
|
104 |
"content": [
|
105 |
{
|
106 |
"type": "text",
|
107 |
+
"text": "Identify and list safety concerns in this workplace image. For each issue found, include its location and specific safety concern. Look for hazards related to PPE, ergonomics, equipment, environment, and work procedures."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
108 |
},
|
109 |
{
|
110 |
"type": "image_url",
|
|
|
113 |
}
|
114 |
}
|
115 |
]
|
116 |
+
},
|
117 |
+
{
|
118 |
+
"role": "assistant",
|
119 |
+
"content": "I'll analyze the image for safety hazards and provide the location and description of each concern."
|
120 |
+
},
|
121 |
+
{
|
122 |
+
"role": "user",
|
123 |
+
"content": "Please format each observation as: - <location>position:detailed safety concern</location>"
|
124 |
}
|
125 |
],
|
126 |
+
temperature=0.7,
|
127 |
max_tokens=500,
|
128 |
stream=False
|
129 |
)
|
|
|
178 |
font_scale = 0.5
|
179 |
thickness = 2
|
180 |
padding = 10
|
181 |
+
|
182 |
for idx, obs in enumerate(observations):
|
183 |
color = self.colors[idx % len(self.colors)]
|
184 |
|
|
|
217 |
try:
|
218 |
# Get analysis
|
219 |
analysis, _ = self.analyze_frame(frame)
|
220 |
+
print(f"Raw analysis: {analysis}") # Debug print
|
221 |
display_frame = frame.copy()
|
222 |
|
223 |
# Parse observations
|
|
|
236 |
'description': description.strip()
|
237 |
})
|
238 |
|
239 |
+
print(f"Parsed observations: {observations}") # Debug print
|
240 |
+
|
241 |
# Draw observations
|
242 |
if observations:
|
243 |
annotated_frame = self.draw_observations(display_frame, observations)
|