Skip to content

Commit 0050cea

Browse files
authored
feat(dashboard): add web dashboard
* feat: Complete initial setup of web dashboard * feat(recordings): Add simple view to start, stop and list recordings * fix: Fix sqlite thread issue and a few dashbaord ui improvements * feat: Add script to download npm dependencies and update installer script * chore: Code cleanup and workflow fix
1 parent dd1c29e commit 0050cea

40 files changed

+10391
-27
lines changed

.github/workflows/main.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ jobs:
5858
- run: poetry install --no-interaction --no-root
5959
if: steps.cache-deps.outputs.cache-hit != 'true'
6060

61+
- name: Activate virtualenv
62+
run: source .venv/bin/activate
63+
if: steps.cache-deps.outputs.cache-hit == 'true'
64+
6165
- name: Check formatting with Black
6266
run: poetry run black --preview --check .
6367

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ pip3 install poetry
9696
poetry install
9797
poetry shell
9898
alembic upgrade head
99+
poetry run install-dashbaord
100+
99101
pytest
100102
```
101103

install/install_openadapt.ps1

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ $pythonMaxVersion = "3.10.12" # Change this if a different Higher version are su
1616
$pythonInstaller = "python-3.10.11-amd64.exe"
1717
$pythonInstallerLoc = "https://www.python.org/ftp/python/3.10.11/python-3.10.11-amd64.exe"
1818

19+
$nvmCmd = "nvm"
20+
$nvmInstaller = "nvm-setup.exe"
21+
$nvmInstallerLoc = "https://github.com/coreybutler/nvm-windows/releases/download/1.1.12/nvm-setup.exe"
22+
1923
$gitCmd = "git"
2024
$gitInstaller = "Git-2.40.1-64-bit.exe"
2125
$gitInstallerLoc = "https://github.com/git-for-windows/git/releases/download/v2.40.1.windows.1/Git-2.40.1-64-bit.exe"
@@ -226,6 +230,39 @@ function GetPythonCMD {
226230
exit
227231
}
228232

233+
# Check and Install NVM and return the nvm command
234+
function GetNVMCMD {
235+
$nvmExists = CheckCMDExists $nvmCmd
236+
if (!$nvmExists) {
237+
# Install NVM
238+
Write-Host "Downloading NVM installer..."
239+
$ProgressPreference = 'SilentlyContinue'
240+
Invoke-WebRequest -Uri $nvmInstallerLoc -OutFile $nvmInstaller
241+
$exists = Test-Path -Path $nvmInstaller -PathType Leaf
242+
if (!$exists) {
243+
Write-Host "Failed to download NVM installer" -ForegroundColor Red
244+
exit
245+
}
246+
247+
Write-Host "Installing NVM..."
248+
Start-Process -FilePath $nvmInstaller -Verb runAs -ArgumentList '/VERYSILENT /NORESTART /NOCANCEL /SP-' -Wait
249+
Remove-Item $nvmInstaller
250+
251+
RefreshPathVariables
252+
253+
# Make sure NVM is now available
254+
$nvmExists = CheckCMDExists $nvmCmd
255+
if (!$nvmExists) {
256+
Write-Host "Error after installing NVM. Uninstalling..."
257+
Start-Process -FilePath $nvmInstaller -Verb runAs -ArgumentList '/VERYSILENT /NORESTART /NOCANCEL /SP-' -Wait
258+
Cleanup
259+
exit
260+
}
261+
}
262+
# Return the nvm command
263+
return $nvmCmd
264+
}
265+
229266

230267
# Check and Install Git and return the git command
231268
function GetGitCMD {
@@ -310,6 +347,9 @@ RunAndCheck "$tesseract --version" "check TesseractOCR"
310347
$python = GetPythonCMD
311348
RunAndCheck "$python --version" "check Python"
312349

350+
$nvm = GetNVMCMD
351+
RunAndCheck "$nvm --version" "check NVM"
352+
313353
$git = GetGitCMD
314354
RunAndCheck "$git --version" "check Git"
315355

@@ -321,6 +361,7 @@ Set-Location .\OpenAdapt
321361
RunAndCheck "pip install poetry" "Run ``pip install poetry``"
322362
RunAndCheck "poetry install" "Run ``poetry install``"
323363
RunAndCheck "poetry run alembic upgrade head" "Run ``alembic upgrade head``" -SkipCleanup:$true
364+
RunAndCheck "poetry run dashboard" "Install dashboard dependencies" -SkipCleanup:$true
324365
RunAndCheck "poetry run pytest" "Run ``Pytest``" -SkipCleanup:$true
325366
Write-Host "OpenAdapt installed Successfully!" -ForegroundColor Green
326367
Start-Process powershell -Verb RunAs -ArgumentList "-NoExit", "-Command", "Set-Location -Path '$pwd'; poetry shell"

install/install_openadapt.sh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ set -x
88
pythonCmd="python3.10"
99
pythonVerStr="Python 3.10*"
1010
pythonInstallerLoc="https://www.python.org/ftp/python/3.10.11/python-3.10.11-macos11.pkg"
11+
nvmCmd="nvm"
12+
nvmInstallerLoc="https://github.com/raw/nvm-sh/nvm/v0.39.7/install.sh"
1113

1214
# Set default values when no parameters are provided
1315
BRANCH=${BRANCH:-main}
@@ -93,6 +95,27 @@ CheckPythonExists() {
9395
exit 1
9496
}
9597

98+
CheckNVMExists() {
99+
if CheckCMDExists $nvmCmd; then
100+
return
101+
fi
102+
103+
# Install NVM
104+
echo Installing NVM
105+
106+
curl -o- $nvmInstallerLoc | bash
107+
108+
export NVM_DIR="$HOME/.nvm"
109+
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
110+
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
111+
112+
if ! CheckCMDExists $nvmCmd; then
113+
echo "Failed to install NVM"
114+
Cleanup
115+
exit 1
116+
fi
117+
}
118+
96119
################################ INSTALLATION ################################
97120

98121
# Download brew
@@ -125,6 +148,7 @@ if ! CheckCMDExists "tesseract"; then
125148
fi
126149

127150
CheckPythonExists
151+
CheckNVMExists
128152

129153
[ -d "OpenAdapt" ] && mv OpenAdapt OpenAdapt-$(date +%Y-%m-%d_%H-%M-%S)
130154
RunAndCheck "git clone $REPO_URL" "Clone git repo"
@@ -134,6 +158,7 @@ RunAndCheck "git checkout $BRANCH" "Checkout branch $BRANCH"
134158
RunAndCheck "pip3.10 install poetry" "Install Poetry"
135159
RunAndCheck "poetry install" "Install Python dependencies"
136160
RunAndCheck "poetry run alembic upgrade head" "Update database"
161+
RunAndCheck "poetry run dashboard" "Install dashboard dependencies"
137162
RunAndCheck "poetry run pytest" "Run tests"
138163
if [ -z "$SKIP_POETRY_SHELL" ]; then
139164
RunAndCheck "poetry shell" "Activate virtual environment"

openadapt/app/cards.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,12 @@ def stop_record() -> None:
7676
record_proc = None
7777

7878

79+
def is_recording() -> bool:
80+
"""Check if a recording session is currently active."""
81+
global record_proc
82+
return record_proc is not None
83+
84+
7985
def quick_record() -> None:
8086
"""Run a recording session with no option for recording name (uses date instead)."""
8187
global record_proc
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"extends": "next/core-web-vitals"
3+
}

openadapt/app/dashboard/.gitignore

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2+
3+
# dependencies
4+
/node_modules
5+
/.pnp
6+
.pnp.js
7+
8+
# testing
9+
/coverage
10+
11+
# next.js
12+
/.next/
13+
/out/
14+
15+
# production
16+
/build
17+
18+
# misc
19+
.DS_Store
20+
*.pem
21+
22+
# debug
23+
npm-debug.log*
24+
yarn-debug.log*
25+
yarn-error.log*
26+
27+
# local env files
28+
.env*.local
29+
30+
# vercel
31+
.vercel
32+
33+
# typescript
34+
*.tsbuildinfo
35+
next-env.d.ts

openadapt/app/dashboard/.nvmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
21
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"trailingComma": "es5",
3+
"tabWidth": 4,
4+
"semi": false,
5+
"singleQuote": true
6+
}

openadapt/app/dashboard/README.md

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<p align="center">
2+
<a href="https://nextjs-fastapi-starter.vercel.app/">
3+
<img src="https://assets.vercel.com/image/upload/v1588805858/repositories/vercel/logo.png" height="96">
4+
<h3 align="center">Next.js FastAPI Starter</h3>
5+
</a>
6+
</p>
7+
8+
<p align="center">Simple Next.js boilerplate that uses <a href="https://fastapi.tiangolo.com/">FastAPI</a> as the API backend.</p>
9+
10+
<br/>
11+
12+
## Introduction
13+
14+
This is a hybrid Next.js + Python app that uses Next.js as the frontend and FastAPI as the API backend. One great use case of this is to write Next.js apps that use Python AI libraries on the backend.
15+
16+
## How It Works
17+
18+
The Python/FastAPI server is mapped into to Next.js app under `/api/`.
19+
20+
This is implemented using [`next.config.js` rewrites](https://github.com/digitros/nextjs-fastapi/blob/main/next.config.js) to map any request to `/api/:path*` to the FastAPI API, which is hosted in the `/api` folder.
21+
22+
On localhost, the rewrite will be made to the `127.0.0.1:8000` port, which is where the FastAPI server is running.
23+
24+
In production, the FastAPI server is hosted as [Python serverless functions](https://vercel.com/docs/concepts/functions/serverless-functions/runtimes/python) on Vercel.
25+
26+
## Demo
27+
28+
https://nextjs-fastapi-starter.vercel.app/
29+
30+
## Deploy Your Own
31+
32+
You can clone & deploy it to Vercel with one click:
33+
34+
[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/clone?repository-url=https%3A%2F%2Fgithub.com%2Fdigitros%2Fnextjs-fastapi%2Ftree%2Fmain)
35+
36+
## Developing Locally
37+
38+
You can clone & create this repo with the following command
39+
40+
```bash
41+
npx create-next-app nextjs-fastapi --example "https://github.com/digitros/nextjs-fastapi"
42+
```
43+
44+
## Getting Started
45+
46+
First, install the dependencies:
47+
48+
```bash
49+
npm install
50+
# or
51+
yarn
52+
# or
53+
pnpm install
54+
```
55+
56+
Then, run the development server:
57+
58+
```bash
59+
npm run dev
60+
# or
61+
yarn dev
62+
# or
63+
pnpm dev
64+
```
65+
66+
Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.
67+
68+
The FastApi server will be running on [http://127.0.0.1:8000](http://127.0.0.1:8000) – feel free to change the port in `package.json` (you'll also need to update it in `next.config.js`).
69+
70+
## Learn More
71+
72+
To learn more about Next.js, take a look at the following resources:
73+
74+
- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
75+
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.
76+
- [FastAPI Documentation](https://fastapi.tiangolo.com/) - learn about FastAPI features and API.
77+
78+
You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js/) - your feedback and contributions are welcome!

0 commit comments

Comments
 (0)