without saving to disk send to server by sokcet like part of JSON with JSON-structure data = ('user_id': user_id, 'filename': filename, 'file_source': file_source)
on server side take JSON and save screenshots with name filename and source of file file_source
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Here's a Python script that captures screenshots from all monitors, converts them to base64, and sends them to a server using a WebSocket connection as part of a JSON object. The server receives the JSON, decodes the base64 image data, and saves the screenshots with the specified filename and file source.
client.py:
python
import base64
import io
import json
import asyncio
import websockets
import mss
from PIL import Image
async def send_screenshot(uri, user_id, filename, file_source):
with mss.mss() as sct:
monitors = sct.monitors
screenshots = []
for i, monitor in enumerate(monitors[1:], start=1):
screenshot = sct.grab(monitor)
img = Image.frombytes("RGB", screenshot.size, screenshot.bgra, "raw", "BGRX")
img_buffer = io.BytesIO()
img.save(img_buffer, format="PNG")
img_base64 = base64.b64encode(img_buffer.getvalue()).decode("utf-8")
screenshots.append({'filename': f"{filename}_{i}.png", 'file_source': file_source, 'image_data': img_base64})
async with websockets.connect(uri) as websocket:
data = json.dumps({'user_id': user_id, 'screenshots': screenshots})
await websocket.send(data)
user_id = "example_user"
filename = "screenshot"
file_source = "client_app"
asyncio.get_event_loop().run_until_complete(send_screenshot("ws://localhost:8000", user_id, filename, file_source))
Run the server.py script first, then run the client.py script to capture and send screenshots. The server will save the received screenshots in the specified file source directory.