Spaces:
Runtime error
Runtime error
Update web-app.py
Browse files- web-app.py +46 -22
web-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",
|
| 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",
|
|
@@ -54,10 +61,16 @@ for file, link in files.items():
|
|
| 54 |
print(f"Error downloading {file}: {e}")
|
| 55 |
|
| 56 |
def download_from_url(url, model):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
if url == '':
|
| 58 |
return "URL cannot be left empty.", {"choices":show_available("assets/weights"),"__type__":"update"}
|
| 59 |
-
if model =='':
|
| 60 |
-
return "You need to name your model. For example: My-Model", {"choices":show_available("assets/weights"),"__type__":"update"}
|
| 61 |
url = url.strip()
|
| 62 |
zip_dirs = ["zips", "unzips"]
|
| 63 |
for directory in zip_dirs:
|
|
@@ -68,6 +81,13 @@ def download_from_url(url, model):
|
|
| 68 |
zipfile = model + '.zip'
|
| 69 |
zipfile_path = './zips/' + zipfile
|
| 70 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
if "drive.google.com" in url:
|
| 72 |
subprocess.run(["gdown", url, "--fuzzy", "-O", zipfile_path])
|
| 73 |
elif "mega.nz" in url:
|
|
@@ -94,7 +114,7 @@ def download_from_url(url, model):
|
|
| 94 |
return "Success.", {"choices":show_available("assets/weights"),"__type__":"update"}
|
| 95 |
except:
|
| 96 |
return "There's been an error.", {"choices":show_available("assets/weights"),"__type__":"update"}
|
| 97 |
-
|
| 98 |
def show_available(filepath,format=None):
|
| 99 |
if format:
|
| 100 |
print(f"Format: {format}")
|
|
@@ -106,11 +126,16 @@ def show_available(filepath,format=None):
|
|
| 106 |
else:
|
| 107 |
print(f"Does not match format: {file}")
|
| 108 |
print(f"Matches: {files}")
|
|
|
|
|
|
|
| 109 |
return files
|
|
|
|
|
|
|
| 110 |
return os.listdir(filepath)
|
| 111 |
|
| 112 |
def upload_file(file):
|
| 113 |
audio_formats = ['.wav', '.mp3', '.ogg', '.flac', '.aac']
|
|
|
|
| 114 |
try:
|
| 115 |
_, ext = os.path.splitext(file.name)
|
| 116 |
filename = os.path.basename(file.name)
|
|
@@ -128,25 +153,21 @@ def upload_file(file):
|
|
| 128 |
return {"choices":show_available('audios'),"__type__": "update","value":filename}
|
| 129 |
|
| 130 |
def refresh():
|
| 131 |
-
return {"choices":show_available("audios"),"__type__": "update"},{"choices":show_available("assets/weights",".pth"),"__type__": "update"}
|
| 132 |
|
| 133 |
def update_audio_player(choice):
|
| 134 |
return os.path.join("audios",choice)
|
| 135 |
|
| 136 |
-
|
| 137 |
-
with
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
gr.Markdown(
|
| 141 |
-
value="""
|
| 142 |
-
Rejekts EasyGUI
|
| 143 |
-
"""
|
| 144 |
-
)
|
| 145 |
with gr.Row():
|
| 146 |
with gr.Column():
|
| 147 |
with gr.Tabs():
|
| 148 |
with gr.TabItem("1.Choose a voice model:"):
|
| 149 |
-
model_picker = gr.Dropdown(label="",choices=show_available('assets/weights','.pth'),value='',interactive=True)
|
|
|
|
| 150 |
with gr.TabItem("(Or download a model here)"):
|
| 151 |
with gr.Row():
|
| 152 |
url = gr.Textbox(label="Paste the URL here:",value="",placeholder="(i.e. https://huggingface.co/repo/model/resolve/main/model.zip)")
|
|
@@ -156,6 +177,9 @@ with app:
|
|
| 156 |
with gr.Column():
|
| 157 |
download_button = gr.Button("Download")
|
| 158 |
download_button.click(fn=download_from_url,inputs=[url,model_rename],outputs=[url,model_picker])
|
|
|
|
|
|
|
|
|
|
| 159 |
|
| 160 |
with gr.Row():
|
| 161 |
with gr.Tabs():
|
|
@@ -164,14 +188,14 @@ with app:
|
|
| 164 |
audio_picker = gr.Dropdown(label="",choices=show_available('audios'),value='',interactive=True)
|
| 165 |
recorder.stop_recording(upload_file, inputs=[recorder],outputs=[audio_picker])
|
| 166 |
with gr.TabItem("(Or upload a new file here)"):
|
| 167 |
-
dropbox = gr.
|
| 168 |
dropbox.upload(fn=upload_file, inputs=[dropbox],outputs=[audio_picker])
|
| 169 |
audio_refresher = gr.Button("Refresh")
|
| 170 |
-
audio_refresher.click(fn=refresh,inputs=[],outputs=[audio_picker,model_picker])
|
| 171 |
convert_button = gr.Button("Convert")
|
| 172 |
with gr.Row():
|
| 173 |
audio_player = gr.Audio()
|
| 174 |
audio_picker.change(fn=update_audio_player, inputs=[audio_picker],outputs=[audio_player])
|
| 175 |
-
convert_button.click(convert, inputs=[audio_picker,model_picker],outputs=[audio_picker,audio_player])
|
| 176 |
|
| 177 |
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,pitch):
|
| 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", str(pitch),
|
| 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",
|
|
|
|
| 61 |
print(f"Error downloading {file}: {e}")
|
| 62 |
|
| 63 |
def download_from_url(url, model):
|
| 64 |
+
if model =='':
|
| 65 |
+
try:
|
| 66 |
+
model = url.split('/')[-1].split('?')[0]
|
| 67 |
+
except:
|
| 68 |
+
return "You need to name your model. For example: My-Model", {"choices":show_available("assets/weights"),"__type__":"update"}
|
| 69 |
+
url=url.replace('/blob/main/','/resolve/main/')
|
| 70 |
+
model=model.replace('.pth','').replace('.index','').replace('.zip','')
|
| 71 |
+
print(f"Model name: {model}")
|
| 72 |
if url == '':
|
| 73 |
return "URL cannot be left empty.", {"choices":show_available("assets/weights"),"__type__":"update"}
|
|
|
|
|
|
|
| 74 |
url = url.strip()
|
| 75 |
zip_dirs = ["zips", "unzips"]
|
| 76 |
for directory in zip_dirs:
|
|
|
|
| 81 |
zipfile = model + '.zip'
|
| 82 |
zipfile_path = './zips/' + zipfile
|
| 83 |
try:
|
| 84 |
+
if url.endswith('.pth'):
|
| 85 |
+
subprocess.run(["wget", url, "-O", f'./assets/weights/{model}.pth'])
|
| 86 |
+
return f"Sucessfully downloaded as {model}.pth", {"choices":show_available("assets/weights"),"__type__":"update"}
|
| 87 |
+
elif url.endswith('.index'):
|
| 88 |
+
if not os.path.exists(f'./logs/{model}'): os.makedirs(f'./logs/{model}')
|
| 89 |
+
subprocess.run(["wget", url, "-O", f'./logs/{model}/added_{model}.index'])
|
| 90 |
+
return f"Successfully downloaded as added_{model}.index", {"choices":show_available("assets/weights"),"__type__":"update"}
|
| 91 |
if "drive.google.com" in url:
|
| 92 |
subprocess.run(["gdown", url, "--fuzzy", "-O", zipfile_path])
|
| 93 |
elif "mega.nz" in url:
|
|
|
|
| 114 |
return "Success.", {"choices":show_available("assets/weights"),"__type__":"update"}
|
| 115 |
except:
|
| 116 |
return "There's been an error.", {"choices":show_available("assets/weights"),"__type__":"update"}
|
| 117 |
+
|
| 118 |
def show_available(filepath,format=None):
|
| 119 |
if format:
|
| 120 |
print(f"Format: {format}")
|
|
|
|
| 126 |
else:
|
| 127 |
print(f"Does not match format: {file}")
|
| 128 |
print(f"Matches: {files}")
|
| 129 |
+
if len(files) < 1:
|
| 130 |
+
return ['']
|
| 131 |
return files
|
| 132 |
+
if len(os.listdir(filepath)) < 1:
|
| 133 |
+
return ['']
|
| 134 |
return os.listdir(filepath)
|
| 135 |
|
| 136 |
def upload_file(file):
|
| 137 |
audio_formats = ['.wav', '.mp3', '.ogg', '.flac', '.aac']
|
| 138 |
+
print(file)
|
| 139 |
try:
|
| 140 |
_, ext = os.path.splitext(file.name)
|
| 141 |
filename = os.path.basename(file.name)
|
|
|
|
| 153 |
return {"choices":show_available('audios'),"__type__": "update","value":filename}
|
| 154 |
|
| 155 |
def refresh():
|
| 156 |
+
return {"choices":show_available("audios"),"__type__": "update"},{"choices":show_available("assets/weights",".pth"),"__type__": "update"},{"choices":show_available("logs"),"__type__": "update"}
|
| 157 |
|
| 158 |
def update_audio_player(choice):
|
| 159 |
return os.path.join("audios",choice)
|
| 160 |
|
| 161 |
+
with gr.Blocks() as app:
|
| 162 |
+
with gr.Row():
|
| 163 |
+
with gr.Column():
|
| 164 |
+
gr.HTML("<img src='file/a.png' alt='easy>")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 165 |
with gr.Row():
|
| 166 |
with gr.Column():
|
| 167 |
with gr.Tabs():
|
| 168 |
with gr.TabItem("1.Choose a voice model:"):
|
| 169 |
+
model_picker = gr.Dropdown(label="Model: ",choices=show_available('assets/weights','.pth'),value=show_available('assets/weights','.pth')[0],interactive=True,allow_custom_value=True)
|
| 170 |
+
index_picker = gr.Dropdown(label="Index:",interactive=True,choices=show_available('logs'),value=show_available('logs')[0],allow_custom_value=True)
|
| 171 |
with gr.TabItem("(Or download a model here)"):
|
| 172 |
with gr.Row():
|
| 173 |
url = gr.Textbox(label="Paste the URL here:",value="",placeholder="(i.e. https://huggingface.co/repo/model/resolve/main/model.zip)")
|
|
|
|
| 177 |
with gr.Column():
|
| 178 |
download_button = gr.Button("Download")
|
| 179 |
download_button.click(fn=download_from_url,inputs=[url,model_rename],outputs=[url,model_picker])
|
| 180 |
+
with gr.TabItem("Advanced"):
|
| 181 |
+
index_rate = gr.Slider(label='Index Rate: ',minimum=0,maximum=1,value=0.66,step=0.01)
|
| 182 |
+
pitch = gr.Slider(label='Pitch (-12 lowers it an octave, 0 keeps the original pitch, 12 lifts it an octave): ',minimum =-12, maximum=12, step=1, value=0, interactive=True)
|
| 183 |
|
| 184 |
with gr.Row():
|
| 185 |
with gr.Tabs():
|
|
|
|
| 188 |
audio_picker = gr.Dropdown(label="",choices=show_available('audios'),value='',interactive=True)
|
| 189 |
recorder.stop_recording(upload_file, inputs=[recorder],outputs=[audio_picker])
|
| 190 |
with gr.TabItem("(Or upload a new file here)"):
|
| 191 |
+
dropbox = gr.File(label="Drop an audio here.",file_types=['.wav', '.mp3', '.ogg', '.flac', '.aac'], type="filepath")
|
| 192 |
dropbox.upload(fn=upload_file, inputs=[dropbox],outputs=[audio_picker])
|
| 193 |
audio_refresher = gr.Button("Refresh")
|
| 194 |
+
audio_refresher.click(fn=refresh,inputs=[],outputs=[audio_picker,model_picker,index_picker])
|
| 195 |
convert_button = gr.Button("Convert")
|
| 196 |
with gr.Row():
|
| 197 |
audio_player = gr.Audio()
|
| 198 |
audio_picker.change(fn=update_audio_player, inputs=[audio_picker],outputs=[audio_player])
|
| 199 |
+
convert_button.click(convert, inputs=[audio_picker,model_picker,index_picker,index_rate,pitch],outputs=[audio_picker,audio_player])
|
| 200 |
|
| 201 |
app.queue().launch()
|