Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

POC: Frigate HTTP API using FastAPI #1

Closed
wants to merge 48 commits into from
Closed

POC: Frigate HTTP API using FastAPI #1

wants to merge 48 commits into from

Conversation

iursevla
Copy link
Owner

@iursevla iursevla commented Aug 20, 2024

FastAPI POC

This is a POC of using FastAPI to replace Flask in Frigate HTTP API. It is using the defaults provided by FastAPI (uvicorn and starlette). This was discussed here. The intent is not to be merged right away but rather to further the discussion and to get your feedback on my proposals at the end of this description.

I'm proposing that we add the FastAPI app mount the existing Flask app as a sub-application + 2. This means that the entire application still works as is and we can then start moving endpoint by endpoint to FastAPI until we get to a point where all endpoints are converted. At that point, we can remove Flask altogether.

I've started the conversion of 2-3 endpoints to showcase how it works:

  • Preview endpoints:
    • /preview/{camera_name}/start/{start_ts}/end/{end_ts}
    • /preview/{camera_name}/start/{start_ts}/end/{end_ts}/frames
  • Media endpoints:
    • /{camera_name}/latest.{extension} -> See warning below
  • App endpoints:
    • /logs/{service}

Here it is working with FastAPI

converted_file.mp4

HTTP API Documentation

Without any extra effort, the swagger documentation is available at http://localhost:5001/docs or http://localhost:5001/redoc See documentation

See image && video image
converted_file.mp4
Screenshot 2024-08-24 at 16 05 59

The JSON/YAML schema can then be used to feed the HTTP API page without any human interaction.


Problems faced

Caution

I've faced a problem with the existing endpoints which have an extension suffix: .(jpg|jpeg|png|webp|gif).As a result ⚠️ This lines in nginx.conf was commented out. I've left a comment explaining the errors. If someone wants/can help me figure out why it is failing, then use my branch to debug the endpoints that contain an extension.


Proposal(s):

