Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from playdiffusion import PlayDiffusion, RVCInput
|
| 3 |
+
import os
|
| 4 |
+
import wget
|
| 5 |
+
|
| 6 |
+
# --- Model Downloading ---
|
| 7 |
+
print("--- Checking and Downloading Model Assets ---")
|
| 8 |
+
MODEL_FILES = {
|
| 9 |
+
"kmeans_10k.npy": "https://huggingface.co/PlayHT/PlayDiffusion/resolve/main/kmeans_10k.npy",
|
| 10 |
+
"last_250k_fixed.pkl": "https://huggingface.co/PlayHT/PlayDiffusion/resolve/main/last_250k_fixed.pkl",
|
| 11 |
+
"tokenizer-multi_bpe16384_merged_extended_58M.json": "https://huggingface.co/PlayHT/PlayDiffusion/resolve/main/tokenizer-multi_bpe16384_merged_extended_58M.json",
|
| 12 |
+
"v090_g_01105000": "https://huggingface.co/PlayHT/PlayDiffusion/resolve/main/v090_g_01105000",
|
| 13 |
+
"voice_encoder_1992000.pt": "https://huggingface.co/PlayHT/PlayDiffusion/resolve/main/voice_encoder_1992000.pt",
|
| 14 |
+
"xlsr2_1b_v2_custom.pt": "https://huggingface.co/PlayHT/PlayDiffusion/resolve/main/xlsr2_1b_v2_custom.pt"
|
| 15 |
+
}
|
| 16 |
+
|
| 17 |
+
for filename, url in MODEL_FILES.items():
|
| 18 |
+
if not os.path.exists(filename):
|
| 19 |
+
print(f"Downloading {filename}...")
|
| 20 |
+
wget.download(url, filename)
|
| 21 |
+
else:
|
| 22 |
+
print(f"{filename} already exists. Skipping download.")
|
| 23 |
+
|
| 24 |
+
# --- Gradio App ---
|
| 25 |
+
print("Initializing PlayDiffusion... This will load the models into memory.")
|
| 26 |
+
inpainter = PlayDiffusion()
|
| 27 |
+
print("PlayDiffusion initialized successfully.")
|
| 28 |
+
|
| 29 |
+
def speech_rvc(rvc_source_speech, rvc_target_voice):
|
| 30 |
+
if rvc_source_speech is None or rvc_target_voice is None:
|
| 31 |
+
raise gr.Error("Please provide both a source speech audio and a target voice audio.")
|
| 32 |
+
print("Starting voice conversion...")
|
| 33 |
+
converted_audio = inpainter.rvc(RVCInput(source_speech=rvc_source_speech, target_voice=rvc_target_voice))
|
| 34 |
+
print("Voice conversion finished.")
|
| 35 |
+
return converted_audio
|
| 36 |
+
|
| 37 |
+
with gr.Blocks(theme=gr.themes.Soft(), title="PlayDiffusion Voice Conversion") as demo:
|
| 38 |
+
gr.Markdown("# π£οΈ PlayDiffusion Voice Conversion")
|
| 39 |
+
gr.Markdown("Upload a **Source Speech** audio and a **Target Voice** audio to convert the speech.")
|
| 40 |
+
|
| 41 |
+
with gr.Row():
|
| 42 |
+
rvc_source_speech = gr.Audio(label="Source Speech", sources=["upload", "microphone"], type="filepath")
|
| 43 |
+
rvc_target_voice = gr.Audio(label="Target Voice", sources=["upload", "microphone"], type="filepath")
|
| 44 |
+
|
| 45 |
+
rvc_submit = gr.Button("π Run Voice Conversion", variant="primary")
|
| 46 |
+
gr.Markdown("### Converted Speech Output")
|
| 47 |
+
rvc_output = gr.Audio(label="Result", interactive=False)
|
| 48 |
+
|
| 49 |
+
rvc_submit.click(fn=speech_rvc, inputs=[rvc_source_speech, rvc_target_voice], outputs=[rvc_output])
|
| 50 |
+
|
| 51 |
+
demo.launch()
|