Skip to content

Commit

Permalink
build: restructuring, implementation of rye dependency manager, Docke…
Browse files Browse the repository at this point in the history
…rfile improvement
  • Loading branch information
MrPandir committed Feb 17, 2024
1 parent ac681d8 commit 45b49bb
Show file tree
Hide file tree
Showing 12 changed files with 240 additions and 34 deletions.
8 changes: 4 additions & 4 deletions app.py → app/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
from litestar.config.response_cache import CACHE_FOREVER
from litestar.params import Parameter

from tts import tts
from openapi_examples import *
from http_exceptions import *
from exceptions import *
from tts.tts import tts
from tts.exceptions import *
from app.openapi_examples import *
from app.http_exceptions import *


load_dotenv()
Expand Down
File renamed without changes.
File renamed without changes.
42 changes: 22 additions & 20 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,30 +1,32 @@
FROM python:3.9-slim as base
FROM python:3.12.2-slim-bookworm as base
LABEL org.opencontainers.image.authors="MrPandir <MrPandir@users.noreply.github.com>"
LABEL org.opencontainers.image.source="https://github.com/twirapp/silero-tts-api-server"
LABEL org.opencontainers.image.licenses="MIT"
LABEL org.opencontainers.image.title="Silero TTS API server"
LABEL org.opencontainers.image.description="This is a simple server that uses Silero models to convert text to audio files over HTTP"
LABEL org.opencontainers.image.vendor="TwirApp"

FROM base as pip-installer
WORKDIR /app
COPY requirements.txt requirements.txt
RUN pip3 install -r requirements.txt --user --no-cache-dir --no-warn-script-location
FROM base as dependencies-installer
SHELL ["/bin/bash", "-c"]
RUN apt-get -y update && apt-get -y install curl && \
apt-get autoremove && apt-get clean
RUN curl -sSf https://rye-up.com/get | NO_AUTO_INSTALL=1 RYE_INSTALL_OPTION="--yes" RYE_TOOLCHAIN=/usr/local/bin/python3 bash && \
bash -c "source $HOME/.rye/env && rye pin 3.12.2"
ENV PATH=/root/.rye/shims:$PATH
COPY pyproject.toml requirements.lock /app/
RUN --mount=type=cache,target=/root/.cache rye sync --pyproject /app/pyproject.toml --no-dev --no-lock

FROM base as models-installer
WORKDIR /app
RUN apt-get update && apt-get install -y curl
RUN apt-get -y update && apt-get -y install curl
COPY models models
COPY install_models.sh install_models.sh
RUN chmod -x install_models.sh && bash ./install_models.sh >&2


FROM base
LABEL org.opencontainers.image.authors="MrPandir <MrPandir@users.noreply.github.com>"
LABEL org.opencontainers.image.source="https://github.com/twirapp/silero-tts-api-server"
LABEL org.opencontainers.image.licenses="MIT"
LABEL org.opencontainers.image.title="Silero TTS API server"
LABEL org.opencontainers.image.description="This is a simple server that uses Silero models to convert text to audio files over HTTP"
LABEL org.opencontainers.image.vendor="TwirApp"
WORKDIR /app

COPY . /app
COPY --from=models-installer /app/models /app/models
COPY --from=pip-installer /root/.local /root/.local
ENV PATH=/root/.local/bin:$PATH

COPY --from=models-installer /models /app/models
COPY --from=dependencies-installer /app/.venv .venv
ENV PATH=/app/.venv/bin:$PATH
COPY /app ./app
COPY /tts ./tts
CMD ["litestar", "run", "--host", "0.0.0.0", "--port", "8000"]
2 changes: 1 addition & 1 deletion docker/Dockerfile.dockerignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.*
docker/

__pycache__
**/__pycache__
venv
38 changes: 38 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
[project]
name = "silero-tts-api-server"
version = "1.0.0"
description = "This is a simple server that uses Silero models to convert text to audio files over HTTP"
authors = [
{ name = "MrPandir", email = "MrPandir@users.noreply.github.com" }
]
dependencies = [
"uvicorn>=0.27.1",
"litestar>=2.6.1",
"torch>=2.2.0",
"numpy>=1.26.4",
"python-dotenv>=1.0.1",
]
requires-python = ">=3.9"

[tool.rye]
managed = true
dev-dependencies = []
excluded-dependencies = [
"polyfactory",
"faker",
"six",
"filelock",
"fsspec",
"jinja2",
"markupsafe",
"mpmath",
"networkx",
"sympy",
]

[[tool.rye.sources]]
name = "pytorch"
url = "https://download.pytorch.org/whl/cpu"

