TheStinger commited on
Commit
0b67cea
Β·
verified Β·
1 Parent(s): 43af790

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +354 -354
app.py CHANGED
@@ -1,354 +1,354 @@
1
- import gradio as gr
2
- import requests
3
- import random
4
- import os
5
- import zipfile # built in module for unzipping files (thank god)
6
- import librosa
7
- import time
8
- from infer_rvc_python import BaseLoader
9
- from pydub import AudioSegment
10
- from tts_voice import tts_order_voice
11
- import edge_tts
12
- import tempfile
13
- import anyio
14
- from audio_separator.separator import Separator
15
-
16
-
17
- language_dict = tts_order_voice
18
-
19
- # ilaria tts implementation :rofl:
20
- async def text_to_speech_edge(text, language_code):
21
- voice = language_dict[language_code]
22
- communicate = edge_tts.Communicate(text, voice)
23
- with tempfile.NamedTemporaryFile(delete=False, suffix=".mp3") as tmp_file:
24
- tmp_path = tmp_file.name
25
-
26
- await communicate.save(tmp_path)
27
-
28
- return tmp_path
29
-
30
- # fucking dogshit toggle
31
- try:
32
- import spaces
33
- spaces_status = True
34
- except ImportError:
35
- spaces_status = False
36
-
37
- separator = Separator()
38
- converter = BaseLoader(only_cpu=False, hubert_path=None, rmvpe_path=None) # <- yeah so like this handles rvc
39
-
40
- global pth_file
41
- global index_file
42
-
43
- pth_file = "model.pth"
44
- index_file = "model.index"
45
-
46
- #CONFIGS
47
- TEMP_DIR = "temp"
48
- MODEL_PREFIX = "model"
49
- PITCH_ALGO_OPT = [
50
- "pm",
51
- "harvest",
52
- "crepe",
53
- "rmvpe",
54
- "rmvpe+",
55
- ]
56
- UVR_5_MODELS = [
57
- {"model_name": "BS-Roformer-Viperx-1297", "checkpoint": "model_bs_roformer_ep_317_sdr_12.9755.ckpt"},
58
- {"model_name": "MDX23C-InstVoc HQ 2", "checkpoint": "MDX23C-8KFFT-InstVoc_HQ_2.ckpt"},
59
- {"model_name": "Kim Vocal 2", "checkpoint": "Kim_Vocal_2.onnx"},
60
- {"model_name": "5_HP-Karaoke", "checkpoint": "5_HP-Karaoke-UVR.pth"},
61
- {"model_name": "UVR-DeNoise by FoxJoy", "checkpoint": "UVR-DeNoise.pth"},
62
- {"model_name": "UVR-DeEcho-DeReverb by FoxJoy", "checkpoint": "UVR-DeEcho-DeReverb.pth"},
63
- ]
64
-
65
- os.makedirs(TEMP_DIR, exist_ok=True)
66
-
67
- def unzip_file(file):
68
- filename = os.path.basename(file).split(".")[0] # converts "model.zip" to "model" so we can do things
69
- with zipfile.ZipFile(file, 'r') as zip_ref:
70
- zip_ref.extractall(os.path.join(TEMP_DIR, filename)) # might not be very ram efficient...
71
- return True
72
-
73
-
74
- def progress_bar(total, current): # best progress bar ever trust me sunglasses emoji 😎
75
- return "[" + "=" * int(current / total * 20) + ">" + " " * (20 - int(current / total * 20)) + "] " + str(int(current / total * 100)) + "%"
76
-
77
- def download_from_url(url, filename=None):
78
- if "/blob/" in url:
79
- url = url.replace("/blob/", "/resolve/") # made it delik proof 😎
80
- if "huggingface" not in url:
81
- return ["The URL must be from huggingface", "Failed", "Failed"]
82
- if filename is None:
83
- filename = os.path.join(TEMP_DIR, MODEL_PREFIX + str(random.randint(1, 1000)) + ".zip")
84
- response = requests.get(url)
85
- total = int(response.headers.get('content-length', 0)) # bytes to download (length of the file)
86
- if total > 500000000:
87
-
88
- return ["The file is too large. You can only download files up to 500 MB in size.", "Failed", "Failed"]
89
- current = 0
90
- with open(filename, "wb") as f:
91
- for data in response.iter_content(chunk_size=4096): # download in chunks of 4096 bytes (4kb - helps with memory usage and speed)
92
- f.write(data)
93
- current += len(data)
94
- print(progress_bar(total, current), end="\r") # \r is a carriage return, it moves the cursor to the start of the line so its like tqdm sunglasses emoji 😎
95
-
96
- # unzip because the model is in a zip file lel
97
-
98
- try:
99
- unzip_file(filename)
100
- except Exception as e:
101
- return ["Failed to unzip the file", "Failed", "Failed"] # return early if it fails and like tell the user but its dogshit hahahahahahaha 😎 According to all known laws aviation, there is no way a bee should be able to fly.
102
- unzipped_dir = os.path.join(TEMP_DIR, os.path.basename(filename).split(".")[0]) # just do what we did in unzip_file because we need the directory
103
- pth_files = []
104
- index_files = []
105
- for root, dirs, files in os.walk(unzipped_dir): # could be done more efficiently because nobody stores models in subdirectories but like who cares (it's a futureproofing thing lel)
106
- for file in files:
107
- if file.endswith(".pth"):
108
- pth_files.append(os.path.join(root, file))
109
- elif file.endswith(".index"):
110
- index_files.append(os.path.join(root, file))
111
-
112
- print(pth_files, index_files) # debug print because im fucking stupid and i need to see what is going on
113
- global pth_file
114
- global index_file
115
- pth_file = pth_files[0]
116
- index_file = index_files[0]
117
-
118
- pth_file_ui.value = pth_file
119
- index_file_ui.value = index_file
120
- print(pth_file_ui.value)
121
- print(index_file_ui.value)
122
- return ["Downloaded as " + filename, pth_files[0], index_files[0]]
123
-
124
- def inference(audio, model_name):
125
- output_data = inf_handler(audio, model_name)
126
- vocals = output_data[0]
127
- inst = output_data[1]
128
-
129
- return vocals, inst
130
-
131
- if spaces_status:
132
- @spaces.GPU()
133
- def convert_now(audio_files, random_tag, converter):
134
- return converter(
135
- audio_files,
136
- random_tag,
137
- overwrite=False,
138
- parallel_workers=8
139
- )
140
-
141
-
142
- else:
143
- def convert_now(audio_files, random_tag, converter):
144
- return converter(
145
- audio_files,
146
- random_tag,
147
- overwrite=False,
148
- parallel_workers=8
149
- )
150
-
151
- def calculate_remaining_time(epochs, seconds_per_epoch):
152
- total_seconds = epochs * seconds_per_epoch
153
-
154
- hours = total_seconds // 3600
155
- minutes = (total_seconds % 3600) // 60
156
- seconds = total_seconds % 60
157
-
158
- if hours == 0:
159
- return f"{int(minutes)} minutes"
160
- elif hours == 1:
161
- return f"{int(hours)} hour and {int(minutes)} minutes"
162
- else:
163
- return f"{int(hours)} hours and {int(minutes)} minutes"
164
-
165
- def inf_handler(audio, model_name): # its a shame that zerogpu just WONT cooperate with us
166
- model_found = False
167
- for model_info in UVR_5_MODELS:
168
- if model_info["model_name"] == model_name:
169
- separator.load_model(model_info["checkpoint"])
170
- model_found = True
171
- break
172
- if not model_found:
173
- separator.load_model()
174
- output_files = separator.separate(audio)
175
- vocals = output_files[0]
176
- inst = output_files[1]
177
- return vocals, inst
178
-
179
-
180
- def run(
181
- audio_files,
182
- pitch_alg,
183
- pitch_lvl,
184
- index_inf,
185
- r_m_f,
186
- e_r,
187
- c_b_p,
188
- ):
189
- if not audio_files:
190
- raise ValueError("The audio pls")
191
-
192
- if isinstance(audio_files, str):
193
- audio_files = [audio_files]
194
-
195
- try:
196
- duration_base = librosa.get_duration(filename=audio_files[0])
197
- print("Duration:", duration_base)
198
- except Exception as e:
199
- print(e)
200
-
201
- random_tag = "USER_"+str(random.randint(10000000, 99999999))
202
-
203
- file_m = pth_file_ui.value
204
- file_index = index_file_ui.value
205
-
206
- print("Random tag:", random_tag)
207
- print("File model:", file_m)
208
- print("Pitch algorithm:", pitch_alg)
209
- print("Pitch level:", pitch_lvl)
210
- print("File index:", file_index)
211
- print("Index influence:", index_inf)
212
- print("Respiration median filtering:", r_m_f)
213
- print("Envelope ratio:", e_r)
214
-
215
- converter.apply_conf(
216
- tag=random_tag,
217
- file_model=file_m,
218
- pitch_algo=pitch_alg,
219
- pitch_lvl=pitch_lvl,
220
- file_index=file_index,
221
- index_influence=index_inf,
222
- respiration_median_filtering=r_m_f,
223
- envelope_ratio=e_r,
224
- consonant_breath_protection=c_b_p,
225
- resample_sr=44100 if audio_files[0].endswith('.mp3') else 0,
226
- )
227
- time.sleep(0.1)
228
-
229
- result = convert_now(audio_files, random_tag, converter)
230
- print("Result:", result)
231
-
232
- return result[0]
233
-
234
- def upload_model(index_file, pth_file):
235
- pth_file = pth_file.name
236
- index_file = index_file.name
237
- pth_file_ui.value = pth_file
238
- index_file_ui.value = index_file
239
- return "Uploaded!"
240
-
241
- with gr.Blocks(theme="Ilaria RVC") as demo:
242
- gr.Markdown("## Ilaria RVC πŸ’–")
243
- with gr.Tab("Inference"):
244
- sound_gui = gr.Audio(value=None,type="filepath",autoplay=False,visible=True,)
245
- pth_file_ui = gr.Textbox(label="Model pth file",value=pth_file,visible=False,interactive=False,)
246
- index_file_ui = gr.Textbox(label="Index pth file",value=index_file,visible=False,interactive=False,)
247
-
248
- with gr.Accordion("Settings", open=False):
249
- pitch_algo_conf = gr.Dropdown(PITCH_ALGO_OPT,value=PITCH_ALGO_OPT[4],label="Pitch algorithm",visible=True,interactive=True,)
250
- pitch_lvl_conf = gr.Slider(label="Pitch level (lower -> 'male' while higher -> 'female')",minimum=-24,maximum=24,step=1,value=0,visible=True,interactive=True,)
251
- index_inf_conf = gr.Slider(minimum=0,maximum=1,label="Index influence -> How much accent is applied",value=0.75,)
252
- respiration_filter_conf = gr.Slider(minimum=0,maximum=7,label="Respiration median filtering",value=3,step=1,interactive=True,)
253
- envelope_ratio_conf = gr.Slider(minimum=0,maximum=1,label="Envelope ratio",value=0.25,interactive=True,)
254
- consonant_protec_conf = gr.Slider(minimum=0,maximum=0.5,label="Consonant breath protection",value=0.5,interactive=True,)
255
-
256
- button_conf = gr.Button("Convert",variant="primary",)
257
- output_conf = gr.Audio(type="filepath",label="Output",)
258
-
259
- button_conf.click(lambda :None, None, output_conf)
260
- button_conf.click(
261
- run,
262
- inputs=[
263
- sound_gui,
264
- pitch_algo_conf,
265
- pitch_lvl_conf,
266
- index_inf_conf,
267
- respiration_filter_conf,
268
- envelope_ratio_conf,
269
- consonant_protec_conf,
270
- ],
271
- outputs=[output_conf],
272
- )
273
-
274
- with gr.Tab("Ilaria TTS"):
275
- text_tts = gr.Textbox(label="Text", placeholder="Hello!", lines=3, interactive=True,)
276
- dropdown_tts = gr.Dropdown(label="Language and Model",choices=list(language_dict.keys()),interactive=True, value=list(language_dict.keys())[0])
277
-
278
- button_tts = gr.Button("Speak", variant="primary",)
279
-
280
- output_tts = gr.Audio(type="filepath", label="Output",)
281
-
282
- button_tts.click(text_to_speech_edge, inputs=[text_tts, dropdown_tts], outputs=[output_tts])
283
-
284
-
285
- with gr.Tab("Model Loader (Download and Upload)"):
286
- with gr.Accordion("Model Downloader", open=False):
287
- gr.Markdown(
288
- "Download the model from the following URL and upload it here. (Hugginface RVC model)"
289
- )
290
- model = gr.Textbox(lines=1, label="Model URL")
291
- download_button = gr.Button("Download Model")
292
- status = gr.Textbox(lines=1, label="Status", placeholder="Waiting....", interactive=False)
293
- model_pth = gr.Textbox(lines=1, label="Model pth file", placeholder="Waiting....", interactive=False)
294
- index_pth = gr.Textbox(lines=1, label="Index pth file", placeholder="Waiting....", interactive=False)
295
- download_button.click(download_from_url, model, outputs=[status, model_pth, index_pth])
296
- with gr.Accordion("Upload A Model", open=False):
297
- index_file_upload = gr.File(label="Index File (.index)")
298
- pth_file_upload = gr.File(label="Model File (.pth)")
299
- upload_button = gr.Button("Upload Model")
300
- upload_status = gr.Textbox(lines=1, label="Status", placeholder="Waiting....", interactive=False)
301
-
302
- upload_button.click(upload_model, [index_file_upload, pth_file_upload], upload_status)
303
-
304
-
305
- with gr.Tab("Vocal Separator (UVR)"):
306
- gr.Markdown("Separate vocals and instruments from an audio file using UVR models. - This is only on CPU due to ZeroGPU being ZeroGPU :(")
307
- uvr5_audio_file = gr.Audio(label="Audio File",type="filepath")
308
-
309
- with gr.Row():
310
- uvr5_model = gr.Dropdown(label="Model", choices=[model["model_name"] for model in UVR_5_MODELS])
311
- uvr5_button = gr.Button("Separate Vocals", variant="primary",)
312
-
313
- uvr5_output_voc = gr.Audio(type="filepath", label="Output 1",) # UVR models sometimes output it in a weird way where it's like the positions swap randomly, so let's just call them Outputs lol
314
- uvr5_output_inst = gr.Audio(type="filepath", label="Output 2",)
315
-
316
- uvr5_button.click(inference, [uvr5_audio_file, uvr5_model], [uvr5_output_voc, uvr5_output_inst])
317
-
318
- with gr.Tab("Extra"):
319
- with gr.Accordion("Training Time Calculator", open=False):
320
- with gr.Column():
321
- epochs_input = gr.Number(label="Number of Epochs")
322
- seconds_input = gr.Number(label="Seconds per Epoch")
323
- calculate_button = gr.Button("Calculate Time Remaining")
324
- remaining_time_output = gr.Textbox(label="Remaining Time", interactive=False)
325
-
326
- calculate_button.click(
327
- fn=calculate_remaining_time,
328
- inputs=[epochs_input, seconds_input],
329
- outputs=[remaining_time_output]
330
- )
331
-
332
- with gr.Accordion("Model Fusion", open=False):
333
- gr.Markdown(value="Fusion of two models to create a new model - coming soon! 😎")
334
-
335
- with gr.Accordion("Model Quantization", open=False):
336
- gr.Markdown(value="Quantization of a model to reduce its size - coming soon! 😎")
337
-
338
- with gr.Accordion("Training Helper", open=False):
339
- gr.Markdown(value="Help for training models - coming soon! 😎")
340
-
341
- with gr.Tab("Credits"):
342
- gr.Markdown(
343
- """
344
- Ilaria RVC made by [Ilaria](https://huggingface.co/TheStinger) suport her on [ko-fi](https://ko-fi.com/ilariaowo)
345
-
346
- The Inference code is made by [r3gm](https://huggingface.co/r3gm) (his module helped form this space πŸ’–)
347
-
348
- made with ❀️ by [mikus](https://github.com/cappuch) - i make this ui........
349
-
350
- ## In loving memory of JLabDX πŸ•ŠοΈ
351
- """
352
- )
353
-
354
- demo.queue(api_open=False).launch(show_api=False) # idk ilaria if you want or dont want to
 
