• Y
  • List All
  • Feedback
    • This Project
    • All Projects
Profile Account settings Log out
  • Favorite
  • Project
  • All
Loading...
  • Log in
  • Sign up
yjyoon / whisper_server_speaches star
  • Project homeH
  • CodeC
  • IssueI
  • Pull requestP
  • Review R
  • MilestoneM
  • BoardB
  • Files
  • Commit
  • Branches
whisper_server_speachessrcspeachesdependencies.py
Download as .zip file
File name
Commit message
Commit date
.github/workflows
feat: switch to ghcr.io
01-10
configuration
feat: add instrumentation
2024-12-17
docs
rename to `speaches`
01-12
examples
rename to `speaches`
01-12
scripts
chore: misc changes
2024-10-03
src/speaches
rename to `speaches`
01-12
tests
rename to `speaches`
01-12
.dockerignore
chore: update .dockerignore
2024-11-01
.envrc
init
2024-05-20
.gitattributes
chore(deps): update pre-commit hook astral-sh/ruff-pre-commit to v0.7.2
2024-11-02
.gitignore
chore: update .gitignore
2024-07-03
.pre-commit-config.yaml
docs: usage pages (and more)
01-12
Dockerfile
rename to `speaches`
01-12
LICENSE
init
2024-05-20
README.md
rename to `speaches`
01-12
Taskfile.yaml
rename to `speaches`
01-12
audio.wav
chore: update volume names and mount points
01-10
compose.cpu.yaml
rename to `speaches`
01-12
compose.cuda-cdi.yaml
rename to `speaches`
01-12
compose.cuda.yaml
rename to `speaches`
01-12
compose.observability.yaml
rename to `speaches`
01-12
compose.yaml
rename to `speaches`
01-12
flake.lock
deps: update flake
2024-11-01
flake.nix
chore(deps): add loki and tempo package to flake
2024-12-17
mkdocs.yml
rename to `speaches`
01-12
pyproject.toml
rename to `speaches`
01-12
renovate.json
feat: renovate handle pre-commit
2024-11-01
uv.lock
rename to `speaches`
01-12
File name
Commit message
Commit date
routers
rename to `speaches`
01-12
__init__.py
rename to `speaches`
01-12
api_models.py
rename to `speaches`
01-12
asr.py
rename to `speaches`
01-12
audio.py
rename to `speaches`
01-12
config.py
rename to `speaches`
01-12
dependencies.py
rename to `speaches`
01-12
gradio_app.py
rename to `speaches`
01-12
hf_utils.py
rename to `speaches`
01-12
logger.py
rename to `speaches`
01-12
main.py
rename to `speaches`
01-12
model_manager.py
rename to `speaches`
01-12
text_utils.py
rename to `speaches`
01-12
text_utils_test.py
rename to `speaches`
01-12
transcriber.py
rename to `speaches`
01-12
Fedir Zadniprovskyi 01-12 43cc67a rename to `speaches` UNIX
Raw Open in browser Change history
from functools import lru_cache import logging from typing import Annotated from fastapi import Depends, HTTPException, status from fastapi.security import HTTPAuthorizationCredentials, HTTPBearer from httpx import ASGITransport, AsyncClient from openai import AsyncOpenAI from openai.resources.audio import AsyncSpeech, AsyncTranscriptions from openai.resources.chat.completions import AsyncCompletions from speaches.config import Config from speaches.model_manager import PiperModelManager, WhisperModelManager logger = logging.getLogger(__name__) # NOTE: `get_config` is called directly instead of using sub-dependencies so that these functions could be used outside of `FastAPI` # noqa: E501 # https://fastapi.tiangolo.com/advanced/settings/?h=setti#creating-the-settings-only-once-with-lru_cache # WARN: Any new module that ends up calling this function directly (not through `FastAPI` dependency injection) should be patched in `tests/conftest.py` # noqa: E501 @lru_cache def get_config() -> Config: return Config() ConfigDependency = Annotated[Config, Depends(get_config)] @lru_cache def get_model_manager() -> WhisperModelManager: config = get_config() return WhisperModelManager(config.whisper) ModelManagerDependency = Annotated[WhisperModelManager, Depends(get_model_manager)] @lru_cache def get_piper_model_manager() -> PiperModelManager: config = get_config() return PiperModelManager(config.whisper.ttl) # HACK: should have its own config PiperModelManagerDependency = Annotated[PiperModelManager, Depends(get_piper_model_manager)] security = HTTPBearer() async def verify_api_key( config: ConfigDependency, credentials: Annotated[HTTPAuthorizationCredentials, Depends(security)] ) -> None: if credentials.credentials != config.api_key: raise HTTPException(status_code=status.HTTP_403_FORBIDDEN) ApiKeyDependency = Depends(verify_api_key) @lru_cache def get_completion_client() -> AsyncCompletions: config = get_config() oai_client = AsyncOpenAI(base_url=config.chat_completion_base_url, api_key=config.chat_completion_api_key) return oai_client.chat.completions CompletionClientDependency = Annotated[AsyncCompletions, Depends(get_completion_client)] @lru_cache def get_speech_client() -> AsyncSpeech: config = get_config() if config.speech_base_url is None: # this might not work as expected if `speech_router` won't have shared state (access to the same `model_manager`) with the main FastAPI `app`. TODO: verify # noqa: E501 from speaches.routers.speech import ( router as speech_router, ) http_client = AsyncClient( transport=ASGITransport(speech_router), base_url="http://test/v1" ) # NOTE: "test" can be replaced with any other value oai_client = AsyncOpenAI(http_client=http_client, api_key=config.speech_api_key) else: oai_client = AsyncOpenAI(base_url=config.speech_base_url, api_key=config.speech_api_key) return oai_client.audio.speech SpeechClientDependency = Annotated[AsyncSpeech, Depends(get_speech_client)] @lru_cache def get_transcription_client() -> AsyncTranscriptions: config = get_config() if config.transcription_base_url is None: # this might not work as expected if `transcription_router` won't have shared state (access to the same `model_manager`) with the main FastAPI `app`. TODO: verify # noqa: E501 from speaches.routers.stt import ( router as stt_router, ) http_client = AsyncClient( transport=ASGITransport(stt_router), base_url="http://test/v1" ) # NOTE: "test" can be replaced with any other value oai_client = AsyncOpenAI(http_client=http_client, api_key=config.transcription_api_key) else: oai_client = AsyncOpenAI(base_url=config.transcription_base_url, api_key=config.transcription_api_key) return oai_client.audio.transcriptions TranscriptionClientDependency = Annotated[AsyncTranscriptions, Depends(get_transcription_client)]

          
        
    
    
Copyright Yona authors & © NAVER Corp. & NAVER LABS Supported by NAVER CLOUD PLATFORM

or
Sign in with github login with Google Sign in with Google
Reset password | Sign up