[tool.hatch.metadata]
allow-direct-references = true
87 changes: 87 additions & 0 deletions requirements-dev.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
# generated by rye
# use `rye lock` or `rye sync` to update this lockfile
#
# last locked with the following flags:
# pre: false
# features: []
# all-features: false
# with-sources: false

-e file:.
anyio==4.2.0
# via httpx
# via litestar
certifi==2024.2.2
# via httpcore
# via httpx
click==8.1.7
# via litestar
# via rich-click
# via uvicorn
# faker==23.2.1 (excluded)
# via polyfactory
# filelock==3.13.1 (excluded)
# via torch
# fsspec==2024.2.0 (excluded)
# via torch
h11==0.14.0
# via httpcore
# via uvicorn
httpcore==1.0.3
# via httpx
httpx==0.26.0
# via litestar
idna==3.6
# via anyio
# via httpx
# jinja2==3.1.3 (excluded)
# via torch
litestar==2.6.1
# via silero-tts-api-server
markdown-it-py==3.0.0
# via rich
# markupsafe==2.1.5 (excluded)
# via jinja2
mdurl==0.1.2
# via markdown-it-py
# mpmath==1.3.0 (excluded)
# via sympy
msgspec==0.18.6
# via litestar
multidict==6.0.5
# via litestar
# networkx==3.2.1 (excluded)
# via torch
numpy==1.26.4
# via silero-tts-api-server
# polyfactory==2.14.1 (excluded)
# via litestar
pygments==2.17.2
# via rich
python-dateutil==2.8.2
# via faker
python-dotenv==1.0.1
# via silero-tts-api-server
pyyaml==6.0.1
# via litestar
rich==13.7.0
# via litestar
# via rich-click
rich-click==1.7.3
# via litestar
# six==1.16.0 (excluded)
# via python-dateutil
sniffio==1.3.0
# via anyio
# via httpx
# sympy==1.12 (excluded)
# via torch
torch==2.2.0
# via silero-tts-api-server
typing-extensions==4.9.0
# via litestar
# via polyfactory
# via rich-click
# via torch
uvicorn==0.27.1
# via silero-tts-api-server
87 changes: 87 additions & 0 deletions requirements.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
# generated by rye
# use `rye lock` or `rye sync` to update this lockfile
#
# last locked with the following flags:
# pre: false
# features: []
# all-features: false
# with-sources: false

-e file:.
anyio==4.2.0
# via httpx
# via litestar
certifi==2024.2.2
# via httpcore
# via httpx
click==8.1.7
# via litestar
# via rich-click
# via uvicorn
# faker==23.2.1 (excluded)
# via polyfactory
# filelock==3.13.1 (excluded)
# via torch
# fsspec==2024.2.0 (excluded)
# via torch
h11==0.14.0
# via httpcore
# via uvicorn
httpcore==1.0.3
# via httpx
httpx==0.26.0
# via litestar
idna==3.6
# via anyio
# via httpx
# jinja2==3.1.3 (excluded)
# via torch
litestar==2.6.1
# via silero-tts-api-server
markdown-it-py==3.0.0
# via rich
# markupsafe==2.1.5 (excluded)
# via jinja2
mdurl==0.1.2
# via markdown-it-py
# mpmath==1.3.0 (excluded)
# via sympy
msgspec==0.18.6
# via litestar
multidict==6.0.5
# via litestar
# networkx==3.2.1 (excluded)
# via torch
numpy==1.26.4
# via silero-tts-api-server
# polyfactory==2.14.1 (excluded)
# via litestar
pygments==2.17.2
# via rich
python-dateutil==2.8.2
# via faker
python-dotenv==1.0.1
# via silero-tts-api-server
pyyaml==6.0.1
# via litestar
rich==13.7.0
# via litestar
# via rich-click
rich-click==1.7.3
# via litestar
# six==1.16.0 (excluded)
# via python-dateutil
sniffio==1.3.0
# via anyio
# via httpx
# sympy==1.12 (excluded)
# via torch
torch==2.2.0
# via silero-tts-api-server
typing-extensions==4.9.0
# via litestar
# via polyfactory
# via rich-click
# via torch
uvicorn==0.27.1
# via silero-tts-api-server
8 changes: 0 additions & 8 deletions requirements.txt

This file was deleted.

File renamed without changes.
2 changes: 1 addition & 1 deletion tts.py → tts/tts.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import torch
from torch.package import PackageImporter

from exceptions import *
from tts.exceptions import *

if TYPE_CHECKING:
from .typing.package import TTSModelMultiAcc_v3
Expand Down
File renamed without changes.

0 comments on commit 45b49bb

Please sign in to comment.