diff --git a/DB.py b/DB.py index ffaaeda..7139bd7 100644 --- a/DB.py +++ b/DB.py @@ -1,8 +1,11 @@ +import os from datetime import datetime +from pathlib import Path import peewee -database = peewee.SqliteDatabase('voice_cache.sqlite') +DB_PATH = Path(os.getenv('DATA_DIR', '.')) / 'voice_cache.sqlite' +database = peewee.SqliteDatabase(str(DB_PATH)) class BaseModel(peewee.Model): diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..0408b87 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,33 @@ +FROM python:3.11-slim as builder + +WORKDIR /app + +ENV PYTHONDONTWRITEBYTECODE 1 +ENV PYTHONUNBUFFERED 1 + +RUN apt update && apt install git gcc -y --no-install-recommends && apt clean && rm -rf /var/lib/apt/lists/* +COPY requirements.txt . +RUN --mount=type=cache,target=/root/.cache/pip pip install Cython && \ + pip wheel --no-deps --wheel-dir /app/wheels -r requirements.txt && \ + pip wheel torch numpy --wheel-dir /app/wheels --index-url https://download.pytorch.org/whl/cpu + + + +FROM python:3.11-slim + +ENV PYTHONDONTWRITEBYTECODE 1 +ENV PYTHONUNBUFFERED 1 + +RUN useradd -ms /bin/bash silero_user +USER silero_user + +WORKDIR /app + +COPY --from=builder /app/wheels /wheels +COPY --from=builder /app/requirements.txt . + +RUN pip install --no-cache /wheels/* + +COPY . . + +CMD ["python3", "/app/main.py"] diff --git a/TTSSilero/TTSSilero.py b/TTSSilero/TTSSilero.py index 41659c8..bfdbd7c 100644 --- a/TTSSilero/TTSSilero.py +++ b/TTSSilero/TTSSilero.py @@ -1,7 +1,9 @@ import contextlib -import os import io +import os import wave +from pathlib import Path + import torch.package from .Speakers import Speakers @@ -12,12 +14,12 @@ class TTSSilero: def __init__(self, threads: int = 12): device = torch.device('cpu') torch.set_num_threads(threads) - local_file = 'model_multi.pt' + local_file = Path(os.getenv('DATA_DIR', '.')) / 'model_multi.pt' if not os.path.isfile(local_file): torch.hub.download_url_to_file( 'https://models.silero.ai/models/tts/multi/v2_multi.pt', - local_file + str(local_file) ) self.model: TTSModelMulti_v2 = torch.package.PackageImporter(local_file).load_pickle("tts_models", "model") diff --git a/main.py b/main.py index 03741b8..c780019 100644 --- a/main.py +++ b/main.py @@ -8,8 +8,10 @@ from loguru import logger from DynamicCommandPrefix import dynamic_command_prefix import Observ +LOG_FILE_ENABLED = os.getenv('LOG_FILE_ENABLED', 'true').lower() == 'true' -logger.add('offlineTTSBot.log', backtrace=True, diagnose=False, rotation='5MB') +if LOG_FILE_ENABLED: + logger.add('offlineTTSBot.log', backtrace=True, diagnose=False, rotation='5MB') """ while msg := input('$ '): diff --git a/requirements.txt b/requirements.txt index 16b6b1f..e73a1e5 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,7 +2,4 @@ discord-py loguru~=0.6.0 peewee~=3.14.10 PyNaCl -Cython -torch -numpy -git+https://github.com/aaiyer/rfoo.git \ No newline at end of file +git+https://github.com/aaiyer/rfoo.git