John6666 commited on
Commit
a8b441e
1 Parent(s): d5fcf79

Upload app.py

Browse files

With this change, the function should be executable. The remaining problem is,
- Give a name to each label.
- Set the minimum, maximum and step correctly.
- If gr.Number is better than gr.Scale, change it.
- Where it's a gr.Textbox, it can be gr.Dropdown or gr.Radio.
- Give choices the right choices (list).
- There is a place where the numbers are string, what should we do about this?
- What about the layout? Like the side-by-side part.
- If there are parts that need to be kept out of the tab, we need to decide on that as well.
and so on.

Files changed (1) hide show
  1. app.py +65 -181
app.py CHANGED
@@ -1,181 +1,65 @@
1
- import gradio as gr
2
- from rvc_infer import download_online_model
3
- import os
4
- import re
5
- import random
6
- from scipy.io.wavfile import write
7
- from scipy.io.wavfile import read
8
- import numpy as np
9
- import yt_dlp
10
- import subprocess
11
-
12
-
13
-
14
-
15
- def download_model(url, dir_name):
16
- output_models = download_online_model(url, dir_name)
17
- return dir_name
18
-
19
-
20
- uvr_models = {
21
- 'BS-Roformer-Viperx-1297.ckpt': 'model_bs_roformer_ep_317_sdr_12.9755.ckpt',
22
- 'MDX23C-8KFFT-InstVoc_HQ.ckpt': 'MDX23C-8KFFT-InstVoc_HQ.ckpt',
23
- 'BS-Roformer-Viperx-1053.ckpt': 'model_bs_roformer_ep_937_sdr_10.5309.ckpt',
24
- 'Mel-Roformer-Viperx-1143.ckpt': 'model_mel_band_roformer_ep_3005_sdr_11.4360.ckpt',
25
- 'Kim_Vocal_2.onnx': 'Kim_Vocal_2.onnx',
26
- 'UVR-De-Echo-Aggressive.pth': 'UVR-De-Echo-Aggressive.pth',
27
- }
28
-
29
-
30
-
31
-
32
-
33
- output_format = [
34
- 'wav',
35
- 'flac',
36
- 'mp3',
37
- ]
38
-
39
- mdxnet_overlap_values = [
40
- '0.25',
41
- '0.5',
42
- '0.75',
43
- '0.99',
44
- ]
45
-
46
- vrarch_window_size_values = [
47
- '320',
48
- '512',
49
- '1024',
50
- ]
51
-
52
-
53
-
54
-
55
-
56
-
57
- def download_audio(url):
58
- ydl_opts = {
59
- 'format': 'bestaudio/best',
60
- 'outtmpl': 'ytdl/%(title)s.%(ext)s',
61
- 'postprocessors': [{
62
- 'key': 'FFmpegExtractAudio',
63
- 'preferredcodec': 'wav',
64
- 'preferredquality': '192',
65
- }],
66
- }
67
-
68
- with yt_dlp.YoutubeDL(ydl_opts) as ydl:
69
- info_dict = ydl.extract_info(url, download=True)
70
- file_path = ydl.prepare_filename(info_dict).rsplit('.', 1)[0] + '.wav'
71
- sample_rate, audio_data = read(file_path)
72
- audio_array = np.asarray(audio_data, dtype=np.int16)
73
-
74
- return sample_rate, audio_array
75
-
76
- def roformer_separator(roformer_audio, roformer_model, roformer_output_format, roformer_overlap, roformer_segment_size, mdx23c_denoise, mdxnet_denoise, vrarch_tta, vrarch_high_end_process):
77
- files_list = []
78
- files_list.clear()
79
- directory = "./outputs"
80
- random_id = str(random.randint(10000, 99999))
81
- pattern = f"{random_id}"
82
- os.makedirs("outputs", exist_ok=True)
83
- write(f'{random_id}.wav', roformer_audio[0], roformer_audio[1])
84
- full_roformer_model = roformer_models[roformer_model]
85
- prompt = f"audio-separator {random_id}.wav --model_filename {full_roformer_model} --output_dir=./outputs --output_format={roformer_output_format} --normalization=0.9 --mdxc_overlap={roformer_overlap} --mdxc_segment_size={roformer_segment_size}"
86
-
87
- if mdx23c_denoise:
88
- prompt += " --mdx_enable_denoise"
89
-
90
- if mdxnet_denoise:
91
- prompt += " --mdx_enable_denoise"
92
-
93
-
94
- if vrarch_tta:
95
- prompt += " --vr_enable_tta"
96
- if vrarch_high_end_process:
97
- prompt += " --vr_high_end_process"
98
-
99
- os.system(prompt)
100
-
101
- for file in os.listdir(directory):
102
- if re.search(pattern, file):
103
- files_list.append(os.path.join(directory, file))
104
-
105
- stem1_file = files_list[0]
106
- stem2_file = files_list[1]
107
-
108
- return stem1_file, stem2_file
109
-
110
-
111
-
112
-
113
-
114
- CSS = """
115
- """
116
-
117
- with gr.Blocks(theme="Hev832/Applio", fill_width=True, css=CSS) as demo:
118
-
119
- with gr.Tabs():
120
- with gr.Tab("inferenece"):
121
- gr.Markdown("in progress")
122
- with gr.Tab("Download model"):
123
- gr.Markdown("## Download Model for infernece")
124
- url_input = gr.Textbox(label="Model URL", placeholder="Enter the URL of the model")
125
- dir_name_input = gr.Textbox(label="Directory Name", placeholder="Enter the directory name")
126
-
127
- download_button = gr.Button("Download Model")
128
- download_button.click(download_model, inputs=[url_input, dir_name_input], outputs=url_input)
129
-
130
- with gr.Tab("UVR5"):
131
- roformer_model = gr.Dropdown(
132
- label = "Select the Model",
133
- choices=list(uvr_models.keys()),
134
- interactive = True
135
- )
136
- roformer_output_format = gr.Dropdown(
137
- label = "Select the Output Format",
138
- choices = output_format,
139
- interactive = True
140
- )
141
- roformer_overlap = gr.Slider(
142
- minimum = 2,
143
- maximum = 4,
144
- step = 1,
145
- label = "Overlap",
146
- info = "Amount of overlap between prediction windows.",
147
- value = 4,
148
- interactive = True
149
- )
150
- roformer_segment_size = gr.Slider(
151
- minimum = 32,
152
- maximum = 4000,
153
- step = 32,
154
- label = "Segment Size",
155
- info = "Larger consumes more resources, but may give better results.",
156
- value = 256,
157
- interactive = True
158
- )
159
- mdx23c_denoise = gr.Checkbox(
160
- label = "Denoise",
161
- info = "Enable denoising during separation.",
162
- value = False,
163
- interactive = True
164
- )
165
- with gr.Tab(" Credits"):
166
- gr.Markdown(
167
- """
168
- this project made by [Blane187](https://huggingface.co/Blane187) with Improvements by [John6666](https://huggingfce.co/John6666)
169
- """)
170
-
171
-
172
-
173
-
174
-
175
-
176
-
177
-
178
-
179
-
180
-
181
- demo.launch(debug=True,show_api=False)
 
