Update app.py
Browse files
app.py
CHANGED
|
@@ -8,6 +8,7 @@ import io
|
|
| 8 |
import base64
|
| 9 |
import torch
|
| 10 |
|
|
|
|
| 11 |
class RobustSafetyMonitor:
|
| 12 |
def __init__(self):
|
| 13 |
"""Initialize the robust safety detection tool with configuration."""
|
|
@@ -43,12 +44,12 @@ class RobustSafetyMonitor:
|
|
| 43 |
return image
|
| 44 |
|
| 45 |
def encode_image(self, frame):
|
| 46 |
-
"""Convert image to base64 encoding."""
|
| 47 |
frame_pil = PILImage.fromarray(frame)
|
| 48 |
buffered = io.BytesIO()
|
| 49 |
-
frame_pil.save(buffered, format="JPEG", quality=95)
|
| 50 |
img_base64 = base64.b64encode(buffered.getvalue()).decode('utf-8')
|
| 51 |
-
return
|
| 52 |
|
| 53 |
def detect_objects(self, frame):
|
| 54 |
"""Detect objects using YOLOv5."""
|
|
@@ -83,7 +84,7 @@ class RobustSafetyMonitor:
|
|
| 83 |
{
|
| 84 |
"type": "image_url",
|
| 85 |
"image_url": {
|
| 86 |
-
"url":
|
| 87 |
}
|
| 88 |
}
|
| 89 |
]
|
|
|
|
| 8 |
import base64
|
| 9 |
import torch
|
| 10 |
|
| 11 |
+
|
| 12 |
class RobustSafetyMonitor:
|
| 13 |
def __init__(self):
|
| 14 |
"""Initialize the robust safety detection tool with configuration."""
|
|
|
|
| 44 |
return image
|
| 45 |
|
| 46 |
def encode_image(self, frame):
|
| 47 |
+
"""Convert image to base64 encoding without extra formatting."""
|
| 48 |
frame_pil = PILImage.fromarray(frame)
|
| 49 |
buffered = io.BytesIO()
|
| 50 |
+
frame_pil.save(buffered, format="JPEG", quality=95) # Ensure JPEG format
|
| 51 |
img_base64 = base64.b64encode(buffered.getvalue()).decode('utf-8')
|
| 52 |
+
return img_base64 # Return only the base64 string, no "data:image/jpeg;base64,"
|
| 53 |
|
| 54 |
def detect_objects(self, frame):
|
| 55 |
"""Detect objects using YOLOv5."""
|
|
|
|
| 84 |
{
|
| 85 |
"type": "image_url",
|
| 86 |
"image_url": {
|
| 87 |
+
"url": image_base64 # Corrected: Send only the base64 string
|
| 88 |
}
|
| 89 |
}
|
| 90 |
]
|