Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Latest commit

 

History

History

backend

Whisper-WebUI REST API

REST API for Whisper-WebUI. Documentation is auto-generated upon deploying the app.
Swagger UI is available at app/docs or root URL with redirection. Redoc is available at app/redoc.

Setup and Installation

Installation assumes that you are in the root directory of Whisper-WebUI

  1. Create .env in backend/configs/.env
HF_TOKEN="YOUR_HF_TOKEN FOR DIARIZATION MODEL (READ PERMISSION)"
DB_URL="sqlite:///backend/records.db"

HF_TOKEN is used to download diarization model, DB_URL indicates where your db file is located. It is stored in backend/ by default.

  1. Install dependency
pip install -r backend/requirements-backend.txt
  1. Deploy the server with uvicorn or whatever.
uvicorn backend.main:app --host 0.0.0.0 --port 8000

Deploy with your domain name

You can deploy the server with your domain name by setting up a reverse proxy with Nginx.

  1. Install Nginx if you don't already have it.
  1. Edit nginx.conf for your domain name.

    server_name your-own-domain-name.com;

  2. Add an A type record of your public IPv4 address in your domain provider. (you can get it by searching "What is my IP" in Google)

  3. Open a terminal and go to the location of nginx.conf, then start the nginx server, so that you can manage nginx-related logs there.

cd backend/nginx
nginx -c "/path/to/Whisper-WebUI/backend/nginx/nginx.conf"
  1. Open another terminal in the root project location /Whisper-WebUI, and deploy the app with uvicorn or whatever. Now the app will be available at your domain.
uvicorn backend.main:app --host 0.0.0.0 --port 8000
  1. When you turn off nginx, you can use nginx -s stop.
cd backend/nginx
nginx -s stop -c "/path/to/Whisper-WebUI/backend/nginx/nginx.conf"

Configuration

You can set some server configurations in config.yaml.
For example, initial model size for Whisper or the cleanup frequency and TTL for cached files.
If the endpoint generates and saves the file, all output files are stored in the cache directory, e.g. separated vocal/instrument files for /bgm-separation are saved in cache directory.

Docker

The Dockerfile should be built when you're in the root directory of Whisper-WebUI.

  1. git clone this repository
git clone https://github.com/jhj0517/Whisper-WebUI.git
  1. Mount volume paths with your local paths in docker-compose.yaml
    # The DB file is saved in /Whisper-WebUI/backend/records.db unless you edit it in /Whisper-WebUI/backend/configs/.env
    - ./models:/Whisper-WebUI/models
    - ./outputs:/Whisper-WebUI/outputs
    - ./backend:/Whisper-WebUI/backend
  2. Build the image
docker compose -f backend/docker-compose.yaml build
  1. Run the container
docker compose -f backend/docker-compose.yaml up
  1. Then you can read docs at localhost:8000 (default port is set to 8000 in docker-compose.yaml) and run your own tests.

Architecture

diagram

The response can be obtained through the polling API. Each task is stored in the DB whenever the task is queued or updated by the process.

When the client first sends the POST request, the server returns an identifier to the client that can be used to track the status of the task. The task status is updated by the processes, and once the task is completed, the client can finally obtain the result.

The client needs to implement manual API polling to do this, this is the example for the python client:

def wait_for_task_completion(identifier: str,
                             max_attempts: int = 20,
                             frequency: int = 3) -> httpx.Response:
    """
    Polls the task status every `frequency` until it is completed, failed, or the `max_attempts` are reached.
    """
    attempts = 0
    while attempts < max_attempts:
        task = fetch_task(identifier)
        status = task.json()["status"]
        if status == "COMPLETED":
            return task["result"]
        if status == "FAILED":
            raise Exception("Task polling failed")
        time.sleep(frequency)
        attempts += 1
    return None