ahmetoner / whisper-asr-webservice

OpenAI Whisper ASR Webservice API
https://ahmetoner.github.io/whisper-asr-webservice
MIT License
1.85k stars 331 forks source link

Add ALLOW_ORIGINS Environment Variable #219

Open harvmaster opened 1 month ago

harvmaster commented 1 month ago

Add ALLOW_ORIGINS environment variable

Adds the ALLOW_ORIGINS environment variable to be set on the docker container. This is important for interfacing with the container from a website using fetch, as the browser will block the contents of the response if the appropriate headers are not present. This change ensures the headers are present on allowed origins. It imports the middleware package from FastAPI to handle the origin matching.

Example with docker-compose

version: '3.7'

services:
  openai-whisper-asr:
    container_name: whisper
    image: onerahmet/openai-whisper-asr-webservice:latest-gpu
    ports:
      - "9000:9000"
    environment:
      - ASR_MODEL=base
      - ASR_ENGINE=openai_whisper
      - ALLOW_ORIGINS=https://example.com
    deploy:
      resources:
        reservations:
          devices:
            - driver: nvidia
              count: 1
              capabilities: [gpu]

The default behavior is to allow any origins *`** (Wild cards are supportedhttps://*.example.com`) The variable is comma separated, so adding multiple origins can be done like so:

- ALLOW_ORIGINS=https://example.com, https://second_example.com, https://third_example.com

Docs have also been updated with this information