Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,24 +1,31 @@
|
|
1 |
import gradio as gr
|
2 |
import os, shutil
|
3 |
-
import subprocess
|
4 |
from datetime import datetime
|
5 |
os.environ["rmvpe_root"] = "assets/rmvpe"
|
6 |
os.environ['index_root']="logs"
|
7 |
os.environ['weight_root']="assets/weights"
|
8 |
|
9 |
-
def convert(audio_picker,model_picker):
|
10 |
gr.Warning("Your audio is being converted. Please wait.")
|
11 |
now = datetime.now().strftime("%d%m%Y%H%M%S")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
command = [
|
13 |
"python",
|
14 |
"tools/infer_cli.py",
|
15 |
"--f0up_key", "0",
|
16 |
"--input_path", f"audios/{audio_picker}",
|
17 |
-
"--index_path",
|
18 |
"--f0method", "rmvpe",
|
19 |
"--opt_path", f"audios/cli_output_{now}.wav",
|
20 |
"--model_name", f"{model_picker}",
|
21 |
-
"--index_rate",
|
22 |
"--device", "cpu",
|
23 |
"--filter_radius", "3",
|
24 |
"--resample_sr", "0",
|
@@ -129,7 +136,7 @@ def upload_file(file):
|
|
129 |
return {"choices":show_available('audios'),"__type__": "update","value":filename}
|
130 |
|
131 |
def refresh():
|
132 |
-
return {"choices":show_available("audios"),"__type__": "update"},{"choices":show_available("assets/weights",".pth"),"__type__": "update"}
|
133 |
|
134 |
def update_audio_player(choice):
|
135 |
return os.path.join("audios",choice)
|
@@ -139,7 +146,8 @@ with gr.Blocks() as app:
|
|
139 |
with gr.Column():
|
140 |
with gr.Tabs():
|
141 |
with gr.TabItem("1.Choose a voice model:"):
|
142 |
-
model_picker = gr.Dropdown(label="",choices=show_available('assets/weights','.pth'),value='',interactive=True)
|
|
|
143 |
with gr.TabItem("(Or download a model here)"):
|
144 |
with gr.Row():
|
145 |
url = gr.Textbox(label="Paste the URL here:",value="",placeholder="(i.e. https://huggingface.co/repo/model/resolve/main/model.zip)")
|
@@ -149,6 +157,8 @@ with gr.Blocks() as app:
|
|
149 |
with gr.Column():
|
150 |
download_button = gr.Button("Download")
|
151 |
download_button.click(fn=download_from_url,inputs=[url,model_rename],outputs=[url,model_picker])
|
|
|
|
|
152 |
|
153 |
with gr.Row():
|
154 |
with gr.Tabs():
|
@@ -160,11 +170,11 @@ with gr.Blocks() as app:
|
|
160 |
dropbox = gr.Audio(label="Drop an audio here.",sources=['upload'], type="filepath")
|
161 |
dropbox.upload(fn=upload_file, inputs=[dropbox],outputs=[audio_picker])
|
162 |
audio_refresher = gr.Button("Refresh")
|
163 |
-
audio_refresher.click(fn=refresh,inputs=[],outputs=[audio_picker,model_picker])
|
164 |
convert_button = gr.Button("Convert")
|
165 |
with gr.Row():
|
166 |
audio_player = gr.Audio()
|
167 |
audio_picker.change(fn=update_audio_player, inputs=[audio_picker],outputs=[audio_player])
|
168 |
-
convert_button.click(convert, inputs=[audio_picker,model_picker],outputs=[audio_picker,audio_player])
|
169 |
|
170 |
app.queue().launch()
|
|
|
1 |
import gradio as gr
|
2 |
import os, shutil
|
3 |
+
import subprocess, glob
|
4 |
from datetime import datetime
|
5 |
os.environ["rmvpe_root"] = "assets/rmvpe"
|
6 |
os.environ['index_root']="logs"
|
7 |
os.environ['weight_root']="assets/weights"
|
8 |
|
9 |
+
def convert(audio_picker,model_picker,index_picker,index_rate):
|
10 |
gr.Warning("Your audio is being converted. Please wait.")
|
11 |
now = datetime.now().strftime("%d%m%Y%H%M%S")
|
12 |
+
index_files = glob.glob(f"logs/{index_picker}/*.index")
|
13 |
+
if index_files:
|
14 |
+
print(f"Found index: {index_files[0]}")
|
15 |
+
else:
|
16 |
+
gr.Warning("Sorry, I couldn't find your .index file.")
|
17 |
+
print("Did not find a matching .index file")
|
18 |
+
index_files = [f'logs/{model_picker}/fake_index.index']
|
19 |
command = [
|
20 |
"python",
|
21 |
"tools/infer_cli.py",
|
22 |
"--f0up_key", "0",
|
23 |
"--input_path", f"audios/{audio_picker}",
|
24 |
+
"--index_path", index_files[0],
|
25 |
"--f0method", "rmvpe",
|
26 |
"--opt_path", f"audios/cli_output_{now}.wav",
|
27 |
"--model_name", f"{model_picker}",
|
28 |
+
"--index_rate", str(float(index_rate)),
|
29 |
"--device", "cpu",
|
30 |
"--filter_radius", "3",
|
31 |
"--resample_sr", "0",
|
|
|
136 |
return {"choices":show_available('audios'),"__type__": "update","value":filename}
|
137 |
|
138 |
def refresh():
|
139 |
+
return {"choices":show_available("audios"),"__type__": "update"},{"choices":show_available("assets/weights",".pth"),"__type__": "update"},{"choices":show_available("logs"),"__type__": "update"}
|
140 |
|
141 |
def update_audio_player(choice):
|
142 |
return os.path.join("audios",choice)
|
|
|
146 |
with gr.Column():
|
147 |
with gr.Tabs():
|
148 |
with gr.TabItem("1.Choose a voice model:"):
|
149 |
+
model_picker = gr.Dropdown(label="Model: ",choices=show_available('assets/weights','.pth'),value=show_available('assets/weights','.pth')[0],interactive=True,placeholder="Choose a VOICE MODEL here")
|
150 |
+
index_picker = gr.Dropdown(label="Index:",interactive=True,choices=show_available('logs'),value=show_available('logs')[0],allow_custom_value=True)
|
151 |
with gr.TabItem("(Or download a model here)"):
|
152 |
with gr.Row():
|
153 |
url = gr.Textbox(label="Paste the URL here:",value="",placeholder="(i.e. https://huggingface.co/repo/model/resolve/main/model.zip)")
|
|
|
157 |
with gr.Column():
|
158 |
download_button = gr.Button("Download")
|
159 |
download_button.click(fn=download_from_url,inputs=[url,model_rename],outputs=[url,model_picker])
|
160 |
+
with gr.TabItem("Advanced"):
|
161 |
+
index_rate = gr.Slider(label='Index Rate: ',minimum=0,maximum=1,value=0.66,step=0.01)
|
162 |
|
163 |
with gr.Row():
|
164 |
with gr.Tabs():
|
|
|
170 |
dropbox = gr.Audio(label="Drop an audio here.",sources=['upload'], type="filepath")
|
171 |
dropbox.upload(fn=upload_file, inputs=[dropbox],outputs=[audio_picker])
|
172 |
audio_refresher = gr.Button("Refresh")
|
173 |
+
audio_refresher.click(fn=refresh,inputs=[],outputs=[audio_picker,model_picker,index_picker])
|
174 |
convert_button = gr.Button("Convert")
|
175 |
with gr.Row():
|
176 |
audio_player = gr.Audio()
|
177 |
audio_picker.change(fn=update_audio_player, inputs=[audio_picker],outputs=[audio_player])
|
178 |
+
convert_button.click(convert, inputs=[audio_picker,model_picker,index_picker,index_rate],outputs=[audio_picker,audio_player])
|
179 |
|
180 |
app.queue().launch()
|