1
+ import gradio as gr
2
+ import requests
3
+ import random
4
+ import os
5
+ import zipfile # built in module for unzipping files (thank god)
6
+ import librosa
7
+ import time
8
+ from infer_rvc_python import BaseLoader
9
+ from pydub import AudioSegment
10
+ from tts_voice import tts_order_voice
11
+ import edge_tts
12
+ import tempfile
13
+ import anyio
14
+ from audio_separator.separator import Separator
15
+
16
+
17
+ language_dict = tts_order_voice
18
+
19
+ # ilaria tts implementation :rofl:
20
+ async def text_to_speech_edge(text, language_code):
21
+ voice = language_dict[language_code]
22
+ communicate = edge_tts.Communicate(text, voice)
23
+ with tempfile.NamedTemporaryFile(delete=False, suffix=".mp3") as tmp_file:
24
+ tmp_path = tmp_file.name
25
+
26
+ await communicate.save(tmp_path)
27
+
28
+ return tmp_path
29
+
30
+ # fucking dogshit toggle
31
+ try:
32
+ import spaces
33
+ spaces_status = True
34
+ except ImportError:
35
+ spaces_status = False
36
+
37
+ separator = Separator()
38
+ converter = BaseLoader(only_cpu=False, hubert_path=None, rmvpe_path=None) # <- yeah so like this handles rvc
39
+
40
+ global pth_file
41
+ global index_file
42
+
43
+ pth_file = "model.pth"
44
+ index_file = "model.index"
45
+
46
+ #CONFIGS
47
+ TEMP_DIR = "temp"
48
+ MODEL_PREFIX = "model"
49
+ PITCH_ALGO_OPT = [
50
+ "pm",
51
+ "harvest",
52
+ "crepe",
53
+ "rmvpe",
54
+ "rmvpe+",
55
+ ]
56
+ UVR_5_MODELS = [
57
+ {"model_name": "BS-Roformer-Viperx-1297", "checkpoint": "model_bs_roformer_ep_317_sdr_12.9755.ckpt"},
58
+ {"model_name": "MDX23C-InstVoc HQ 2", "checkpoint": "MDX23C-8KFFT-InstVoc_HQ_2.ckpt"},
59
+ {"model_name": "Kim Vocal 2", "checkpoint": "Kim_Vocal_2.onnx"},
60
+ {"model_name": "5_HP-Karaoke", "checkpoint": "5_HP-Karaoke-UVR.pth"},
61
+ {"model_name": "UVR-DeNoise by FoxJoy", "checkpoint": "UVR-DeNoise.pth"},
62
+ {"model_name": "UVR-DeEcho-DeReverb by FoxJoy", "checkpoint": "UVR-DeEcho-DeReverb.pth"},
63
+ ]
64
+
65
+ os.makedirs(TEMP_DIR, exist_ok=True)
66
+
67
+ def unzip_file(file):
68
+ filename = os.path.basename(file).split(".")[0] # converts "model.zip" to "model" so we can do things
69
+ with zipfile.ZipFile(file, 'r') as zip_ref:
70
+ zip_ref.extractall(os.path.join(TEMP_DIR, filename)) # might not be very ram efficient...
71
+ return True
72
+
73
+
74
+ def progress_bar(total, current): # best progress bar ever trust me sunglasses emoji 😎
75
+ return "[" + "=" * int(current / total * 20) + ">" + " " * (20 - int(current / total * 20)) + "] " + str(int(current / total * 100)) + "%"
76
+
77
+ def download_from_url(url, filename=None):
78
+ if "/blob/" in url:
79
+ url = url.replace("/blob/", "/resolve/") # made it delik proof 😎
80
+ if "huggingface" not in url:
81
+ return ["The URL must be from huggingface", "Failed", "Failed"]
82
+ if filename is None:
83
+ filename = os.path.join(TEMP_DIR, MODEL_PREFIX + str(random.randint(1, 1000)) + ".zip")
84
+ response = requests.get(url)
85
+ total = int(response.headers.get('content-length', 0)) # bytes to download (length of the file)
86
+ if total > 500000000:
87
+
88
+ return ["The file is too large. You can only download files up to 500 MB in size.", "Failed", "Failed"]
89
+ current = 0
90
+ with open(filename, "wb") as f:
91
+ for data in response.iter_content(chunk_size=4096): # download in chunks of 4096 bytes (4kb - helps with memory usage and speed)
92
+ f.write(data)
93
+ current += len(data)
94
+ print(progress_bar(total, current), end="\r") # \r is a carriage return, it moves the cursor to the start of the line so its like tqdm sunglasses emoji 😎
95
+
96
+ # unzip because the model is in a zip file lel
97
+
98
+ try:
99
+ unzip_file(filename)
100
+ except Exception as e:
101
+ return ["Failed to unzip the file", "Failed", "Failed"] # return early if it fails and like tell the user but its dogshit hahahahahahaha 😎 According to all known laws aviation, there is no way a bee should be able to fly.
102
+ unzipped_dir = os.path.join(TEMP_DIR, os.path.basename(filename).split(".")[0]) # just do what we did in unzip_file because we need the directory
103
+ pth_files = []
104
+ index_files = []
105
+ for root, dirs, files in os.walk(unzipped_dir): # could be done more efficiently because nobody stores models in subdirectories but like who cares (it's a futureproofing thing lel)
106
+ for file in files:
107
+ if file.endswith(".pth"):
108
+ pth_files.append(os.path.join(root, file))
109
+ elif file.endswith(".index"):
110
+ index_files.append(os.path.join(root, file))
111
+
112
+ print(pth_files, index_files) # debug print because im fucking stupid and i need to see what is going on
113
+ global pth_file
114
+ global index_file
115
+ pth_file = pth_files[0]
116
+ index_file = index_files[0]
117
+
118
+ pth_file_ui.value = pth_file
119
+ index_file_ui.value = index_file
120
+ print(pth_file_ui.value)
121
+ print(index_file_ui.value)
122
+ return ["Downloaded as " + filename, pth_files[0], index_files[0]]
123
+
124
+ def inference(audio, model_name):
125
+ output_data = inf_handler(audio, model_name)
126
+ vocals = output_data[0]
127
+ inst = output_data[1]
128
+
129
+ return vocals, inst
130
+
131
+ if spaces_status:
132
+ @spaces.GPU()
133
+ def convert_now(audio_files, random_tag, converter):
134
+ return converter(
135
+ audio_files,
136
+ random_tag,
137
+ overwrite=False,
138
+ parallel_workers=8
139
+ )
140
+
141
+
142
+ else:
143
+ def convert_now(audio_files, random_tag, converter):
144
+ return converter(
145
+ audio_files,
146
+ random_tag,
147
+ overwrite=False,
148
+ parallel_workers=8
149
+ )
150
+
151
+ def calculate_remaining_time(epochs, seconds_per_epoch):
152
+ total_seconds = epochs * seconds_per_epoch
153
+
154
+ hours = total_seconds // 3600
155
+ minutes = (total_seconds % 3600) // 60
156
+ seconds = total_seconds % 60
157
+
158
+ if hours == 0:
159
+ return f"{int(minutes)} minutes"
160
+ elif hours == 1:
161
+ return f"{int(hours)} hour and {int(minutes)} minutes"
162
+ else:
163
+ return f"{int(hours)} hours and {int(minutes)} minutes"
164
+
165
+ def inf_handler(audio, model_name): # its a shame that zerogpu just WONT cooperate with us
166
+ model_found = False
167
+ for model_info in UVR_5_MODELS:
168
+ if model_info["model_name"] == model_name:
169
+ separator.load_model(model_info["checkpoint"])
170
+ model_found = True
171
+ break
172
+ if not model_found:
173
+ separator.load_model()
174
+ output_files = separator.separate(audio)
175
+ vocals = output_files[0]
176
+ inst = output_files[1]
177
+ return vocals, inst
178
+
179
+
180
+ def run(
181
+ audio_files,
182
+ pitch_alg,
183
+ pitch_lvl,
184
+ index_inf,
185
+ r_m_f,
186
+ e_r,
187
+ c_b_p,
188
+ ):
189
+ if not audio_files:
190
+ raise ValueError("The audio pls")
191
+
192
+ if isinstance(audio_files, str):
193
+ audio_files = [audio_files]
194
+
195
+ try:
196
+ duration_base = librosa.get_duration(filename=audio_files[0])
197
+ print("Duration:", duration_base)
198
+ except Exception as e:
199
+ print(e)
200
+
201
+ random_tag = "USER_"+str(random.randint(10000000, 99999999))
202
+
203
+ file_m = pth_file_ui.value
204
+ file_index = index_file_ui.value
205
+
206
+ print("Random tag:", random_tag)
207
+ print("File model:", file_m)
208
+ print("Pitch algorithm:", pitch_alg)
209
+ print("Pitch level:", pitch_lvl)
210
+ print("File index:", file_index)
211
+ print("Index influence:", index_inf)
212
+ print("Respiration median filtering:", r_m_f)
213
+ print("Envelope ratio:", e_r)
214
+
215
+ converter.apply_conf(
216
+ tag=random_tag,
217
+ file_model=file_m,
218
+ pitch_algo=pitch_alg,
219
+ pitch_lvl=pitch_lvl,
220
+ file_index=file_index,
221
+ index_influence=index_inf,
222
+ respiration_median_filtering=r_m_f,
223
+ envelope_ratio=e_r,
224
+ consonant_breath_protection=c_b_p,
225
+ resample_sr=44100 if audio_files[0].endswith('.mp3') else 0,
226
+ )
227
+ time.sleep(0.1)
228
+
229
+ result = convert_now(audio_files, random_tag, converter)
230
+ print("Result:", result)
231
+
232
+ return result[0]
233
+
234
+ def upload_model(index_file, pth_file):
235
+ pth_file = pth_file.name
236
+ index_file = index_file.name
237
+ pth_file_ui.value = pth_file
238
+ index_file_ui.value = index_file
239
+ return "Uploaded!"
240
+
241
+ with gr.Blocks(theme=gr.themes.Default(primary_hue="pink", secondary_hue="rose"), title="Ilaria RVC πŸ’–") as demo:
242
+ gr.Markdown("## Ilaria RVC πŸ’–")
243
+ with gr.Tab("Inference"):
244
+ sound_gui = gr.Audio(value=None,type="filepath",autoplay=False,visible=True,)
245
+ pth_file_ui = gr.Textbox(label="Model pth file",value=pth_file,visible=False,interactive=False,)
246
+ index_file_ui = gr.Textbox(label="Index pth file",value=index_file,visible=False,interactive=False,)
247
+
248
+ with gr.Accordion("Settings", open=False):
249
+ pitch_algo_conf = gr.Dropdown(PITCH_ALGO_OPT,value=PITCH_ALGO_OPT[4],label="Pitch algorithm",visible=True,interactive=True,)
250
+ pitch_lvl_conf = gr.Slider(label="Pitch level (lower -> 'male' while higher -> 'female')",minimum=-24,maximum=24,step=1,value=0,visible=True,interactive=True,)
251
+ index_inf_conf = gr.Slider(minimum=0,maximum=1,label="Index influence -> How much accent is applied",value=0.75,)
252
+ respiration_filter_conf = gr.Slider(minimum=0,maximum=7,label="Respiration median filtering",value=3,step=1,interactive=True,)
253
+ envelope_ratio_conf = gr.Slider(minimum=0,maximum=1,label="Envelope ratio",value=0.25,interactive=True,)
254
+ consonant_protec_conf = gr.Slider(minimum=0,maximum=0.5,label="Consonant breath protection",value=0.5,interactive=True,)
255
+
256
+ button_conf = gr.Button("Convert",variant="primary",)
257
+ output_conf = gr.Audio(type="filepath",label="Output",)
258
+
259
+ button_conf.click(lambda :None, None, output_conf)
260
+ button_conf.click(
261
+ run,
262
+ inputs=[
263
+ sound_gui,
264
+ pitch_algo_conf,
265
+ pitch_lvl_conf,
266
+ index_inf_conf,
267
+ respiration_filter_conf,
268
+ envelope_ratio_conf,
269
+ consonant_protec_conf,
270
+ ],
271
+ outputs=[output_conf],
272
+ )
273
+
274
+ with gr.Tab("Ilaria TTS"):
275
+ text_tts = gr.Textbox(label="Text", placeholder="Hello!", lines=3, interactive=True,)
276
+ dropdown_tts = gr.Dropdown(label="Language and Model",choices=list(language_dict.keys()),interactive=True, value=list(language_dict.keys())[0])
277
+
278
+ button_tts = gr.Button("Speak", variant="primary",)
279
+
280
+ output_tts = gr.Audio(type="filepath", label="Output",)
281
+
282
+ button_tts.click(text_to_speech_edge, inputs=[text_tts, dropdown_tts], outputs=[output_tts])
283
+
284
+
285
+ with gr.Tab("Model Loader (Download and Upload)"):
286
+ with gr.Accordion("Model Downloader", open=False):
287
+ gr.Markdown(
288
+ "Download the model from the following URL and upload it here. (Hugginface RVC model)"
289
+ )
290
+ model = gr.Textbox(lines=1, label="Model URL")
291
+ download_button = gr.Button("Download Model")
292
+ status = gr.Textbox(lines=1, label="Status", placeholder="Waiting....", interactive=False)
293
+ model_pth = gr.Textbox(lines=1, label="Model pth file", placeholder="Waiting....", interactive=False)
294
+ index_pth = gr.Textbox(lines=1, label="Index pth file", placeholder="Waiting....", interactive=False)
295
+ download_button.click(download_from_url, model, outputs=[status, model_pth, index_pth])
296
+ with gr.Accordion("Upload A Model", open=False):
297
+ index_file_upload = gr.File(label="Index File (.index)")
298
+ pth_file_upload = gr.File(label="Model File (.pth)")
299
+ upload_button = gr.Button("Upload Model")
300
+ upload_status = gr.Textbox(lines=1, label="Status", placeholder="Waiting....", interactive=False)
301
+
302
+ upload_button.click(upload_model, [index_file_upload, pth_file_upload], upload_status)
303
+
304
+
305
+ with gr.Tab("Vocal Separator (UVR)"):
306
+ gr.Markdown("Separate vocals and instruments from an audio file using UVR models. - This is only on CPU due to ZeroGPU being ZeroGPU :(")
307
+ uvr5_audio_file = gr.Audio(label="Audio File",type="filepath")
308
+
309
+ with gr.Row():
310
+ uvr5_model = gr.Dropdown(label="Model", choices=[model["model_name"] for model in UVR_5_MODELS])
311
+ uvr5_button = gr.Button("Separate Vocals", variant="primary",)
312
+
313
+ uvr5_output_voc = gr.Audio(type="filepath", label="Output 1",) # UVR models sometimes output it in a weird way where it's like the positions swap randomly, so let's just call them Outputs lol
314
+ uvr5_output_inst = gr.Audio(type="filepath", label="Output 2",)
315
+
316
+ uvr5_button.click(inference, [uvr5_audio_file, uvr5_model], [uvr5_output_voc, uvr5_output_inst])
317
+
318
+ with gr.Tab("Extra"):
319
+ with gr.Accordion("Training Time Calculator", open=False):
320
+ with gr.Column():
321
+ epochs_input = gr.Number(label="Number of Epochs")
322
+ seconds_input = gr.Number(label="Seconds per Epoch")
323
+ calculate_button = gr.Button("Calculate Time Remaining")
324
+ remaining_time_output = gr.Textbox(label="Remaining Time", interactive=False)
325
+
326
+ calculate_button.click(
327
+ fn=calculate_remaining_time,
328
+ inputs=[epochs_input, seconds_input],
329
+ outputs=[remaining_time_output]
330
+ )
331
+
332
+ with gr.Accordion("Model Fusion", open=False):
333
+ gr.Markdown(value="Fusion of two models to create a new model - coming soon! 😎")
334
+
335
+ with gr.Accordion("Model Quantization", open=False):
336
+ gr.Markdown(value="Quantization of a model to reduce its size - coming soon! 😎")
337
+
338
+ with gr.Accordion("Training Helper", open=False):
339
+ gr.Markdown(value="Help for training models - coming soon! 😎")
340
+
341
+ with gr.Tab("Credits"):
342
+ gr.Markdown(
343
+ """
344
+ Ilaria RVC made by [Ilaria](https://huggingface.co/TheStinger) suport her on [ko-fi](https://ko-fi.com/ilariaowo)
345
+
346
+ The Inference code is made by [r3gm](https://huggingface.co/r3gm) (his module helped form this space πŸ’–)
347
+
348
+ made with ❀️ by [mikus](https://github.com/cappuch) - i make this ui........
349
+
350
+ ## In loving memory of JLabDX πŸ•ŠοΈ
351
+ """
352
+ )
353
+
354
+ demo.queue(api_open=False).launch(show_api=False) # idk ilaria if you want or dont want to