My main proposal is (assuming we can get the nginx problem I've faced resolved):

  • Create a feature branch from the current development and merge this POC code in there
  • Then I can then start moving 2-3 endpoints a day/every 2 days to FastAPI and each time I create PR that can be reviewed and merged into the feature branch

Other proposals:

  1. In the previous POC I was not specific about the types for each path/query parameter but we can be more precise with the types
Details image

By being specific the endpoint will fail if invoked with invalid parameters

image

and we also get extra auto-complete on the docs

image
  1. Add prefix to API endpoints e.g. media related endpoints should be /api/media/... this avoid any conflict between endpoints and makes it easier to read and more "RESTFUL".

    i.e., the following should all be `/api/media/...` image
  2. Split app.py file into multiple other route files:

    • Move the config endpoints to config.py
    • Move the timeline endpoints to timeline.py
    • Move the logs endpoints tologs.py
    • Move the app lifecycle endpoints (stats/version/restart/etc) to lifecycle.py

Proposals 2 and 3 probably should be left out for future implementation to avoid scope creep

hunterjm and others added 30 commits August 18, 2024 07:41
* Initial re-implementation of semantic search

* put docker-compose back and make reindex match docs

* remove debug code and fix import

* fix docs

* manually build pysqlite3 as binaries are only available for x86-64

* update comment in build_pysqlite3.sh

* only embed objects

* better error handling when genai fails

* ask ollama to pull requested model at startup

* update ollama docs

* address some PR review comments

* fix lint

* use IPC to write description, update docs for reindex

* remove gemini-pro-vision from docs as it will be unavailable soon

* fix OpenAI doc available models

* fix api error in gemini and metadata for embeddings
* initial event search api implementation

* fix lint

* fix tests

* move chromadb imports and pysqlite hotswap to fix tests

* remove unused import

* switch default limit to 50

* fix events accidently pulling inside chroma results loop
* Add basic search page

* Abstract filters to separate components

* Make searching functional

* Add loading and no results indicators

* Implement searching

* Combine account and settings menus on mobile

* Support using thumbnail for in progress detections

* Fetch previews

* Move recordings view and open recordings when search is selected

* Implement detail pane

* Implement saving of description

* Implement similarity search

* Fix clicking

* Add date range picker

* Fix

* Fix iOS zoom bug

* Mobile fixes

* Use text area

* Fix spacing for drawer

* Fix fetching previews incorrectly
* Chroma logs in frontend

* fix lint
* Initial support for Hailo-8L

Added file for Hailo-8L detector including dockerfile, h8l.mk, h8l.hcl, hailo8l.py, ci.yml and ssd_mobilenat_v1.hef as the inference network.

Added files to help with the installation of Hailo-8L dependences like generate_wheel_conf.py, requirements-wheel-h8l.txt and modified setup.py to try and work with any hardware.

Updated docs to reflect Initial Hailo-8L support including oject_detectors.md,  hardware.md and installation.md.

* Update .github/workflows/ci.yml

typo h8l not arm64

Co-authored-by: Nicolas Mowen <nickmowen213@gmail.com>

* Update docs/docs/configuration/object_detectors.md

Clarity for the end user and correct uses of words

Co-authored-by: Nicolas Mowen <nickmowen213@gmail.com>

* Update docs/docs/frigate/installation.md

typo

Co-authored-by: Nicolas Mowen <nickmowen213@gmail.com>

* update Installation.md to clarify Hailo-8L installation process.

* Update docs/docs/frigate/hardware.md

Co-authored-by: Josh Hawkins <32435876+hawkeye217@users.noreply.github.com>

* Update hardware.md add Inference time.

* Oops no new line at the end of the file.

* Update docs/docs/frigate/hardware.md typo

Co-authored-by: Josh Hawkins <32435876+hawkeye217@users.noreply.github.com>

* Update dockerfile to download the ssd_modilenet_v1 model instead of having it in the repo.

* Updated dockerfile so it dose not download the model file.

add function to download it at runtime.

update model path.

* fix formatting according to ruff and removed unnecessary functions.

---------

Co-authored-by: Nicolas Mowen <nickmowen213@gmail.com>
Co-authored-by: Josh Hawkins <32435876+hawkeye217@users.noreply.github.com>
* Setup basic notification page

* Add basic notification implementation

* Register for push notifications

* Implement dispatching

* Add fields

* Handle image and link

* Add notification config

* Add field for users notification tokens

* Implement saving of notification tokens

* Implement VAPID key generation

* Implement public key encoding

* Implement webpush from server

* Implement push notification handling

* Make notifications config only

* Add maskable icon

* Use zod form to control notification settings in the UI

* Use js

* Always open notification

* Support multiple endpoints

* Handle cleaning up expired notification registrations

* Correctly unsubscribe notifications

* Change ttl dynamically

* Add note about notification latency and features

* Cleanup docs

* Fix firefox pushes

* Add links to docs and improve formatting

* Improve wording

* Fix docstring

Co-authored-by: Blake Blackshear <blake@frigate.video>

* Handle case where native auth is not enabled

* Show errors in UI

---------

Co-authored-by: Blake Blackshear <blake@frigate.video>
* Disable semantic search by default and don't start processes unless enabled

* Conditionally create embeddings

* Fix typing
* Support building docker image for amd64 and arm64

* Support installations on amd64 and arm64

* Run build in new job

* Update docs
* Use review item thumbnail for export

* Formatting
…hear#13071)

* Add ability to submit to frigate+ from review panel

* Add separator

* Use consistent ID
@iursevla iursevla changed the title POC: started example of fastapi usage POC: FastAPI example Aug 23, 2024
@iursevla iursevla changed the title POC: FastAPI example POC: Frigate HTTP API using FastAPI Aug 24, 2024
# Conflicts:
#	frigate/api/app.py
#	web/src/pages/Logs.tsx
@iursevla iursevla closed this Aug 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants