Update app.py
Browse files
app.py
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
|
|
| 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 ---")
|
|
@@ -21,10 +23,20 @@ for filename, url in MODEL_FILES.items():
|
|
| 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 |
-
|
|
|
|
|
|
|
|
|
|
| 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:
|
|
@@ -34,9 +46,13 @@ def speech_rvc(rvc_source_speech, 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")
|
|
@@ -48,4 +64,5 @@ with gr.Blocks(theme=gr.themes.Soft(), title="PlayDiffusion Voice Conversion") a
|
|
| 48 |
|
| 49 |
rvc_submit.click(fn=speech_rvc, inputs=[rvc_source_speech, rvc_target_voice], outputs=[rvc_output])
|
| 50 |
|
|
|
|
| 51 |
demo.launch()
|
|
|
|
| 1 |
+
# app.py
|
| 2 |
import gradio as gr
|
| 3 |
from playdiffusion import PlayDiffusion, RVCInput
|
| 4 |
import os
|
| 5 |
import wget
|
| 6 |
+
import torch # Import torch to check for CUDA availability
|
| 7 |
|
| 8 |
# --- Model Downloading ---
|
| 9 |
print("--- Checking and Downloading Model Assets ---")
|
|
|
|
| 23 |
else:
|
| 24 |
print(f"{filename} already exists. Skipping download.")
|
| 25 |
|
| 26 |
+
|
| 27 |
# --- Gradio App ---
|
| 28 |
+
# --- KEY CHANGE: Force the model to load on the CPU ---
|
| 29 |
+
# Check if a GPU is available, otherwise default to CPU
|
| 30 |
+
device = 'cuda' if torch.cuda.is_available() else 'cpu'
|
| 31 |
+
print(f"--- Device selected: {device.upper()} ---")
|
| 32 |
print("Initializing PlayDiffusion... This will load the models into memory.")
|
| 33 |
+
|
| 34 |
+
# Pass the selected device to the PlayDiffusion constructor
|
| 35 |
+
inpainter = PlayDiffusion(device=device)
|
| 36 |
+
|
| 37 |
print("PlayDiffusion initialized successfully.")
|
| 38 |
+
# ----------------------------------------------------
|
| 39 |
+
|
| 40 |
|
| 41 |
def speech_rvc(rvc_source_speech, rvc_target_voice):
|
| 42 |
if rvc_source_speech is None or rvc_target_voice is None:
|
|
|
|
| 46 |
print("Voice conversion finished.")
|
| 47 |
return converted_audio
|
| 48 |
|
| 49 |
+
|
| 50 |
with gr.Blocks(theme=gr.themes.Soft(), title="PlayDiffusion Voice Conversion") as demo:
|
| 51 |
gr.Markdown("# π£οΈ PlayDiffusion Voice Conversion")
|
| 52 |
+
gr.Markdown(f"### Running on: **{device.upper()}**")
|
| 53 |
gr.Markdown("Upload a **Source Speech** audio and a **Target Voice** audio to convert the speech.")
|
| 54 |
+
if device == 'cpu':
|
| 55 |
+
gr.Warning("Running on CPU. The voice conversion process will be extremely slow and may time out.")
|
| 56 |
|
| 57 |
with gr.Row():
|
| 58 |
rvc_source_speech = gr.Audio(label="Source Speech", sources=["upload", "microphone"], type="filepath")
|
|
|
|
| 64 |
|
| 65 |
rvc_submit.click(fn=speech_rvc, inputs=[rvc_source_speech, rvc_target_voice], outputs=[rvc_output])
|
| 66 |
|
| 67 |
+
|
| 68 |
demo.launch()
|