Next
commited on
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,77 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
|
3 |
+
|
4 |
+
def paths_for_files(path):
|
5 |
+
return [os.path.abspath(os.path.join(path, f)) for f in os.listdir(path) if os.path.splitext(f)[1].lower() in ('.mp3', '.wav', '.flac', '.ogg')]
|
6 |
+
|
7 |
+
with gr.Blocks(title="🔊", theme=gr.themes.Base(primary_hue="rose", neutral_hue="zinc")) as app:
|
8 |
+
with gr.Tabs():
|
9 |
+
with gr.TabItem("Inference"):
|
10 |
+
voice_model = gr.Dropdown(label="Model Voice", choices=sorted(names), value=lambda: sorted(names)[0] if len(sorted(names)) > 0 else '', interactive=True)
|
11 |
+
refresh_button = gr.Button("Refresh", variant="primary")
|
12 |
+
spk_item = gr.Slider(minimum=0, maximum=2333, step=1, label="Speaker ID", value=0, visible=False, interactive=True)
|
13 |
+
vc_transform0 = gr.Number(label="Pitch", value=0)
|
14 |
+
but0 = gr.Button(value="Convert", variant="primary")
|
15 |
+
dropbox = gr.File(label="Drop your audio here & hit the Reload button.")
|
16 |
+
record_button = gr.Audio(source="microphone", label="OR Record audio.", type="filepath")
|
17 |
+
input_audio0 = gr.Dropdown(label="Input Path", value=paths_for_files('audios')[0] if len(paths_for_files('audios')) > 0 else '', choices=paths_for_files('audios'), allow_custom_value=True)
|
18 |
+
audio_player = gr.Audio()
|
19 |
+
input_audio0.change(fn=lambda path: {"value": path, "__type__": "update"} if os.path.exists(path) else None, inputs=[input_audio0], outputs=[audio_player])
|
20 |
+
record_button.stop_recording(fn=lambda audio: audio, inputs=[record_button], outputs=[input_audio0])
|
21 |
+
dropbox.upload(fn=lambda audio: audio.name, inputs=[dropbox], outputs=[input_audio0])
|
22 |
+
with gr.Accordion("Change Index", open=False):
|
23 |
+
file_index2 = gr.Dropdown(label="Change Index", choices=sorted(index_paths), interactive=True, value=sorted(index_paths)[0] if len(sorted(index_paths)) > 0 else '')
|
24 |
+
index_rate1 = gr.Slider(minimum=0, maximum=1, label="Index Strength", value=0.5, interactive=True)
|
25 |
+
vc_output2 = gr.Audio(label="Output")
|
26 |
+
with gr.Accordion("General Settings", open=False):
|
27 |
+
f0method0 = gr.Radio(label="Method", choices=["pm", "harvest", "crepe", "rmvpe"] if config.dml == False else ["pm", "harvest", "rmvpe"], value="rmvpe", interactive=True)
|
28 |
+
filter_radius0 = gr.Slider(minimum=0, maximum=7, label="Breathiness Reduction (Harvest only)", value=3, step=1, interactive=True)
|
29 |
+
resample_sr0 = gr.Slider(minimum=0, maximum=48000, label="Resample", value=0, step=1, interactive=True, visible=False)
|
30 |
+
rms_mix_rate0 = gr.Slider(minimum=0, maximum=1, label="Volume Normalization", value=0, interactive=True)
|
31 |
+
protect0 = gr.Slider(minimum=0, maximum=0.5, label="Breathiness Protection (0 is enabled, 0.5 is disabled)", value=0.33, step=0.01, interactive=True)
|
32 |
+
if voice_model is not None:
|
33 |
+
vc.get_vc(voice_model.value, protect0, protect0)
|
34 |
+
file_index1 = gr.Textbox(label="Index Path", interactive=True, visible=False)
|
35 |
+
refresh_button.click(fn=change_choices, inputs=[], outputs=[voice_model, file_index2], api_name="infer_refresh")
|
36 |
+
refresh_button.click(fn=lambda: {"choices": paths_for_files('audios'), "__type__": "update"}, inputs=[], outputs=[input_audio0])
|
37 |
+
refresh_button.click(fn=lambda: {"value": paths_for_files('audios')[0], "__type__": "update"} if len(paths_for_files('audios')) > 0 else {"value": "", "__type__": "update"}, inputs=[], outputs=[input_audio0])
|
38 |
+
f0_file = gr.File(label="F0 Path", visible=False)
|
39 |
+
vc_output1 = gr.Textbox(label="Information", placeholder="Welcome!", visible=False)
|
40 |
+
but0.click(vc.vc_single, [spk_item, input_audio0, vc_transform0, f0_file, f0method0, file_index1, file_index2, index_rate1, filter_radius0, resample_sr0, rms_mix_rate0, protect0], [vc_output1, vc_output2], api_name="infer_convert")
|
41 |
+
voice_model.change(fn=vc.get_vc, inputs=[voice_model, protect0, protect0], outputs=[spk_item, protect0, protect0, file_index2, file_index2], api_name="infer_change_voice")
|
42 |
+
with gr.TabItem("Download Models"):
|
43 |
+
url_input = gr.Textbox(label="URL to model", value="", placeholder="https://...", scale=6)
|
44 |
+
name_output = gr.Textbox(label="Save as", value="", placeholder="MyModel", scale=2)
|
45 |
+
url_download = gr.Button(value="Download Model", scale=2)
|
46 |
+
url_download.click(inputs=[url_input, name_output], outputs=[url_input], fn=download_from_url)
|
47 |
+
model_browser = gr.Dropdown(choices=list(model_library.models.keys()), label="OR Search Models (Quality UNKNOWN)", scale=5)
|
48 |
+
download_from_browser = gr.Button(value="Get", scale=2)
|
49 |
+
download_from_browser.click(inputs=[model_browser], outputs=[model_browser], fn=lambda model: download_from_url(model_library.models[model], model))
|
50 |
+
with gr.TabItem("Train"):
|
51 |
+
training_name = gr.Textbox(label="Name your model", value="My-Voice", placeholder="My-Voice")
|
52 |
+
np7 = gr.Slider(minimum=0, maximum=config.n_cpu, step=1, label="Number of CPU processes used to extract pitch features", value=int(np.ceil(config.n_cpu / 1.5)), interactive=True)
|
53 |
+
sr2 = gr.Radio(label="Sampling Rate", choices=["40k", "32k"], value="32k", interactive=True, visible=False)
|
54 |
+
if_f0_3 = gr.Radio(label="Will your model be used for singing? If not, you can ignore this.", choices=[True, False], value=True, interactive=True, visible=False)
|
55 |
+
version19 = gr.Radio(label="Version", choices=["v1", "v2"], value="v2", interactive=True, visible=False)
|
56 |
+
easy_uploader.upload(fn=lambda folder: os.makedirs(folder, exist_ok=True), inputs=[dataset_folder], outputs=[])
|
57 |
+
easy_uploader.upload(fn=lambda files, folder: [shutil.copy2(f.name, os.path.join(folder, os.path.split(f.name)[1])) for f in files] if folder != "" else gr.Warning('Please enter a folder name for your dataset'), inputs=[easy_uploader, dataset_folder], outputs=[])
|
58 |
+
gpus6 = gr.Textbox(label="Enter the GPU numbers to use separated by -, (e.g. 0-1-2)", value=gpus, interactive=True, visible=F0GPUVisible)
|
59 |
+
gpu_info9 = gr.Textbox(label="GPU Info", value=gpu_info, visible=F0GPUVisible)
|
60 |
+
spk_id5 = gr.Slider(minimum=0, maximum=4, step=1, label="Speaker ID", value=0, interactive=True, visible=False)
|
61 |
+
f0method8 = gr.Radio(label="F0 extraction method", choices=["pm", "harvest", "dio", "rmvpe", "rmvpe_gpu"], value="rmvpe_gpu", interactive=True)
|
62 |
+
gpus_rmvpe = gr.Textbox(label="GPU numbers to use separated by -, (e.g. 0-1-2)", value="%s-%s" % (gpus, gpus), interactive=True, visible=F0GPUVisible)
|
63 |
+
f0method8.change(fn=change_f0_method, inputs=[f0method8], outputs=[gpus_rmvpe])
|
64 |
+
but1 = gr.Button("1. Process", variant="primary")
|
65 |
+
info1 = gr.Textbox(label="Information", value="", visible=True)
|
66 |
+
but1.click(preprocess_dataset, [dataset_folder, training_name, sr2, np7], [info1], api_name="train_preprocess")
|
67 |
+
but2 = gr.Button("2. Extract Features", variant="primary")
|
68 |
+
info2 = gr.Textbox(label="Information", value="", max_lines=8)
|
69 |
+
but2.click(extract_f0_feature, [gpus6, np7, f0method8, if_f0_3, gpus_rmvpe, version19, dataset_folder], [info2], api_name="train_extract_features")
|
70 |
+
but3 = gr.Button("3. Train", variant="primary")
|
71 |
+
info3 = gr.Textbox(label="Information", value="", max_lines=8)
|
72 |
+
but3.click(train_index, [gpus6, np7, f0method8, version19, dataset_folder, spk_id5], [info3], api_name="train_model")
|
73 |
+
but4 = gr.Button("4. Extract Feature", variant="primary")
|
74 |
+
info4 = gr.Textbox(label="Information", value="", max_lines=8)
|
75 |
+
but4.click(extract_feature, [gpus6, np7, f0method8, version19, dataset_folder, spk_id5], [info4], api_name="train_extract_feature")
|
76 |
+
|
77 |
+
app.queue(concurrency_count=3, max_size=20).launch()
|