• 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_speachestestsmodel_manager_test.py
Download as .zip file
File name
Commit message
Commit date
.github/workflows
deps: move ui packages to a separate group
2024-10-01
examples
Update script.sh
2024-09-03
scripts
chore: misc changes
2024-10-03
src/speaches
chore: misc changes
2024-10-03
tests
feat: model unloading
2024-10-01
.dockerignore
chore: ignore .env
2024-05-27
.envrc
init
2024-05-20
.gitattributes
docs: add live-transcription demo
2024-05-28
.gitignore
chore: update .gitignore
2024-07-03
.pre-commit-config.yaml
fix: pre-commit basedpyright not checking all files
2024-10-01
Dockerfile.cpu
deps: move ui packages to a separate group
2024-10-01
Dockerfile.cuda
deps: move ui packages to a separate group
2024-10-01
LICENSE
init
2024-05-20
README.md
Update README.md
2024-10-01
Taskfile.yaml
feat: dependency injection
2024-09-22
audio.wav
docs: update README.md
2024-05-27
compose.yaml
chore: format compose
2024-09-11
flake.lock
deps: update flake
2024-10-01
flake.nix
deps: update flake
2024-09-08
pyproject.toml
feat: model unloading
2024-10-01
uv.lock
feat: model unloading
2024-10-01
File name
Commit message
Commit date
__init__.py
feat: add /v1/models and /v1/model routes #14
2024-06-03
api_model_test.py
chore: auto-fix ruff errors
2024-10-01
api_timestamp_granularities_test.py
chore: auto-fix ruff errors
2024-10-01
conftest.py
chore: auto-fix ruff errors
2024-10-01
model_manager_test.py
feat: model unloading
2024-10-01
openai_timestamp_granularities_test.py
chore: auto-fix ruff errors
2024-10-01
sse_test.py
chore: auto-fix ruff errors
2024-10-01
Fedir Zadniprovskyi 2024-10-01 8f29df1 feat: model unloading UNIX
Raw Open in browser Change history
import asyncio import os import anyio from httpx import ASGITransport, AsyncClient import pytest from faster_whisper_server.main import create_app @pytest.mark.asyncio async def test_model_unloaded_after_ttl() -> None: ttl = 5 model = "Systran/faster-whisper-tiny.en" os.environ["WHISPER__TTL"] = str(ttl) os.environ["ENABLE_UI"] = "false" async with AsyncClient(transport=ASGITransport(app=create_app()), base_url="http://test") as aclient: res = (await aclient.get("/api/ps")).json() assert len(res["models"]) == 0 await aclient.post(f"/api/ps/{model}") res = (await aclient.get("/api/ps")).json() assert len(res["models"]) == 1 await asyncio.sleep(ttl + 1) res = (await aclient.get("/api/ps")).json() assert len(res["models"]) == 0 @pytest.mark.asyncio async def test_ttl_resets_after_usage() -> None: ttl = 5 model = "Systran/faster-whisper-tiny.en" os.environ["WHISPER__TTL"] = str(ttl) os.environ["ENABLE_UI"] = "false" async with AsyncClient(transport=ASGITransport(app=create_app()), base_url="http://test") as aclient: await aclient.post(f"/api/ps/{model}") res = (await aclient.get("/api/ps")).json() assert len(res["models"]) == 1 await asyncio.sleep(ttl - 2) res = (await aclient.get("/api/ps")).json() assert len(res["models"]) == 1 async with await anyio.open_file("audio.wav", "rb") as f: data = await f.read() res = ( await aclient.post( "/v1/audio/transcriptions", files={"file": ("audio.wav", data, "audio/wav")}, data={"model": model} ) ).json() res = (await aclient.get("/api/ps")).json() assert len(res["models"]) == 1 await asyncio.sleep(ttl - 2) res = (await aclient.get("/api/ps")).json() assert len(res["models"]) == 1 await asyncio.sleep(3) res = (await aclient.get("/api/ps")).json() assert len(res["models"]) == 0 # test the model can be used again after being unloaded # this just ensures the model can be loaded again after being unloaded res = ( await aclient.post( "/v1/audio/transcriptions", files={"file": ("audio.wav", data, "audio/wav")}, data={"model": model} ) ).json() @pytest.mark.asyncio async def test_model_cant_be_unloaded_when_used() -> None: ttl = 0 model = "Systran/faster-whisper-tiny.en" os.environ["WHISPER__TTL"] = str(ttl) os.environ["ENABLE_UI"] = "false" async with AsyncClient(transport=ASGITransport(app=create_app()), base_url="http://test") as aclient: async with await anyio.open_file("audio.wav", "rb") as f: data = await f.read() task = asyncio.create_task( aclient.post( "/v1/audio/transcriptions", files={"file": ("audio.wav", data, "audio/wav")}, data={"model": model} ) ) await asyncio.sleep(0.01) res = await aclient.delete(f"/api/ps/{model}") assert res.status_code == 409 await task res = (await aclient.get("/api/ps")).json() assert len(res["models"]) == 0 @pytest.mark.asyncio async def test_model_cant_be_loaded_twice() -> None: ttl = -1 model = "Systran/faster-whisper-tiny.en" os.environ["ENABLE_UI"] = "false" os.environ["WHISPER__TTL"] = str(ttl) async with AsyncClient(transport=ASGITransport(app=create_app()), base_url="http://test") as aclient: res = await aclient.post(f"/api/ps/{model}") assert res.status_code == 201 res = await aclient.post(f"/api/ps/{model}") assert res.status_code == 409 res = (await aclient.get("/api/ps")).json() assert len(res["models"]) == 1 @pytest.mark.asyncio async def test_model_is_unloaded_after_request_when_ttl_is_zero() -> None: ttl = 0 os.environ["WHISPER__MODEL"] = "Systran/faster-whisper-tiny.en" os.environ["WHISPER__TTL"] = str(ttl) os.environ["ENABLE_UI"] = "false" async with AsyncClient(transport=ASGITransport(app=create_app()), base_url="http://test") as aclient: async with await anyio.open_file("audio.wav", "rb") as f: data = await f.read() res = await aclient.post( "/v1/audio/transcriptions", files={"file": ("audio.wav", data, "audio/wav")}, data={"model": "Systran/faster-whisper-tiny.en"}, ) res = (await aclient.get("/api/ps")).json() assert len(res["models"]) == 0

          
        
    
    
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