File size: 2,406 Bytes
f029cb5 40d5f8f f029cb5 |
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 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
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?
|