-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: use
State
to keep multithreading within controller
- Loading branch information
1 parent
5db5ec3
commit 4f2b300
Showing
7 changed files
with
68 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
from typing import BinaryIO, Protocol | ||
|
||
|
||
class TranscriberProtocol(Protocol): | ||
""" | ||
Summary | ||
------- | ||
a protocol for all transcriber(s) | ||
Methods | ||
------- | ||
transcribe(file: str | BinaryIO, caption_format: str) -> str | None: | ||
converts transcription segments into a specific caption format | ||
""" | ||
|
||
__slots__ = ('model',) | ||
|
||
def transcribe(self, file: str | BinaryIO, caption_format: str) -> str | None: | ||
""" | ||
Summary | ||
------- | ||
transcribes a compatible audio/video into a chosen caption format | ||
Parameters | ||
---------- | ||
file (str | BinaryIO) : the file to transcribe | ||
caption_format (str) : the chosen caption format | ||
Returns | ||
------- | ||
transcription (str | None) : the transcribed text in the chosen caption format | ||
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,22 @@ | ||
from contextlib import asynccontextmanager | ||
from typing import AsyncIterator | ||
|
||
from server.features import Transcriber | ||
from litestar import Litestar | ||
|
||
from capgen.transcriber import Transcriber | ||
from server.config import Config | ||
|
||
|
||
@asynccontextmanager | ||
async def load_model(_) -> AsyncIterator[None]: | ||
async def load_model(app: Litestar) -> AsyncIterator[None]: | ||
""" | ||
Summary | ||
------- | ||
download and load the model | ||
""" | ||
Transcriber.load() | ||
yield | ||
app.state.transcriber = Transcriber('cpu', number_of_workers=Config.worker_count) | ||
|
||
try: | ||
yield | ||
finally: | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
from litestar.datastructures import State | ||
|
||
from capgen.transcriber.protocol import TranscriberProtocol | ||
|
||
|
||
class AppState(State): | ||
""" | ||
Summary | ||
------- | ||
the Litestar application state that will be injected into the routers | ||
""" | ||
|
||
transcriber: TranscriberProtocol |