Skip to content

Commit

Permalink
Improve application start method
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmetoner committed Oct 6, 2024
1 parent 37f1bb2 commit a6169fb
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,4 @@ RUN poetry install

EXPOSE 9000

ENTRYPOINT ["gunicorn", "--bind", "0.0.0.0:9000", "--workers", "1", "--timeout", "0", "app.webservice:app", "-k", "uvicorn.workers.UvicornWorker"]
ENTRYPOINT ["whisper-asr-webservice"]
2 changes: 1 addition & 1 deletion Dockerfile.gpu
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,4 @@ RUN $POETRY_VENV/bin/pip install torch==1.13.1+cu117 -f https://download.pytorch

EXPOSE 9000

CMD gunicorn --bind 0.0.0.0:9000 --workers 1 --timeout 0 app.webservice:app -k uvicorn.workers.UvicornWorker
CMD whisper-asr-webservice
33 changes: 30 additions & 3 deletions app/webservice.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import importlib.metadata
import os
from os import path
from typing import Annotated, BinaryIO, Union
from typing import Annotated, BinaryIO, Optional, Union
from urllib.parse import quote

import click
import ffmpeg
import numpy as np
import uvicorn
from fastapi import FastAPI, File, Query, UploadFile, applications
from fastapi.openapi.docs import get_swagger_ui_html
from fastapi.responses import RedirectResponse, StreamingResponse
Expand All @@ -14,9 +16,9 @@

ASR_ENGINE = os.getenv("ASR_ENGINE", "openai_whisper")
if ASR_ENGINE == "faster_whisper":
from .faster_whisper.core import language_detection, transcribe
from app.faster_whisper.core import language_detection, transcribe
else:
from .openai_whisper.core import language_detection, transcribe
from app.openai_whisper.core import language_detection, transcribe

SAMPLE_RATE = 16000
LANGUAGE_CODES = sorted(tokenizer.LANGUAGES.keys())
Expand Down Expand Up @@ -122,3 +124,28 @@ def load_audio(file: BinaryIO, encode=True, sr: int = SAMPLE_RATE):
out = file.read()

return np.frombuffer(out, np.int16).flatten().astype(np.float32) / 32768.0

@click.command()
@click.option(
"-h",
"--host",
metavar="HOST",
default="0.0.0.0",
help="Host for the webservice (default: 0.0.0.0)",
)
@click.option(
"-p",
"--port",
metavar="PORT",
default=9000,
help="Port for the webservice (default: 9000)",
)
@click.version_option(version=projectMetadata["Version"])
def start(
host: str,
port: Optional[int] = None
):
uvicorn.run(app, host=host, port=port)

if __name__ == "__main__":
start()
2 changes: 1 addition & 1 deletion docs/build.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ poetry install
Starting the Webservice:

```sh
poetry run gunicorn --bind 0.0.0.0:9000 --workers 1 --timeout 0 app.webservice:app -k uvicorn.workers.UvicornWorker
poetry run whisper-asr-webservice --host 0.0.0.0 --port 9000
```

### Build
Expand Down

0 comments on commit a6169fb

Please sign in to comment.