Spaces:
Build error
Build error
Ashish Kumar
commited on
Commit
·
4f2aafb
1
Parent(s):
555d90e
Initial commit: Kokoro TTS app with Railway deployment support
Browse files- .dockerignore +16 -0
- .gitignore +13 -0
- Dockerfile +35 -0
- app.py +24 -5
- railway.json +12 -0
- requirements.txt +4 -1
.dockerignore
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
venv/
|
| 2 |
+
__pycache__/
|
| 3 |
+
*.pyc
|
| 4 |
+
*.pyo
|
| 5 |
+
*.pyd
|
| 6 |
+
.Python
|
| 7 |
+
.env
|
| 8 |
+
.git
|
| 9 |
+
.gitignore
|
| 10 |
+
.vscode
|
| 11 |
+
.idea
|
| 12 |
+
*.log
|
| 13 |
+
*.swp
|
| 14 |
+
*.swo
|
| 15 |
+
*~
|
| 16 |
+
.DS_Store
|
.gitignore
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
venv/
|
| 2 |
+
__pycache__/
|
| 3 |
+
*.pyc
|
| 4 |
+
*.pyo
|
| 5 |
+
*.pyd
|
| 6 |
+
.Python
|
| 7 |
+
.env
|
| 8 |
+
*.log
|
| 9 |
+
*.swp
|
| 10 |
+
*.swo
|
| 11 |
+
*~
|
| 12 |
+
.DS_Store
|
| 13 |
+
.cache/
|
Dockerfile
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Use Python 3.11 slim image
|
| 2 |
+
FROM python:3.11-slim
|
| 3 |
+
|
| 4 |
+
# Set working directory
|
| 5 |
+
WORKDIR /app
|
| 6 |
+
|
| 7 |
+
# Install system dependencies
|
| 8 |
+
RUN apt-get update && apt-get install -y \
|
| 9 |
+
espeak-ng \
|
| 10 |
+
git \
|
| 11 |
+
&& rm -rf /var/lib/apt/lists/*
|
| 12 |
+
|
| 13 |
+
# Copy requirements file
|
| 14 |
+
COPY requirements.txt .
|
| 15 |
+
|
| 16 |
+
# Install Python dependencies
|
| 17 |
+
RUN pip install --no-cache-dir --upgrade pip && \
|
| 18 |
+
pip install --no-cache-dir -r requirements.txt
|
| 19 |
+
|
| 20 |
+
# Copy application files
|
| 21 |
+
COPY app.py .
|
| 22 |
+
COPY en.txt .
|
| 23 |
+
COPY frankenstein5k.md .
|
| 24 |
+
COPY gatsby5k.md .
|
| 25 |
+
COPY README.md .
|
| 26 |
+
|
| 27 |
+
# Expose port (Railway will override PORT env var)
|
| 28 |
+
EXPOSE 7860
|
| 29 |
+
|
| 30 |
+
# Set environment variables
|
| 31 |
+
ENV PYTHONUNBUFFERED=1
|
| 32 |
+
ENV GRADIO_SERVER_NAME=0.0.0.0
|
| 33 |
+
|
| 34 |
+
# Run the application
|
| 35 |
+
CMD ["python", "app.py"]
|
app.py
CHANGED
|
@@ -1,4 +1,17 @@
|
|
| 1 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
from kokoro import KModel, KPipeline
|
| 3 |
import gradio as gr
|
| 4 |
import os
|
|
@@ -8,9 +21,12 @@ import torch
|
|
| 8 |
IS_DUPLICATE = not os.getenv('SPACE_ID', '').startswith('hexgrad/')
|
| 9 |
CUDA_AVAILABLE = torch.cuda.is_available()
|
| 10 |
if not IS_DUPLICATE:
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
CHAR_LIMIT = None if IS_DUPLICATE else 5000
|
| 16 |
models = {gpu: KModel().to('cuda' if gpu else 'cpu').eval() for gpu in [False] + ([True] if CUDA_AVAILABLE else [])}
|
|
@@ -199,4 +215,7 @@ with gr.Blocks() as app:
|
|
| 199 |
predict_btn.click(fn=predict, inputs=[text, voice, speed], outputs=[out_audio], api_name=API_NAME)
|
| 200 |
|
| 201 |
if __name__ == '__main__':
|
| 202 |
-
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Handle spaces dependency for localhost
|
| 2 |
+
try:
|
| 3 |
+
import spaces
|
| 4 |
+
SPACES_AVAILABLE = True
|
| 5 |
+
except ImportError:
|
| 6 |
+
# Mock spaces for localhost
|
| 7 |
+
class spaces:
|
| 8 |
+
class GPU:
|
| 9 |
+
def __init__(self, duration=None):
|
| 10 |
+
pass
|
| 11 |
+
def __call__(self, func):
|
| 12 |
+
return func
|
| 13 |
+
SPACES_AVAILABLE = False
|
| 14 |
+
|
| 15 |
from kokoro import KModel, KPipeline
|
| 16 |
import gradio as gr
|
| 17 |
import os
|
|
|
|
| 21 |
IS_DUPLICATE = not os.getenv('SPACE_ID', '').startswith('hexgrad/')
|
| 22 |
CUDA_AVAILABLE = torch.cuda.is_available()
|
| 23 |
if not IS_DUPLICATE:
|
| 24 |
+
try:
|
| 25 |
+
import kokoro
|
| 26 |
+
import misaki
|
| 27 |
+
print('DEBUG', kokoro.__version__, CUDA_AVAILABLE, misaki.__version__)
|
| 28 |
+
except ImportError:
|
| 29 |
+
print('DEBUG: kokoro/misaki version info not available')
|
| 30 |
|
| 31 |
CHAR_LIMIT = None if IS_DUPLICATE else 5000
|
| 32 |
models = {gpu: KModel().to('cuda' if gpu else 'cpu').eval() for gpu in [False] + ([True] if CUDA_AVAILABLE else [])}
|
|
|
|
| 215 |
predict_btn.click(fn=predict, inputs=[text, voice, speed], outputs=[out_audio], api_name=API_NAME)
|
| 216 |
|
| 217 |
if __name__ == '__main__':
|
| 218 |
+
# Get port from environment variable (Railway/cloud platforms) or default to 7860
|
| 219 |
+
port = int(os.getenv('PORT', 7860))
|
| 220 |
+
# For localhost and cloud, launch with server_name 0.0.0.0 to allow access from network
|
| 221 |
+
app.queue(api_open=API_OPEN).launch(show_api=API_OPEN, ssr_mode=True, server_name='0.0.0.0', server_port=port)
|
railway.json
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"$schema": "https://railway.app/railway.schema.json",
|
| 3 |
+
"build": {
|
| 4 |
+
"builder": "DOCKERFILE",
|
| 5 |
+
"dockerfilePath": "Dockerfile"
|
| 6 |
+
},
|
| 7 |
+
"deploy": {
|
| 8 |
+
"startCommand": "python app.py",
|
| 9 |
+
"restartPolicyType": "ON_FAILURE",
|
| 10 |
+
"restartPolicyMaxRetries": 10
|
| 11 |
+
}
|
| 12 |
+
}
|
requirements.txt
CHANGED
|
@@ -1 +1,4 @@
|
|
| 1 |
-
kokoro>=0.9.4
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
kokoro>=0.9.4
|
| 2 |
+
gradio>=5.24.0
|
| 3 |
+
torch
|
| 4 |
+
numpy
|