Skip to content

armgit / cua

Public Imported from GitHub
0

Scale computer-use 2.0 with open-source drivers, cross-OS sandboxes, and benchmarks for training, evaluation, and data generation.

changed bytes to base64

Dillon DuPont56438440e6ab
diff --git a/libs/computer-server/computer_server/diorama/diorama.py b/libs/computer-server/computer_server/diorama/diorama.py
index b437b97406..711ba410a7 100644
--- a/libs/computer-server/computer_server/diorama/diorama.py
+++ b/libs/computer-server/computer_server/diorama/diorama.py
@@ -149,17 +149,20 @@ class Diorama:
logger.warning(f"Command was cancelled: {action}")
return None
- async def screenshot(self, as_bytes: bool = True) -> Union[bytes, Image]:
+ async def screenshot(self, as_bytes: bool = True) -> Union[str, Image.Image]:
+ import base64
result, img = await self._send_cmd("screenshot")
self._scene_hitboxes = result.get("hitboxes", [])
self._scene_size = img.size
if as_bytes:
- # PIL Image to bytes
+ # PIL Image to bytes, then base64 encode for JSON
+ import io
img_byte_arr = io.BytesIO()
img.save(img_byte_arr, format="PNG")
- img_byte_arr = img_byte_arr.getvalue()
- return img_byte_arr
+ img_bytes = img_byte_arr.getvalue()
+ img_b64 = base64.b64encode(img_bytes).decode("ascii")
+ return img_b64
else:
return img