Spaces:
Sleeping
Sleeping
Commit
·
aeff66c
1
Parent(s):
e76369a
Fix Gradio app deployment issues
Browse files- Dockerfile +7 -1
- app.py +47 -19
- requirements-hf.txt +1 -1
Dockerfile
CHANGED
|
@@ -2,11 +2,11 @@ FROM python:3.10-slim
|
|
| 2 |
|
| 3 |
WORKDIR /app
|
| 4 |
|
| 5 |
-
# Install system dependencies
|
| 6 |
RUN apt-get update && apt-get install -y \
|
| 7 |
build-essential \
|
| 8 |
ffmpeg \
|
| 9 |
git \
|
|
|
|
| 10 |
&& rm -rf /var/lib/apt/lists/*
|
| 11 |
|
| 12 |
# Copy requirements first for better caching
|
|
@@ -22,9 +22,15 @@ COPY . .
|
|
| 22 |
ENV PYTHONPATH=/app
|
| 23 |
ENV GRADIO_SERVER_NAME=0.0.0.0
|
| 24 |
ENV GRADIO_SERVER_PORT=7860
|
|
|
|
|
|
|
| 25 |
|
| 26 |
# Expose the port
|
| 27 |
EXPOSE 7860
|
| 28 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
# Run the application
|
| 30 |
CMD ["python", "app.py"]
|
|
|
|
| 2 |
|
| 3 |
WORKDIR /app
|
| 4 |
|
|
|
|
| 5 |
RUN apt-get update && apt-get install -y \
|
| 6 |
build-essential \
|
| 7 |
ffmpeg \
|
| 8 |
git \
|
| 9 |
+
curl \
|
| 10 |
&& rm -rf /var/lib/apt/lists/*
|
| 11 |
|
| 12 |
# Copy requirements first for better caching
|
|
|
|
| 22 |
ENV PYTHONPATH=/app
|
| 23 |
ENV GRADIO_SERVER_NAME=0.0.0.0
|
| 24 |
ENV GRADIO_SERVER_PORT=7860
|
| 25 |
+
ENV HOST=0.0.0.0
|
| 26 |
+
ENV PORT=7860
|
| 27 |
|
| 28 |
# Expose the port
|
| 29 |
EXPOSE 7860
|
| 30 |
|
| 31 |
+
# Health check
|
| 32 |
+
HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 \
|
| 33 |
+
CMD curl -f http://localhost:7860/ || exit 1
|
| 34 |
+
|
| 35 |
# Run the application
|
| 36 |
CMD ["python", "app.py"]
|
app.py
CHANGED
|
@@ -1,5 +1,6 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import numpy as np
|
|
|
|
| 3 |
|
| 4 |
def synthesize_speech(text, speaker_id=0):
|
| 5 |
"""
|
|
@@ -33,7 +34,15 @@ def synthesize_speech(text, speaker_id=0):
|
|
| 33 |
return (sample_rate, audio.astype(np.float32))
|
| 34 |
|
| 35 |
def create_demo():
|
| 36 |
-
with gr.Blocks(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
gr.Markdown(
|
| 38 |
"""
|
| 39 |
# 🎤 Learnable-Speech: High-Quality 24kHz Speech Synthesis
|
|
@@ -135,19 +144,20 @@ def create_demo():
|
|
| 135 |
"""
|
| 136 |
)
|
| 137 |
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
|
|
|
| 151 |
|
| 152 |
generate_btn.click(
|
| 153 |
fn=synthesize_speech,
|
|
@@ -158,9 +168,27 @@ def create_demo():
|
|
| 158 |
return demo
|
| 159 |
|
| 160 |
if __name__ == "__main__":
|
|
|
|
|
|
|
|
|
|
|
|
|
| 161 |
demo = create_demo()
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import numpy as np
|
| 3 |
+
import os
|
| 4 |
|
| 5 |
def synthesize_speech(text, speaker_id=0):
|
| 6 |
"""
|
|
|
|
| 34 |
return (sample_rate, audio.astype(np.float32))
|
| 35 |
|
| 36 |
def create_demo():
|
| 37 |
+
with gr.Blocks(
|
| 38 |
+
title="Learnable-Speech Demo",
|
| 39 |
+
theme=gr.themes.Default(),
|
| 40 |
+
css="""
|
| 41 |
+
.gradio-container {
|
| 42 |
+
max-width: 1200px !important;
|
| 43 |
+
}
|
| 44 |
+
"""
|
| 45 |
+
) as demo:
|
| 46 |
gr.Markdown(
|
| 47 |
"""
|
| 48 |
# 🎤 Learnable-Speech: High-Quality 24kHz Speech Synthesis
|
|
|
|
| 144 |
"""
|
| 145 |
)
|
| 146 |
|
| 147 |
+
with gr.Row():
|
| 148 |
+
gr.Examples(
|
| 149 |
+
examples=[
|
| 150 |
+
["Hello everyone! I am here to tell you that Learnable-Speech is amazing!"],
|
| 151 |
+
["The Secret Service believed that it was very doubtful that any President would ride regularly in a vehicle."],
|
| 152 |
+
["We propose Learnable-Speech, a new approach to neural text-to-speech synthesis."],
|
| 153 |
+
["This implementation uses flow matching for high-quality 24kHz audio generation."],
|
| 154 |
+
],
|
| 155 |
+
inputs=[text_input],
|
| 156 |
+
fn=lambda x: synthesize_speech(x, 0),
|
| 157 |
+
outputs=audio_output,
|
| 158 |
+
cache_examples=False,
|
| 159 |
+
label="Example Texts"
|
| 160 |
+
)
|
| 161 |
|
| 162 |
generate_btn.click(
|
| 163 |
fn=synthesize_speech,
|
|
|
|
| 168 |
return demo
|
| 169 |
|
| 170 |
if __name__ == "__main__":
|
| 171 |
+
# Get environment variables for flexible deployment
|
| 172 |
+
port = int(os.environ.get("PORT", 7860))
|
| 173 |
+
host = os.environ.get("HOST", "0.0.0.0")
|
| 174 |
+
|
| 175 |
demo = create_demo()
|
| 176 |
+
|
| 177 |
+
# Try to launch with error handling
|
| 178 |
+
try:
|
| 179 |
+
demo.launch(
|
| 180 |
+
server_name=host,
|
| 181 |
+
server_port=port,
|
| 182 |
+
share=False,
|
| 183 |
+
show_error=True,
|
| 184 |
+
quiet=False,
|
| 185 |
+
enable_queue=True
|
| 186 |
+
)
|
| 187 |
+
except Exception as e:
|
| 188 |
+
print(f"Failed to launch on {host}:{port}, trying with share=True")
|
| 189 |
+
demo.launch(
|
| 190 |
+
share=True,
|
| 191 |
+
show_error=True,
|
| 192 |
+
quiet=False,
|
| 193 |
+
enable_queue=True
|
| 194 |
+
)
|
requirements-hf.txt
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
gradio==
|
| 2 |
torch==2.1.0
|
| 3 |
torchaudio==2.1.0
|
| 4 |
numpy==1.24.3
|
|
|
|
| 1 |
+
gradio==3.50.2
|
| 2 |
torch==2.1.0
|
| 3 |
torchaudio==2.1.0
|
| 4 |
numpy==1.24.3
|