1
+ import gradio as gr
2
+ from rvc_infer import download_online_model, infer_audio
3
+
4
+ def download_model(url, dir_name):
5
+ output_models = download_online_model(url, dir_name)
6
+ return output_models
7
+
8
+
9
+ CSS = """
10
+ """
11
+
12
+ with gr.Blocks(theme="Hev832/Applio", fill_width=True, css=CSS) as demo:
13
+ with gr.Tab("Inferenece"):
14
+ gr.Markdown("in progress")
15
+ model_name = gr.Textbox(label="Model Name #", lines=1, value="")
16
+ input_audio = gr.Audio(label="Input Audio #", type="filepath")
17
+ f0_change = gr.Slider(label="f0 change #", minimum=0, maximum=10, step=1, value=0)
18
+ f0_method = gr.Dropdown(label="f0 method #", choices=["rmvpe+"], value="rmvpe+")
19
+ min_pitch = gr.Textbox(label="min pitch #", lines=1, value="50")
20
+ max_pitch = gr.Textbox(label="max pitch #", lines=1, value="1100")
21
+ crepe_hop_length = gr.Slider(label="crepe_hop_length #", minimum=0, maximum=256, step=1, value=128)
22
+ index_rate = gr.Slider(label="index_rate #", minimum=0, maximum=1.0, step=0.01, value=0.75)
23
+ filter_radius = gr.Slider(label="filter_radius #", minimum=0, maximum=10.0, step=0.01, value=3)
24
+ rms_mix_rate = gr.Slider(label="rms_mix_rate #", minimum=0, maximum=1.0, step=0.01, value=0.25)
25
+ protect = gr.Slider(label="protect #", minimum=0, maximum=1.0, step=0.01, value=0.33)
26
+ split_infer = gr.Checkbox(label="split_infer #", value=False)
27
+ min_silence = gr.Slider(label="min_silence #", minimum=0, maximum=1000, step=1, value=500)
28
+ silence_threshold = gr.Slider(label="silence_threshold #", minimum=-1000, maximum=1000, step=1, value=-50)
29
+ seek_step = gr.Slider(label="seek_step #", minimum=0, maximum=100, step=1, value=0)
30
+ keep_silence = gr.Slider(label="keep_silence #", minimum=-1000, maximum=1000, step=1, value=100)
31
+ do_formant = gr.Checkbox(label="do_formant #", value=False)
32
+ quefrency = gr.Slider(label="quefrency #", minimum=0, maximum=100, step=1, value=0)
33
+ timbre = gr.Slider(label="timbre #", minimum=0, maximum=100, step=1, value=1)
34
+ f0_autotune = gr.Checkbox(label="f0_autotune #", value=False)
35
+ audio_format = gr.Dropdown(label="audio_format #", choices=["wav"], value="wav")
36
+ resample_sr = gr.Slider(label="resample_sr #", minimum=0, maximum=100, step=1, value=0)
37
+ hubert_model_path = gr.Textbox(label="hubert_model_pathe #", lines=1, value="hubert_base.pt")
38
+ rmvpe_model_path = gr.Textbox(label="rmvpe_model_path #", lines=1, value="rmvpe.pt")
39
+ fcpe_model_path = gr.Textbox(label="fcpe_model_path #", lines=1, value="fcpe.pt")
40
+ submit_inference = gr.Button('Inference #', variant='primary')
41
+ result_audio = gr.Audio("Output Audio #", type="filepath")
42
+
43
+ with gr.Tab("Download Model"):
44
+ gr.Markdown("## Download Model for infernece")
45
+ url_input = gr.Textbox(label="Model URL", placeholder="Enter the URL of the model")
46
+ dir_name_input = gr.Textbox(label="Directory Name", placeholder="Enter the directory name")
47
+ output = gr.Textbox(label="Output Models")
48
+ download_button = gr.Button("Download Model")
49
+ download_button.click(download_model, inputs=[url_input, dir_name_input], outputs=output)
50
+
51
+ gr.on(
52
+ triggers=[submit_inference.click],
53
+ fn=infer_audio,
54
+ inputs=[model_name, input_audio, f0_change, f0_method, min_pitch, max_pitch, crepe_hop_length, index_rate,
55
+ filter_radius, rms_mix_rate, protect, split_infer, min_silence, silence_threshold, seek_step,
56
+ keep_silence, do_formant, quefrency, timbre, f0_autotune, audio_format, resample_sr,
57
+ hubert_model_path, rmvpe_model_path, fcpe_model_path],
58
+ outputs=[result_audio],
59
+ queue=True,
60
+ show_api=True,
61
+ show_progress="full",
62
+ )
63
+
64
+ demo.queue()
65
+ demo.launch()