capradeepgujaran commited on
Commit
9cefc40
·
verified ·
1 Parent(s): 1ae9e2e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -21
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
- 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,9 +33,9 @@ def create_monitor_interface():
33
 
34
  buffered = io.BytesIO()
35
  frame_pil.save(buffered,
36
- format="JPEG",
37
- quality=85,
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,27 +45,34 @@ def create_monitor_interface():
45
  messages=[
46
  {
47
  "role": "system",
48
- "content": "You are a safety analysis expert. Analyze images for safety concerns and provide detailed observations."
 
 
 
 
 
 
49
  },
50
  {
51
  "role": "user",
52
  "content": [
53
  {
54
  "type": "text",
55
- "text": """Analyze this image for safety concerns and risks. For each issue you identify:
56
-
57
- 1. Specify the exact location in the image where the issue is visible
58
- 2. Describe what the safety concern is
59
- 3. Include any relevant details about PPE, posture, equipment, or environmental hazards
60
-
61
- Format EACH observation exactly like this:
62
- - <location>position:detailed description of the concern</location>
63
-
64
- Example format:
65
- - <location>center:Worker bending incorrectly while lifting heavy materials</location>
66
- - <location>top-right:Missing safety guardrail near elevated platform</location>
67
-
68
- Provide multiple observations if you see multiple issues."""
 
69
  },
70
  {
71
  "type": "image_url",
@@ -76,7 +83,7 @@ Provide multiple observations if you see multiple issues."""
76
  ]
77
  }
78
  ],
79
- temperature=0.5, # Increased for more varied observations
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
  )