Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -4,7 +4,7 @@ import numpy as np
|
|
4 |
import torch
|
5 |
from infer_rvc_python import BaseLoader
|
6 |
|
7 |
-
# Initialize the audio transformation model
|
8 |
converter = BaseLoader(only_cpu=False, hubert_path=None, rmvpe_path=None)
|
9 |
|
10 |
# Path to the models directory
|
@@ -27,12 +27,12 @@ def configure_model(file_model, file_index):
|
|
27 |
consonant_breath_protection=0.5,
|
28 |
resample_sr=44100
|
29 |
)
|
30 |
-
return "Model configured successfully."
|
31 |
|
32 |
# Function to process each audio chunk
|
33 |
-
def transform_audio_chunk(audio
|
34 |
if audio is None:
|
35 |
-
return None
|
36 |
|
37 |
audio_data = torch.tensor(audio[1], dtype=torch.float32).unsqueeze(0) # Prepare audio for processing
|
38 |
with torch.no_grad():
|
@@ -41,12 +41,7 @@ def transform_audio_chunk(audio, instream):
|
|
41 |
tag="live_transform",
|
42 |
)
|
43 |
|
44 |
-
|
45 |
-
if instream is None:
|
46 |
-
return (audio[0], transformed_audio.squeeze(0).numpy()), (audio[0], transformed_audio.squeeze(0).numpy())
|
47 |
-
else:
|
48 |
-
new_stream = np.concatenate((instream[1], transformed_audio.squeeze(0).numpy()))
|
49 |
-
return (audio[0], new_stream), (audio[0], new_stream)
|
50 |
|
51 |
# Gradio interface setup
|
52 |
with gr.Blocks() as demo:
|
@@ -59,18 +54,16 @@ with gr.Blocks() as demo:
|
|
59 |
index_file = gr.Dropdown(choices=index_files, label="Select Index File")
|
60 |
configure_button = gr.Button("Configure Model")
|
61 |
|
62 |
-
# Audio input component with streaming enabled
|
63 |
-
inp = gr.Audio(sources="microphone", streaming=True, type="numpy"
|
64 |
# Audio output component to play back the transformed audio
|
65 |
-
out = gr.Audio(
|
66 |
-
|
67 |
-
stream = gr.State()
|
68 |
-
|
69 |
# Link the input to the processing function and output
|
70 |
-
inp.stream(transform_audio_chunk, [inp
|
71 |
|
72 |
# Link the model configuration button to the configure_model function
|
73 |
-
configure_button.click(configure_model, inputs=[model_file, index_file], outputs=[
|
74 |
|
75 |
if __name__ == "__main__":
|
76 |
demo.launch()
|
|
|
4 |
import torch
|
5 |
from infer_rvc_python import BaseLoader
|
6 |
|
7 |
+
# Initialize the audio transformation model
|
8 |
converter = BaseLoader(only_cpu=False, hubert_path=None, rmvpe_path=None)
|
9 |
|
10 |
# Path to the models directory
|
|
|
27 |
consonant_breath_protection=0.5,
|
28 |
resample_sr=44100
|
29 |
)
|
30 |
+
return "Model configured successfully."
|
31 |
|
32 |
# Function to process each audio chunk
|
33 |
+
def transform_audio_chunk(audio):
|
34 |
if audio is None:
|
35 |
+
return None
|
36 |
|
37 |
audio_data = torch.tensor(audio[1], dtype=torch.float32).unsqueeze(0) # Prepare audio for processing
|
38 |
with torch.no_grad():
|
|
|
41 |
tag="live_transform",
|
42 |
)
|
43 |
|
44 |
+
return audio[0], transformed_audio.squeeze(0).numpy()
|
|
|
|
|
|
|
|
|
|
|
45 |
|
46 |
# Gradio interface setup
|
47 |
with gr.Blocks() as demo:
|
|
|
54 |
index_file = gr.Dropdown(choices=index_files, label="Select Index File")
|
55 |
configure_button = gr.Button("Configure Model")
|
56 |
|
57 |
+
# Audio input component with streaming enabled
|
58 |
+
inp = gr.Audio(sources="microphone", streaming=True, type="numpy")
|
59 |
# Audio output component to play back the transformed audio
|
60 |
+
out = gr.Audio()
|
61 |
+
|
|
|
|
|
62 |
# Link the input to the processing function and output
|
63 |
+
inp.stream(transform_audio_chunk, inputs=[inp], outputs=[out])
|
64 |
|
65 |
# Link the model configuration button to the configure_model function
|
66 |
+
configure_button.click(configure_model, inputs=[model_file, index_file], outputs=[])
|
67 |
|
68 |
if __name__ == "__main__":
|
69 |
demo.launch()
|