SohomToom's picture
Update Dockerfile
f029cb5 verified
raw
history blame
2.41 kB
Great! Here's how to deploy your OpenVoice-based Gradio app on Hugging Face Spaces using Docker.
---
1. Directory Structure
openvoice-gradio-app/
β”œβ”€β”€ app.py
β”œβ”€β”€ Dockerfile
β”œβ”€β”€ requirements.txt
└── README.md (optional)
---
2. app.py
Here's a minimal Gradio interface using OpenVoice:
import gradio as gr
from openvoice import OpenVoice
# Load OpenVoice model (adjust to your setup)
model = OpenVoice(language="en")
def clone_and_speak(audio, text):
output_path = "output.wav"
model.clone_voice(
source_audio_path=audio.name,
target_text=text,
output_path=output_path
)
return output_path
with gr.Blocks() as demo:
gr.Markdown("# OpenVoice TTS - Hugging Face Space")
with gr.Row():
audio_input = gr.Audio(label="Upload voice to clone", type="file")
text_input = gr.Textbox(label="Enter text to synthesize")
with gr.Row():
generate_btn = gr.Button("Generate Audio")
audio_output = gr.Audio(label="Synthesized Output", type="filepath")
generate_btn.click(fn=clone_and_speak, inputs=[audio_input, text_input], outputs=audio_output)
demo.launch()
---
3. requirements.txt
List all necessary dependencies:
gradio
torch
transformers
numpy
# Include the repo name if OpenVoice is pip-installable
# If using local installation, skip and use Dockerfile instead
---
4. Dockerfile
# Use official Python image
FROM python:3.10-slim
# System dependencies
RUN apt-get update && apt-get install -y ffmpeg git && rm -rf /var/lib/apt/lists/*
# Set working directory
WORKDIR /app
# Copy files
COPY . .
# Install Python dependencies
RUN pip install --upgrade pip
RUN pip install -r requirements.txt
# Clone OpenVoice if not pip installable
RUN git clone https://github.com/myshell-ai/OpenVoice.git && \
pip install -e OpenVoice
# Expose port for Gradio
EXPOSE 7860
# Launch the app
CMD ["python", "app.py"]
---
5. Push to Hugging Face Spaces
1. Create a new Space on Hugging Face.
2. Set SDK to Docker.
3. Push your files to the linked repo via Git.
git init
git remote add origin https://huggingface.co/spaces/your-username/openvoice-gradio-app
git add .
git commit -m "Initial commit"
git push -u origin main
---
Let me know if OpenVoice needs special model download steps or GPU setup. I can adjust the Dockerfile accordingly. Would you like GPU support included?