Spaces:
Running
Running
Upload 4 files
Browse files- README.md +14 -14
- app.py +153 -139
- requirements.txt +2 -1
README.md
CHANGED
@@ -1,15 +1,15 @@
|
|
1 |
-
---
|
2 |
-
title: Rvc Inferpy
|
3 |
-
emoji: π
|
4 |
-
colorFrom: purple
|
5 |
-
colorTo: yellow
|
6 |
-
sdk: gradio
|
7 |
-
sdk_version:
|
8 |
-
app_file: app.py
|
9 |
-
pinned: true
|
10 |
-
license: apache-2.0
|
11 |
-
|
12 |
-
short_description: A easy to use rvc Fork
|
13 |
-
---
|
14 |
-
|
15 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
1 |
+
---
|
2 |
+
title: Rvc Inferpy
|
3 |
+
emoji: π
|
4 |
+
colorFrom: purple
|
5 |
+
colorTo: yellow
|
6 |
+
sdk: gradio
|
7 |
+
sdk_version: 4.44.0
|
8 |
+
app_file: app.py
|
9 |
+
pinned: true
|
10 |
+
license: apache-2.0
|
11 |
+
|
12 |
+
short_description: A easy to use rvc Fork
|
13 |
+
---
|
14 |
+
|
15 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app.py
CHANGED
@@ -1,139 +1,153 @@
|
|
1 |
-
import gradio as gr
|
2 |
-
from rvc_inferpy import infer_audio
|
3 |
-
import os
|
4 |
-
import zipfile
|
5 |
-
import shutil
|
6 |
-
import urllib.request
|
7 |
-
import gdown
|
8 |
-
|
9 |
-
main_dir = os.getcwd()
|
10 |
-
models_dir = os.path.join(main_dir, "models")
|
11 |
-
|
12 |
-
|
13 |
-
audio_files=[]
|
14 |
-
for filename in os.listdir("./audios"):
|
15 |
-
if filename.endswith(('.wav','.mp3','.ogg','.flac','.m4a','.aac','.mp4')):
|
16 |
-
audio_files.append(os.path.join('./audios',filename).replace('\\', '/'))
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
if
|
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 |
-
return
|
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 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
)
|
125 |
-
|
126 |
-
|
127 |
-
with gr.Row():
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from rvc_inferpy import infer_audio
|
3 |
+
import os
|
4 |
+
import zipfile
|
5 |
+
import shutil
|
6 |
+
import urllib.request
|
7 |
+
import gdown
|
8 |
+
|
9 |
+
main_dir = os.getcwd()
|
10 |
+
models_dir = os.path.join(main_dir, "models")
|
11 |
+
os.makedirs(models_dir, exist_ok=True)
|
12 |
+
|
13 |
+
audio_files=[]
|
14 |
+
for filename in os.listdir("./audios"):
|
15 |
+
if filename.endswith(('.wav','.mp3','.ogg','.flac','.m4a','.aac','.mp4')):
|
16 |
+
audio_files.append(os.path.join('./audios',filename).replace('\\', '/'))
|
17 |
+
|
18 |
+
def extract_zip(extraction_folder, zip_name):
|
19 |
+
os.makedirs(extraction_folder, exist_ok=True)
|
20 |
+
with zipfile.ZipFile(zip_name, 'r') as zip_ref:
|
21 |
+
zip_ref.extractall(extraction_folder)
|
22 |
+
os.remove(zip_name)
|
23 |
+
|
24 |
+
index_filepath, model_filepath = None, None
|
25 |
+
for root, dirs, files in os.walk(extraction_folder):
|
26 |
+
for name in files:
|
27 |
+
if name.endswith('.index') and os.stat(os.path.join(root, name)).st_size > 1024 * 100:
|
28 |
+
index_filepath = os.path.join(root, name)
|
29 |
+
if name.endswith('.pth') and os.stat(os.path.join(root, name)).st_size > 1024 * 1024 * 40:
|
30 |
+
model_filepath = os.path.join(root, name)
|
31 |
+
|
32 |
+
if not model_filepath:
|
33 |
+
raise Exception(f'No .pth model file was found in the extracted zip. Please check {extraction_folder}.')
|
34 |
+
|
35 |
+
os.rename(model_filepath, os.path.join(extraction_folder, os.path.basename(model_filepath)))
|
36 |
+
if index_filepath:
|
37 |
+
os.rename(index_filepath, os.path.join(extraction_folder, os.path.basename(index_filepath)))
|
38 |
+
|
39 |
+
for filepath in os.listdir(extraction_folder):
|
40 |
+
if os.path.isdir(os.path.join(extraction_folder, filepath)):
|
41 |
+
shutil.rmtree(os.path.join(extraction_folder, filepath))
|
42 |
+
|
43 |
+
def download_online_model(url, dir_name):
|
44 |
+
try:
|
45 |
+
print(f'[~] Downloading voice model with name {dir_name}...')
|
46 |
+
zip_name = dir_name + ".zip"
|
47 |
+
extraction_folder = os.path.join(models_dir, dir_name)
|
48 |
+
if os.path.exists(extraction_folder):
|
49 |
+
raise Exception(f'Voice model directory {dir_name} already exists! Choose a different name.')
|
50 |
+
|
51 |
+
if 'drive.google.com' in url:
|
52 |
+
gdown.download(url, output=zip_name, use_cookies=True, quiet=True, fuzzy=True)
|
53 |
+
else:
|
54 |
+
urllib.request.urlretrieve(url, zip_name)
|
55 |
+
|
56 |
+
print('[~] Extracting zip file...')
|
57 |
+
extract_zip(extraction_folder, zip_name)
|
58 |
+
print(f'[+] {dir_name} Model successfully downloaded!')
|
59 |
+
|
60 |
+
except Exception as e:
|
61 |
+
raise Exception(str(e))
|
62 |
+
|
63 |
+
def process_audio(model_name, sound_path, f0_change, f0_method, output_format):
|
64 |
+
try:
|
65 |
+
print(model_name, sound_path, f0_change, f0_method, output_format) #
|
66 |
+
# https://github.com/TheNeodev/rvc_inferpy/tree/main?tab=readme-ov-file#as-a-dependency-in-a-python-project <= wrong
|
67 |
+
# https://github.com/TheNeodev/rvc_inferpy/blob/main/rvc_inferpy/infer.py#L117 <= correct
|
68 |
+
inferred_audio = infer_audio(
|
69 |
+
model_name=model_name,
|
70 |
+
audio_path=sound_path,
|
71 |
+
f0_change=f0_change,
|
72 |
+
f0_method=f0_method
|
73 |
+
)
|
74 |
+
# You might need additional logic for handling output_format here
|
75 |
+
return inferred_audio
|
76 |
+
except Exception as e:
|
77 |
+
print(e)
|
78 |
+
raise gr.Error(e)
|
79 |
+
|
80 |
+
def save_to_wav2(dropbox):
|
81 |
+
file_path=dropbox
|
82 |
+
shutil.move(file_path,'./audios')
|
83 |
+
return os.path.join('./audios',os.path.basename(file_path))
|
84 |
+
|
85 |
+
def get_name():
|
86 |
+
if len(audio_files) > 0:
|
87 |
+
return sorted(audio_files)[0]
|
88 |
+
else:
|
89 |
+
return ''
|
90 |
+
|
91 |
+
def change_choices2():
|
92 |
+
audio_files=[]
|
93 |
+
for filename in os.listdir("./audios"):
|
94 |
+
if filename.endswith(('.wav','.mp3','.ogg','.flac','.m4a','.aac','.mp4')):
|
95 |
+
audio_files.append(os.path.join('./audios',filename).replace('\\', '/'))
|
96 |
+
return {"choices": sorted(audio_files), "__type__": "update"}, {"__type__": "update"}
|
97 |
+
|
98 |
+
def get_model_files():
|
99 |
+
model_files=[]
|
100 |
+
for root, dirs, files in os.walk(models_dir):
|
101 |
+
for name in files:
|
102 |
+
if filename.endswith(('.pth')):
|
103 |
+
model_files.append(os.path.join(root, name).replace('\\', '/'))
|
104 |
+
if len(model_files) == 0: model_files = [""]
|
105 |
+
return model_files
|
106 |
+
|
107 |
+
def update_model_name():
|
108 |
+
return gr.update(choices=get_model_files())
|
109 |
+
|
110 |
+
with gr.Blocks(theme=gr.themes.Base(), title=" rvc inferpy") as demo:
|
111 |
+
gr.Markdown("<h1><center>rvc inferpy (Neo RVC Fork)</center></h1>")
|
112 |
+
gr.Markdown("most simplest RVC inference")
|
113 |
+
with gr.Tabs():
|
114 |
+
with gr.TabItem("Inference"):
|
115 |
+
model_name_input = gr.Dropdown(label="Model Name", choices=get_model_files(), value=get_model_files()[0], allow_custom_value=True)
|
116 |
+
with gr.Row():
|
117 |
+
dropbox = gr.Audio(label="Upload Audio for inference")
|
118 |
+
with gr.Row():
|
119 |
+
input_audio0 = gr.Dropdown(
|
120 |
+
label="Choose your audio.",
|
121 |
+
value="",
|
122 |
+
choices=audio_files
|
123 |
+
)
|
124 |
+
dropbox.upload(fn=save_to_wav2, inputs=[dropbox], outputs=[input_audio0])\
|
125 |
+
.then(fn=change_choices2, inputs=None, outputs=[input_audio0])\
|
126 |
+
.then(fn=update_model_name, inputs=None, outputs=[model_name_input])
|
127 |
+
with gr.Row():
|
128 |
+
f0_change_input = gr.Number(label="F0 Change", value=0)
|
129 |
+
f0_method_input = gr.Dropdown(label="F0 Method", choices=["crepe", "dio", "harvest", "rmvpe", "fcpe", "hybrid[fcpe+rmvpe]"], value="crepe")
|
130 |
+
output_format_input = gr.Dropdown(label="Output Format", choices=["wav", "mp3"], value="wav")
|
131 |
+
submit_button = gr.Button("Run Inference")
|
132 |
+
output_audio = gr.Audio(label="Inferred Audio", type="filepath")
|
133 |
+
|
134 |
+
submit_button.click(
|
135 |
+
fn=process_audio,
|
136 |
+
inputs=[model_name_input, input_audio0, f0_change_input, f0_method_input, output_format_input],
|
137 |
+
outputs=output_audio
|
138 |
+
)
|
139 |
+
|
140 |
+
with gr.TabItem("Download Models"):
|
141 |
+
with gr.Row():
|
142 |
+
url_input = gr.Textbox(label="Model URL")
|
143 |
+
url_name_input = gr.Textbox(label="Model Name")
|
144 |
+
download_button = gr.Button("Download")
|
145 |
+
url_output = gr.Textbox(label="Output")
|
146 |
+
|
147 |
+
download_button.click(
|
148 |
+
fn=download_online_model,
|
149 |
+
inputs=[url_input, url_name_input],
|
150 |
+
outputs=url_output
|
151 |
+
)
|
152 |
+
|
153 |
+
demo.launch()
|
requirements.txt
CHANGED
@@ -1,2 +1,3 @@
|
|
1 |
-
rvc-inferpy
|
|
|
2 |
gdown
|
|
|
1 |
+
rvc-inferpy
|
2 |
+
#git+https://github.com/TheNeodev/rvc_inferpy
|
3 |
gdown
|