Skip to content

Commit

Permalink
perf: use Litestar's thread pool
Browse files Browse the repository at this point in the history
  • Loading branch information
winstxnhdw committed Sep 18, 2024
1 parent b1b0615 commit a594953
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions server/api/v1/transcribe.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
from asyncio import wrap_future
from concurrent.futures import ThreadPoolExecutor
from io import BytesIO
from typing import Annotated, Literal

from litestar import Controller, post
from litestar.concurrency import _run_sync_asyncio as run_sync
from litestar.datastructures import UploadFile
from litestar.enums import RequestEncodingType
from litestar.exceptions import ClientException
Expand All @@ -22,7 +21,6 @@ class TranscriberController(Controller):
"""

path = '/transcribe'
thread_pool = ThreadPoolExecutor()

@post(status_code=HTTP_200_OK)
async def transcribe(
Expand All @@ -37,7 +35,7 @@ async def transcribe(
the POST variant of the `/transcribe` route
"""
audio = BytesIO(await data.read())
transcription = await wrap_future(self.thread_pool.submit(state.transcriber.transcribe, audio, caption_format))
transcription = await run_sync(state.transcriber.transcribe, audio, caption_format)

if not transcription:
raise ClientException(detail=f'Invalid format: {caption_format}!')
Expand Down

0 comments on commit a594953

Please sign in to comment.