franciscofsales / BabySleepCoach

DIY Baby Sleep Tracking

Home Page:https://calebolson.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

The Baby Sleep Coach

Shield: CC BY-NC-SA 4.0

This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

CC BY-NC-SA 4.0


This repo contains code to run the AI Baby Sleep Tracking service as well as a web application which provides the user with analysis and charts based on the recorded sleep data.

Pre-requisites

  • Camera which supports RTSP
  • Compute accessible via HTTP requests (I used a Raspberry Pi, but you can use any computer)
  • Python 3.10 or lower (3.11 is not supported by MediaPipe [see])

Setup

There are two components to configure:

  1. A sleep tracking python script
  2. A web application

Warning: jank ahead

I don't treat these projects as I would in industry. The result is a very monolithic and duct-tapey project.

If there is a desire, I will refactor and make this more repeatable and easy to use.

Part 1: Sleep Tracking Script

Install requirements: pip install -r requirements.txt

Run: python main.py

That's it. Except this is where the fun starts.

Most of the dependencies are self explanatory, the only issue I had was installing MediaPipe on Raspbian. I believe I used https://pypi.org/project/mediapipe-rpi4/, but I ran into a number of other issues I won't document here. glhf

There are number of environment variables and holes you'll need to fill with info about your environment. Instead of fixing things, I left a lot of comments.

Alternatively you can touch .env and then copy and paste the contents of .env_sample into it. Then fill in the blanks.

The sleep data is written to sleep_logs.csv. I primed this file with a few rows as an example. Feel free to remove these and start from scratch.

Part 2: The Web App

This one is more straight forward. Just make sure you have yarn.

Execute the following commands:

cd webapp; yarn install; yarn start;

And you'll probably get a warning about the app trying to boot on port 80. You can change it to whatever you want in the package.json.

You'll need to update some paths and IPs in the code.

Someone send me proof you got it all running.



Docker

It is also possible to install the app into a docker container. Clone the repository. Navigate to the path and build the docker image.

docker image build -t babysleepcoach . 

Run the container (adjust the ports, URLs and path).

With an environment file (for the .env file see env_sample_docker):

docker run -d -p7080:80 -p7081:8000 --env-file .env --name babysleepcoach babysleepcoach

Or with the parameters direct via command line:

docker run -d -p7080:80 -p7081:8000 -e REACT_APP_BACKEND_URL=URL_OF_THE_DOCKER_CONTAINER:7081 -e CAM_STREAM_URL=rtsp://user:password@URL_OF_CAMERA:554/stream1 -e DEBUG=False -e OWL=False -e HATCH_IP=127.0.0.1 -v /PATH_TO_SLEEP_LOGS_ON_HOST/sleep_logs.csv:/usr/app/babysleepcoach/sleep_logs.csv --name babysleepcoach babysleepcoach

The frontend can be accessed via http://URL_OF_THE_DOCKER_CONTAINER:7080 (or the port you wrote in the run command).

About

DIY Baby Sleep Tracking

https://calebolson.com

License:Other


Languages

Language:Jupyter Notebook 90.5%Language:Python 5.8%Language:JavaScript 3.1%Language:HTML 0.3%Language:CSS 0.2%Language:Shell 0.1%