File size: 2,707 Bytes
a287c67
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
145b730
a287c67
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
145b730
a287c67
 
 
 
 
 
 
 
 
 
 
 
 
8cbe037
 
 
a287c67
 
8cbe037
a287c67
 
 
 
 
 
 
8cbe037
 
a287c67
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# Genie-TTS OpenAI Compatible API - Docker Image
# ================================================
# This Dockerfile builds a container that:
# 1. Downloads PyTorch model files (.pth, .ckpt) from cloud URLs
# 2. Converts them to ONNX format
# 3. Runs the OpenAI-compatible TTS API server

FROM python:3.10-slim

# Set environment variables
ENV PYTHONUNBUFFERED=1 \
    PYTHONDONTWRITEBYTECODE=1 \
    PIP_NO_CACHE_DIR=1 \
    PIP_DISABLE_PIP_VERSION_CHECK=1 \
    DEBIAN_FRONTEND=noninteractive \
    MODELS_DIR=/app/models \
    GENIE_DATA_DIR=/app/GenieData

# Install system dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
    build-essential \
    libsndfile1 \
    ffmpeg \
    wget \
    curl \
    git \
    && rm -rf /var/lib/apt/lists/*

# Create app directory
WORKDIR /app

# Copy requirements first for better caching
COPY requirements.txt .

# Install Python dependencies (including torch for model conversion)
RUN pip install --no-cache-dir -r requirements.txt

# Install PyTorch (CPU version for model conversion)
RUN pip install --no-cache-dir torch --index-url https://download.pytorch.org/whl/cpu

# Install genie-tts from source or pip
# Option 1: Install from pip
RUN pip install --no-cache-dir genie-tts

# Create directories
RUN mkdir -p /app/models/liang/onnx \
    && mkdir -p /app/models/liang/reference \
    && mkdir -p /app/GenieData \
    && mkdir -p /app/temp

# Download model files
# Model: liang (Chinese V2ProPlus)
RUN echo "Downloading model files..." && \
    wget -q --show-progress -O /app/temp/model.ckpt \
    "https://22333misaka-openlist.hf.space/d/od/shantianliang_proplus_e32.ckpt" && \
    wget -q --show-progress -O /app/temp/model.pth \
    "https://22333misaka-openlist.hf.space/d/od/shantianliang_proplus_e8_s192.pth" && \
    wget -q --show-progress -O /app/models/liang/reference/audio.wav \
    "https://22333misaka-openlist.hf.space/d/od/ref_shantianliang_1.wav" && \
    echo "Download complete!"

# Copy conversion script
COPY convert_model.py .

# Convert PyTorch models to ONNX
RUN echo "Converting models to ONNX format..." && \
    python convert_model.py && \
    echo "Conversion complete!"

# Clean up temporary files and torch to reduce image size
RUN rm -rf /app/temp && \
    pip uninstall -y torch && \
    rm -rf /root/.cache/pip

# Copy model configuration
COPY models/liang/config.json /app/models/liang/config.json

# Copy application code
COPY app.py .

# Expose port (Hugging Face Spaces uses 7860)
EXPOSE 7860

# Health check
HEALTHCHECK --interval=30s --timeout=30s --start-period=60s --retries=3 \
    CMD curl -f http://localhost:7860/health || exit 1

# Run the application
CMD ["python", "app.py"]