Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,106 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import gradio as gr
|
3 |
+
from lib.infer import infer_audio
|
4 |
+
from google.colab import files
|
5 |
+
from pydub import AudioSegment
|
6 |
+
import zipfile
|
7 |
+
import shutil
|
8 |
+
import urllib.request
|
9 |
+
import gdown
|
10 |
+
|
11 |
+
main_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
12 |
+
|
13 |
+
os.chdir(main_dir)
|
14 |
+
|
15 |
+
def upload_audio(model_name, sound_path, f0_change, f0_method, min_pitch, max_pitch,
|
16 |
+
crepe_hop_length, index_rate, filter_radius, rms_mix_rate,
|
17 |
+
protect, split_infer, min_silence, silence_threshold,
|
18 |
+
seek_step, keep_silence, formant_shift, quefrency, timbre,
|
19 |
+
f0_autotune, output_format):
|
20 |
+
|
21 |
+
if not sound_path:
|
22 |
+
uploaded_audio = files.upload()
|
23 |
+
assert len(uploaded_audio) == 1, "Please only input audio one at a time"
|
24 |
+
sound_path = os.path.join(os.getcwd(), list(uploaded_audio.keys())[0])
|
25 |
+
|
26 |
+
inferred_audio = infer_audio(
|
27 |
+
model_name,
|
28 |
+
sound_path,
|
29 |
+
f0_change,
|
30 |
+
f0_method,
|
31 |
+
min_pitch,
|
32 |
+
max_pitch,
|
33 |
+
crepe_hop_length,
|
34 |
+
index_rate,
|
35 |
+
filter_radius,
|
36 |
+
rms_mix_rate,
|
37 |
+
protect,
|
38 |
+
split_infer,
|
39 |
+
min_silence,
|
40 |
+
silence_threshold,
|
41 |
+
seek_step,
|
42 |
+
keep_silence,
|
43 |
+
formant_shift,
|
44 |
+
quefrency,
|
45 |
+
timbre,
|
46 |
+
f0_autotune,
|
47 |
+
output_format
|
48 |
+
)
|
49 |
+
|
50 |
+
return AudioSegment.from_file(inferred_audio)
|
51 |
+
|
52 |
+
def download_model(url, dir_name):
|
53 |
+
models_dir = "models"
|
54 |
+
extraction_folder = os.path.join(models_dir, dir_name)
|
55 |
+
|
56 |
+
if os.path.exists(extraction_folder):
|
57 |
+
return f'Voice model directory {dir_name} already exists! Choose a different name.'
|
58 |
+
|
59 |
+
if 'pixeldrain.com' in url:
|
60 |
+
zip_name = url.split('/')[-1]
|
61 |
+
url = f'https://pixeldrain.com/api/file/{zip_name}'
|
62 |
+
elif 'drive.google.com' in url:
|
63 |
+
zip_name = dir_name + ".zip"
|
64 |
+
gdown.download(url, output=zip_name, use_cookies=True, quiet=True, fuzzy=True)
|
65 |
+
else:
|
66 |
+
zip_name = url.split('/')[-1]
|
67 |
+
urllib.request.urlretrieve(url, zip_name)
|
68 |
+
|
69 |
+
with zipfile.ZipFile(zip_name, 'r') as zip_ref:
|
70 |
+
zip_ref.extractall(extraction_folder)
|
71 |
+
|
72 |
+
os.remove(zip_name)
|
73 |
+
|
74 |
+
return f'{dir_name} model successfully downloaded!'
|
75 |
+
|
76 |
+
with gr.Blocks() as app:
|
77 |
+
gr.Markdown("## Inference")
|
78 |
+
|
79 |
+
with gr.Row():
|
80 |
+
model_name = gr.Textbox(label="Model Name")
|
81 |
+
sound_path = gr.Textbox(label="Audio Path")
|
82 |
+
|
83 |
+
with gr.Row():
|
84 |
+
f0_change = gr.Slider(minimum=-12, maximum=12, label="F0 Change (semitones)", value=0)
|
85 |
+
f0_method = gr.Dropdown(choices=["crepe", "harvest", "mangio-crepe", "rmvpe", "rmvpe+", "fcpe", "fcpe_legacy", "hybrid[mangio-crepe+rmvpe]", "hybrid[mangio-crepe+fcpe]", "hybrid[rmvpe+fcpe]", "hybrid[mangio-crepe+rmvpe+fcpe]"], label="F0 Method", value="fcpe")
|
86 |
+
|
87 |
+
# Add more settings as required
|
88 |
+
# Example for output format
|
89 |
+
output_format = gr.Dropdown(choices=["wav", "flac", "mp3"], label="Output Format", value="wav")
|
90 |
+
|
91 |
+
submit_button = gr.Button("Infer")
|
92 |
+
|
93 |
+
output_audio = gr.Audio(label="Inferred Audio Output")
|
94 |
+
|
95 |
+
submit_button.click(upload_audio, inputs=[model_name, sound_path, f0_change, f0_method, output_format], outputs=output_audio)
|
96 |
+
|
97 |
+
gr.Markdown("## Download Models")
|
98 |
+
|
99 |
+
url = gr.Textbox(label="Model Download URL")
|
100 |
+
dir_name = gr.Textbox(label="Desired Model Name")
|
101 |
+
download_button = gr.Button("Download Model")
|
102 |
+
download_output = gr.Markdown("")
|
103 |
+
|
104 |
+
download_button.click(download_model, inputs=[url, dir_name], outputs=download_output)
|
105 |
+
|
106 |
+
app.launch()
|