Update app.py
Browse files
app.py
CHANGED
@@ -18,10 +18,10 @@ def create_monitor_interface():
|
|
18 |
self.max_image_size = (800, 800)
|
19 |
self.colors = [(0, 0, 255), (255, 0, 0), (0, 255, 0), (255, 255, 0), (255, 0, 255)]
|
20 |
|
21 |
-
|
22 |
if frame is None:
|
23 |
return ""
|
24 |
-
|
25 |
# Convert image
|
26 |
if len(frame.shape) == 2:
|
27 |
frame = cv2.cvtColor(frame, cv2.COLOR_GRAY2RGB)
|
@@ -33,9 +33,9 @@ def create_monitor_interface():
|
|
33 |
|
34 |
buffered = io.BytesIO()
|
35 |
frame_pil.save(buffered,
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
img_base64 = base64.b64encode(buffered.getvalue()).decode('utf-8')
|
40 |
image_url = f"data:image/jpeg;base64,{img_base64}"
|
41 |
|
@@ -45,27 +45,34 @@ def create_monitor_interface():
|
|
45 |
messages=[
|
46 |
{
|
47 |
"role": "system",
|
48 |
-
"content": "You are a safety
|
|
|
|
|
|
|
|
|
|
|
|
|
49 |
},
|
50 |
{
|
51 |
"role": "user",
|
52 |
"content": [
|
53 |
{
|
54 |
"type": "text",
|
55 |
-
"text": """
|
56 |
-
|
57 |
-
1.
|
58 |
-
2.
|
59 |
-
3.
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
- <location>
|
67 |
-
|
68 |
-
|
|
|
69 |
},
|
70 |
{
|
71 |
"type": "image_url",
|
@@ -76,7 +83,7 @@ Provide multiple observations if you see multiple issues."""
|
|
76 |
]
|
77 |
}
|
78 |
],
|
79 |
-
temperature=0.
|
80 |
max_tokens=500,
|
81 |
stream=False
|
82 |
)
|
|
|
18 |
self.max_image_size = (800, 800)
|
19 |
self.colors = [(0, 0, 255), (255, 0, 0), (0, 255, 0), (255, 255, 0), (255, 0, 255)]
|
20 |
|
21 |
+
def analyze_frame(self, frame: np.ndarray) -> str:
|
22 |
if frame is None:
|
23 |
return ""
|
24 |
+
|
25 |
# Convert image
|
26 |
if len(frame.shape) == 2:
|
27 |
frame = cv2.cvtColor(frame, cv2.COLOR_GRAY2RGB)
|
|
|
33 |
|
34 |
buffered = io.BytesIO()
|
35 |
frame_pil.save(buffered,
|
36 |
+
format="JPEG",
|
37 |
+
quality=95, # Increased quality
|
38 |
+
optimize=True)
|
39 |
img_base64 = base64.b64encode(buffered.getvalue()).decode('utf-8')
|
40 |
image_url = f"data:image/jpeg;base64,{img_base64}"
|
41 |
|
|
|
45 |
messages=[
|
46 |
{
|
47 |
"role": "system",
|
48 |
+
"content": """You are a construction site safety expert specializing in ergonomics and workplace safety.
|
49 |
+
Analyze images for:
|
50 |
+
1. Worker posture and ergonomic risks
|
51 |
+
2. PPE usage and compliance
|
52 |
+
3. Tool and equipment safety
|
53 |
+
4. Environmental hazards
|
54 |
+
5. Working position and technique"""
|
55 |
},
|
56 |
{
|
57 |
"role": "user",
|
58 |
"content": [
|
59 |
{
|
60 |
"type": "text",
|
61 |
+
"text": """Carefully analyze this construction worker's position and environment. Look for:
|
62 |
+
|
63 |
+
1. Ergonomic issues (kneeling position, back posture, repetitive motions)
|
64 |
+
2. PPE compliance (knee pads, gloves, appropriate footwear)
|
65 |
+
3. Working technique and body mechanics
|
66 |
+
4. Surrounding hazards or risks
|
67 |
+
|
68 |
+
For each issue identified, format your response as:
|
69 |
+
- <location>position:specific safety concern and recommendation</location>
|
70 |
+
|
71 |
+
For example:
|
72 |
+
- <location>center:Worker kneeling without knee protection, risking joint injury. Recommend knee pads.</location>
|
73 |
+
- <location>bottom:Improper back posture while working, potential for strain. Should maintain straight back.</location>
|
74 |
+
|
75 |
+
Be specific about each safety concern you observe."""
|
76 |
},
|
77 |
{
|
78 |
"type": "image_url",
|
|
|
83 |
]
|
84 |
}
|
85 |
],
|
86 |
+
temperature=0.3, # Lowered temperature for more focused analysis
|
87 |
max_tokens=500,
|
88 |
stream=False
|
89 |
)
|