Skip to main content

OpenDBM REST API

Summary

Inside the OpenDBM repository, there is a folder named rest_api. This folder means to showcase that you can leverage OpenDBM library in API service or Web application, which this folder will showcase the former.

The OpenDBM API designed with OpenAPI 2.0 to standardize API definition for programmatic usage, better developer experience and documentation. It will also protected by standard security protocol.

OpenDBM REST API Summary
ODBM REST API Summary

How to use

To use the Rest API is very straighforward

  • Go to the rest_api directory
  • Install the neccessary dependencies
pip install -r requirements.txt
docker pull opendbmteam/dbm-openface
  • Then you can use Make syntax to run it
make dev

Wait until the rest api ready to serve requests

INFO:     Will watch for changes in these directories: ['/Users/smarty_not_dummy__user/open_dbm/rest_api/app']
INFO: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
INFO: Started reloader process [80258] using StatReload
INFO: Started server process [80275]
  • You can test using the OpenAPI specs like mentioned in here. You can open http://127.0.0.1:8000/docs or http://127.0.0.1:8000/redoc.
  • Before you start using the APIs, you need to create your credentials for authentication. Alternatively, you can try to use username 'aicure' and the password is 'opendbm'.

You can skip below steps if you want to use 'aicure' credential

  • To create your own username, first you generate your own password by following these steps:
cd rest_api/app
python
Python 3.7.13 (default, Mar 28 2022, 07:24:34)
[Clang 12.0.0 ] :: Anaconda, Inc. on darwin
Type "help", "copyright", "credits" or "license" for more information.

Then you can start type your own password using this python command

from services.auth.auth import get_password_hash
print(get_password_hash('test'))
$2b$12$qYnAxjQd..feDyPBYa/mDuRrH.PkcpNHJk3F.l/c0h3l/1NcZup7O

Save the password in the last line and your preferred username in app/services/auth/auth.py

def get_db():
fake_users_db = {
"your_new_username": {
"username": "your_new_username",
"full_name": "New Full name",
"email": "new email",
"hashed_password": "$2b$12$qYnAxjQd..feDyPBYa/mDuRrH.PkcpNHJk3F.l/c0h3l/1NcZup7O ",
"disabled": False,
},
"aicure": {
"username": "aicure",
"full_name": "AiCure OpenDBM",
"email": "opendbm@aicure.com",
"hashed_password": "$2b$12$k4R5SPuHkjFKBsQV5gAHl.e/BlxrX2z1H3vxiB9uGtaDZLFXjggCm",
"disabled": False,
},
"alice": {
"username": "alice",
"full_name": "Alice Wonderson",
"email": "alice@aicure.com",
"hashed_password": "fakehashedsecret2",
"disabled": True,
},
}
return fake_users_db
  • After that you can login using either of these icons, or using the curl alternative
OpenDBM Auth
ODBM Auth
  • Start with uploading the files, put the "local" string value in the platform parameter, then save the upload file name.
OpenDBM File Uploading
ODBM File Uploading

The API response will be

{
"info": "file 'facial_speech_verbal_video_test.mp4' saved at 'files/facial_speech_verbal_video_test.mp4'"
}

Save the file location returned somewhere files/facial_speech_verbal_video_test.mp4

  • Then you can use any API you want, insert the previous upload file url into file_url parameter. Then you can specify variables you want to get. For example, if you use the /video/acoustic API, you can specify the request body like
[
"audio_intensity",
"pitch_frequency"
]
OpenDBM Test Acoustic API
ODBM Test Acoustic API

After you execute the API, you will get the zip file, with the csv results compressed inside that file

You can check more details on rest_api usage in rest_api/README.md

Technology Stack

OpenDBM REST API Technology Stack
ODBM REST API Technology Stack

The OpenDBM API will use FastAPI framework. The main reason is because the asynchronous behaviour of FastAPI will works perfectly to complex and high performance methods like data upload, data pre / processing and other possible long operations.

We also use Uvicorn is an ASGI web server implementation for Python. Until recently Python has lacked a minimal low-level server/application interface for async frameworks. The ASGI specification fills this gap, and means we're now able to start building a common set of tooling usable across all async frameworks. Uvicorn currently supports HTTP/1.1 and WebSockets.

API Documentations

The Rest API documentations can be found when you run the the app. Change the relative path to /docs or /redoc

OpenDBM REST API Swagger API Docs
ODBM REST API Swagger API Docs
OpenDBM REST API Redocs
ODBM REST API Redocs