-
-
Notifications
You must be signed in to change notification settings - Fork 138
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 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
- Loading branch information
Showing
40 changed files
with
10,391 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"extends": "next/core-web-vitals" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files. | ||
|
||
# dependencies | ||
/node_modules | ||
/.pnp | ||
.pnp.js | ||
|
||
# testing | ||
/coverage | ||
|
||
# next.js | ||
/.next/ | ||
/out/ | ||
|
||
# production | ||
/build | ||
|
||
# misc | ||
.DS_Store | ||
*.pem | ||
|
||
# debug | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
|
||
# local env files | ||
.env*.local | ||
|
||
# vercel | ||
.vercel | ||
|
||
# typescript | ||
*.tsbuildinfo | ||
next-env.d.ts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
21 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"trailingComma": "es5", | ||
"tabWidth": 4, | ||
"semi": false, | ||
"singleQuote": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
<p align="center"> | ||
<a href="https://nextjs-fastapi-starter.vercel.app/"> | ||
<img src="https://assets.vercel.com/image/upload/v1588805858/repositories/vercel/logo.png" height="96"> | ||
<h3 align="center">Next.js FastAPI Starter</h3> | ||
</a> | ||
</p> | ||
|
||
<p align="center">Simple Next.js boilerplate that uses <a href="https://fastapi.tiangolo.com/">FastAPI</a> as the API backend.</p> | ||
|
||
<br/> | ||
|
||
## Introduction | ||
|
||
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. | ||
|
||
## How It Works | ||
|
||
The Python/FastAPI server is mapped into to Next.js app under `/api/`. | ||
|
||
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. | ||
|
||
On localhost, the rewrite will be made to the `127.0.0.1:8000` port, which is where the FastAPI server is running. | ||
|
||
In production, the FastAPI server is hosted as [Python serverless functions](https://vercel.com/docs/concepts/functions/serverless-functions/runtimes/python) on Vercel. | ||
|
||
## Demo | ||
|
||
https://nextjs-fastapi-starter.vercel.app/ | ||
|
||
## Deploy Your Own | ||
|
||
You can clone & deploy it to Vercel with one click: | ||
|
||
[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/clone?repository-url=https%3A%2F%2Fgithub.com%2Fdigitros%2Fnextjs-fastapi%2Ftree%2Fmain) | ||
|
||
## Developing Locally | ||
|
||
You can clone & create this repo with the following command | ||
|
||
```bash | ||
npx create-next-app nextjs-fastapi --example "https://github.com/digitros/nextjs-fastapi" | ||
``` | ||
|
||
## Getting Started | ||
|
||
First, install the dependencies: | ||
|
||
```bash | ||
npm install | ||
# or | ||
yarn | ||
# or | ||
pnpm install | ||
``` | ||
|
||
Then, run the development server: | ||
|
||
```bash | ||
npm run dev | ||
# or | ||
yarn dev | ||
# or | ||
pnpm dev | ||
``` | ||
|
||
Open [http://localhost:3000](http://localhost:3000) with your browser to see the result. | ||
|
||
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`). | ||
|
||
## Learn More | ||
|
||
To learn more about Next.js, take a look at the following resources: | ||
|
||
- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API. | ||
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial. | ||
- [FastAPI Documentation](https://fastapi.tiangolo.com/) - learn about FastAPI features and API. | ||
|
||
You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js/) - your feedback and contributions are welcome! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
"""Script to install dependencies needed for the dashboard.""" | ||
|
||
import os | ||
import subprocess | ||
import sys | ||
|
||
|
||
def _run(bash_script: str) -> int: | ||
return subprocess.call(bash_script, shell=True) | ||
|
||
|
||
def entrypoint() -> None: | ||
"""Entrypoint for the installation script.""" | ||
cwd = os.path.dirname(os.path.realpath(__file__)) | ||
os.chdir(cwd) | ||
|
||
if sys.platform == "win32": | ||
_run("powershell -File entrypoint.ps1") | ||
return | ||
_run("source ./entrypoint.sh") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
"""API endpoints for the dashboard.""" | ||
|
||
|
||
from fastapi import FastAPI | ||
|
||
from openadapt.app.cards import is_recording, quick_record, stop_record | ||
from openadapt.db import crud | ||
from openadapt.models import Recording | ||
|
||
app = FastAPI() | ||
|
||
|
||
@app.get("/api/recordings", response_model=None) | ||
def get_recordings() -> dict[str, list[Recording]]: | ||
"""Get all recordings.""" | ||
recordings = crud.get_all_recordings() | ||
return {"recordings": recordings} | ||
|
||
|
||
@app.get("/api/recordings/start") | ||
def start_recording() -> dict[str, str]: | ||
"""Start a recording session.""" | ||
quick_record() | ||
return {"message": "Recording started"} | ||
|
||
|
||
@app.get("/api/recordings/stop") | ||
def stop_recording() -> dict[str, str]: | ||
"""Stop a recording session.""" | ||
stop_record() | ||
return {"message": "Recording stopped"} | ||
|
||
|
||
@app.get("/api/recordings/status") | ||
def recording_status() -> dict[str, bool]: | ||
"""Get the recording status.""" | ||
return {"recording": is_recording()} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
@layer mantine tailwind; | ||
|
||
@import '@mantine/core/styles.layer.css'; | ||
|
||
@layer tailwind { | ||
@tailwind utilities; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import './globals.css' | ||
|
||
import { ColorSchemeScript, MantineProvider } from '@mantine/core' | ||
import { Shell } from '@/components/Shell' | ||
|
||
export const metadata = { | ||
title: 'OpenAdapt', | ||
} | ||
|
||
export default function RootLayout({ | ||
children, | ||
}: { | ||
children: React.ReactNode | ||
}) { | ||
return ( | ||
<html lang="en"> | ||
<head> | ||
<ColorSchemeScript /> | ||
</head> | ||
<body> | ||
<MantineProvider> | ||
<Shell>{children}</Shell> | ||
</MantineProvider> | ||
</body> | ||
</html> | ||
) | ||
} |
Oops, something went wrong.