A Python implementation of the server that handles the client data and application logic
- A backend server to handle data processing and running of various services.
- It takes input from a variety of sources, including video streams and the WebSocket Server.
- Designed to be easy for developers to implement new services and to be able to support real-time data processing.
Follow these steps to set up your development environment:
- Ensure that
python3
is installed on your system. - Install Miniconda from here.
- Note: Some packages may not work with Anaconda, so Miniconda is recommended.
- Upgrade pip, using
pip install --upgrade pip setuptools wheel
- Download and install VLC Player.
- Download and install FFmpeg and add it to your environment path.
- macOS: Use Homebrew install:
brew install ffmpeg
- Windows, Follow this guide to manually install FFmpeg and add it to your environment variables.
- macOS: Use Homebrew install:
- Create new conda environment
tom
usingconda env create -f environment-cpu.yml
- If you already have an existing environment and need to update it,
conda env update --file environment-cpu.yml --prune
. - To completely remove the existing
tom
environment before recreating it,conda remove -n tom --all
. - For ARM Mac (M1-Mn chip),
- If the installation fails due to
pyaudio
, please follow this - If the installation fails due to
egg_info
, change the dependencypsycopg2
topsycopg2-binary
inenvironment-cpu.yml
- If the installation fails due to
googlemaps
, either remove it fromenvironment-cpu.yml
or install it separately usingpip install --use-pep517 googlemaps
after activating thetom
environment.
- If the installation fails due to
- For torchaudio IO functions on MacOS, if you get an error with
torchaudio.load
function- The ffmpeg<7 libraries can be installed with :
conda install -c conda-forge 'ffmpeg<7'
- Refer to https://docs.pytorch.org/audio/main/installation.html for more details
- The ffmpeg<7 libraries can be installed with :
- If you already have an existing environment and need to update it,
- Once the environment is set up, activate it using,
conda activate tom
Follow these steps to set up the project on your computer.
- Clone the repository to your computer and navigate inside the project folder
-
git clone <your-repository-url> cd TOM-Server-Python
- Note: If you plan to contribute, fork the repository first and then clone your forked version. This is necessary because the main repository is read-only.
-
- Download the pretrained weights for YOLOv8 from Ultralytics (e.g., yolov8n.pt).
- Move the downloaded file to the
Processors/Yolov8/weights
directory. If the directory does not exist, create it. - Rename the file to
model.pt
(i.e.,Processors/Yolov8/weights/model.pt
). - [Optional] Use a custom YOLOv8 model (or train one) for other detection (e.g., emotion, face) purposes.
- [Optional] To enable pose landmark, face detection, audio classification with MediaPipe, manually download the following model weights:
- Pose Landmark model from Pose Landmarker:
- Rename the file to
pose_landmarker.task
. - Place it in the
Processors/PoseLandmarkDetection/weights/
directory.
- Rename the file to
- Face Detection model from Face Detector:
- Rename the file to
face_detector.tflite
. - Place it in the
Processors/FaceDetection/weights/
directory.
- Rename the file to
- Audio Classification (YamNet) model from Audio Classifier:
- Rename the file to
yamnet.tflite
. - Place it in the
Processors/BackgroundAudioClassifier/weights/
directory.
- Rename the file to
- Pose Landmark model from Pose Landmarker:
- Move the downloaded file to the
Environment files store project-specific settings. Follow these steps:
- For Development Environment:
- Copy
.sample_env
and paste it as.env.dev
in the (root) project folder. (e.g.,cp .sample_env .env.dev
) - [Optional] Update the file as needed.
- Example:
CAMERA_VIDEO_SOURCE = 0
uses the default camera. You can change it to any video stream/URL/file source. - [Optional] If using a HoloLens camera, enable it by uncommenting the following lines in main.py and update the IP address in
credential/hololens_credential.json
:# from APIs.hololens import hololens_portal # hololens_portal.set_api_credentials() # hololens_portal.set_hololens_as_camera()
- Example:
- Copy
- For Testing Environment:
- Copy
.sample_env
and paste it as.env.test
in the (root) project folder. (e.g.,cp .sample_env .env.test
)
- Copy
Some Third-party services require credentials. If you are using them, create credential files inside a new credential
folder. (Note: JSON format must be correct.)
- Hololens Credentials:
- Create a file
credential/hololens_credential.json
with Hololens credentials such as{"ip": "IP","username": "USERNAME","password": "PASSWORD"}
- Configure the Hololens Device Portal. Save your credentials to
credential/hololens_credential.json
- Configure the Hololens Device Portal. Save your credentials to
- Create a file
- Google Cloud API Credentials:
- Create a file
credential/google_cloud_credentials.json
with Google Cloud API credentials.- Follow authentication to get json key file and rename it to
google_cloud_credentials.json
- Follow authentication to get json key file and rename it to
- Create a file
- OpenAI Credentials:
- Create a file
credential/openai_credential.json
with OpenAI credentials such as{"openai_api_key": "KEY"}
- Create a file
- Gemini API Credentials:
- Create a file
credential/gemini_credential.json
with Gemini credentials such as{"gemini_api_key": "KEY"}
- Create a file
- Anthropic API Credentials:
- Create a file
credential/anthropic_credential.json
with Anthropic credentials such as{"anthropic_api_key": "KEY"}
- Create a file
- Google Maps API Credentials:
- Create a file
credential/google_maps_credential.json
with Google Maps credentials such as{"map_api_key": "KEY"}
- Current Google Maps APIs used:
- To use Google Maps API, you need to have a Google Cloud Platform (GCP) account to get an API key and enable the APIs shown above.
- Create a file
- OpenRouteService API Credentials:
- Create a file
credential/ors_credential.json
with Openrouteservice credentials such as{"map_api_key": "KEY"}
- Create a file
- Geoapify API Credentials:
- Create a file
credential/geoapify_credential.json
with Geoapify credentials such as{"map_api_key": "KEY"}
- Create a file
- Fitbit API Credentials:
- Create a file
credential/fitbit_credential.json
with Fitbit credentials such as{"client_id": "ID","client_secret": "SECRET"}
- Create a file
- If you want to simulate running assistance on a treadmill, follow the steps in Running Demo Service
- If you plan to use local APIs (e.g., local_vector_db), check their individual
README.md
files for configuration steps. - Note: Certain services (e.g., memory_assistance_service) depends on those local APIs.
Follow these steps to ensure your clients (e.g., HoloLens, Xreal, WearOS Watch) can connect to the server properly.
- Ensure all client devices are connected to the same Wi-Fi network as the server.
- Use a private network, as public networks may block ports used for WebSocket communication (e.g., 8090).
- Note: Campus networks or public hotspots may not work due to firewall restrictions.
- Use the following command in your terminal to get the Server IP address:
- Windows: Open Command Prompt and run:
ipconfig
- Mac/Linux: Open Terminal and run:
ifconfig
- Windows: Open Command Prompt and run:
- Look for the IPv4 address under the Wi-Fi section.
- Install TOM-Client-Unity on your HoloLens/Xreal/Quest3 device.
- Update the IP address in
Videos/TOM/tom_config.json
.
- Pair the Brilliant Labs Frame to the server (laptop) via Bluetooth.
- Makesure the device is connected via Bluetooth.
- Install TOM-Client-WearOS on your WearOS smartwatch.
- Update the IP address in
app/src/main/java/com/hci/tom/android/network/Credentials.kt
.
If clients cannot connect to the server via WebSocket, try these steps:
- Ensure all devices are on the same Wi-Fi network
- Windows devices (e.g., PCs or HoloLens) must set their network connection to private.
- Check firewall settings on the server machine
- Allow the server application to communicate through the firewall.
- Test if the server is reachable
- Use another computer on the same network to open
Tests/WebSocketClientTester.html
- This test will attempt to open port 8090 on the server. If it fails, check the network and firewall settings.
- Use another computer on the same network to open
- Activate it via the command line:
conda activate tom
(for Conda users) or through your IDE.
- For Windows Command Prompt:
set ENV=dev
- For Windows PowerShell:
$env:ENV = "dev"
- For Linux/Mac:
export ENV=dev
- Execute
main.py
using:(Avoid usingpython main.py
py main.py
.)
- Configure the IDE (e.g., VSCode, VSCode-Debug, PyCharm) to run the server with the environment variable
ENV=dev
.
- Run the clients after the server has started.
- Run
pytest
viapython -m pytest
(orpython -m pytest Tests\...\yy.py
orpython -m pytest Tests\...\yy.py::test_xx
to run specific tests)
- See the implemented services
- Examples
- Download the first person video here (you can download
fpv_short.mp4
orfpv.mp4
).- Copy the video/s to
Tests/RunningFpv/
. - Configure which video to be used (short/full) in the
.env
file (FPV_OPTION
).
- Copy the video/s to
- Set up the Unity and WearOS clients as mentioned in the Setup the Clients section.
- Ensure that
DemoRunningCoach.yaml
is set in/Config
, andRunningCoach.yaml
is in/Config/Ignore
on the python server.
- See DeveloperGuide.md for more details on development guidelines and adding new services/components.
- Structuring Your Project
- Modules
- python-testing
- To find/update dependencies, use
conda env export > environment.yml
(orpip3 freeze > requirements.txt
) ref
- YOLO-WORLD on WSL - Guide for setting up YOLO-WORLD on a WSL machine.
- cloud-vision-api-python, google-cloud-vision,
- Detic
- google-maps, google-maps-services-python
- OpenAI
- Gemini
- Anthropic
- Nominatim OpenStreetMap
- Openrouteservice, OpenStreetMap
- Geoapify
- GeographicLib
- Shapely
- Ultralytics YOLOv8
- python-fitbit
- python-vlc
- See other dependencies in environment-cpu.yml