Update app.py
Browse files
app.py
CHANGED
@@ -52,21 +52,35 @@ def create_monitor_interface():
|
|
52 |
frame_pil.save(buffered, format="JPEG")
|
53 |
img_base64 = base64.b64encode(buffered.getvalue()).decode('utf-8')
|
54 |
|
55 |
-
|
|
|
56 |
1. PPE usage (helmets, vests, etc.)
|
57 |
2. Unsafe behaviors
|
58 |
3. Equipment safety
|
59 |
4. Environmental hazards
|
60 |
-
|
|
|
61 |
|
62 |
try:
|
63 |
completion = self.client.chat.completions.create(
|
64 |
messages=[
|
|
|
|
|
|
|
|
|
65 |
{
|
66 |
"role": "user",
|
67 |
"content": [
|
68 |
-
{
|
69 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
70 |
]
|
71 |
}
|
72 |
],
|
@@ -76,6 +90,7 @@ def create_monitor_interface():
|
|
76 |
)
|
77 |
return completion.choices[0].message.content
|
78 |
except Exception as e:
|
|
|
79 |
return f"Analysis Error: {str(e)}"
|
80 |
|
81 |
def process_frame(self, frame: np.ndarray) -> tuple[np.ndarray, str]:
|
|
|
52 |
frame_pil.save(buffered, format="JPEG")
|
53 |
img_base64 = base64.b64encode(buffered.getvalue()).decode('utf-8')
|
54 |
|
55 |
+
# Construct the prompt with proper format
|
56 |
+
system_prompt = """You are a workplace safety expert. Analyze the image for safety concerns, focusing on:
|
57 |
1. PPE usage (helmets, vests, etc.)
|
58 |
2. Unsafe behaviors
|
59 |
3. Equipment safety
|
60 |
4. Environmental hazards
|
61 |
+
|
62 |
+
Provide clear, specific observations."""
|
63 |
|
64 |
try:
|
65 |
completion = self.client.chat.completions.create(
|
66 |
messages=[
|
67 |
+
{
|
68 |
+
"role": "system",
|
69 |
+
"content": system_prompt
|
70 |
+
},
|
71 |
{
|
72 |
"role": "user",
|
73 |
"content": [
|
74 |
+
{
|
75 |
+
"type": "text",
|
76 |
+
"text": "Please analyze this image for safety concerns."
|
77 |
+
},
|
78 |
+
{
|
79 |
+
"type": "image",
|
80 |
+
"image": {
|
81 |
+
"url": f"data:image/jpeg;base64,{img_base64}"
|
82 |
+
}
|
83 |
+
}
|
84 |
]
|
85 |
}
|
86 |
],
|
|
|
90 |
)
|
91 |
return completion.choices[0].message.content
|
92 |
except Exception as e:
|
93 |
+
print(f"Detailed error: {str(e)}") # For debugging
|
94 |
return f"Analysis Error: {str(e)}"
|
95 |
|
96 |
def process_frame(self, frame: np.ndarray) -> tuple[np.ndarray, str]:
|