Dockerized

This commit is contained in:
norohind 2023-08-09 22:42:12 +03:00
parent d23ef5b2fa
commit 71e18a595f
Signed by: norohind
GPG Key ID: 01C3BECC26FB59E1
5 changed files with 46 additions and 9 deletions

5
DB.py
View File

@ -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):

33
Dockerfile Normal file
View File

@ -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"]

View File

@ -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")

View File

@ -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('$ '):

View File

@ -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
git+https://github.com/aaiyer/rfoo.git