- server.py: FastAPI WebSocket server that runs a YOLO model and returns detections for each frame.
- client.py: Python desktop client that streams your laptop webcam to the server and draws detections locally.
- web_client.html: Browser client (works on desktop and iPhone Safari) that streams camera frames to the server and can draw returned boxes.
-
Install requirements (prefer a virtualenv):
pip install -r requirements.txt
-
Run the server (downloads YOLO weights on first run):
python -m uvicorn server:app --host 0.0.0.0 --port 8000
-
Run the desktop client (on the same machine or a different one):
- Edit
SERVER_WS_URLinclient.pyto point to your server (e.g.,ws://<server-ip>:8000/ws)
python client.py
- Press
qto quit.
- Edit
-
Try the browser client:
- Open
web_client.htmlin a browser over HTTPS or viapython -m http.serverand visithttp://localhost:8000(adjust for your static server). - Click Connect (allow camera). It will stream frames to
ws://127.0.0.1:8000/wsby default—change the field to your server URL if remote.
- Open
- Protocol: client sends TEXT JSON meta then BINARY JPEG; server replies TEXT JSON with detections.
- Tweak
JPEG_QUALITYandTARGET_FPSon the clients for bandwidth/latency tradeoffs. - For GPU inference, install CUDA-compatible PyTorch and Ultralytics as per their docs.
- Security: this is a demo—add authentication, rate limiting, and TLS for production.
- iPhone: use web_client.html in Mobile Safari; frame sizes and FPS should be lowered for stability.
server.pyclient.pyweb_client.htmlrequirements.txt