Blane187 commited on
Commit
c76c626
·
verified ·
1 Parent(s): cb8b696

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +76 -0
app.py ADDED
@@ -0,0 +1,76 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import shutil
3
+ from os import listdir
4
+ import gradio as gr
5
+ from colorama import Fore
6
+
7
+ def run_inference(model_name, pitch, input_path, f0_method, save_as, index_rate, volume_normalization, consonant_protection):
8
+ # Setting paths for model and index files
9
+ model_filename = model_name + '.pth'
10
+ index_temp = 'Index_Temp'
11
+
12
+ # Ensure Index_Temp exists
13
+ if not os.path.exists(index_temp):
14
+ os.mkdir(index_temp)
15
+ print("Index_Temp folder created.")
16
+ else:
17
+ print("Index_Temp folder found.")
18
+
19
+ # Copy .index file to Index_Temp
20
+ index_file_path = os.path.join('logs/', model_name, '')
21
+ for file_name in listdir(index_file_path):
22
+ if file_name.startswith('added') and file_name.endswith('.index'):
23
+ shutil.copy(index_file_path + file_name, os.path.join(index_temp, file_name))
24
+ print('Index file copied successfully.')
25
+
26
+ # Get the .index file
27
+ indexfile_directory = os.getcwd() + '/' + index_temp
28
+ files = os.listdir(indexfile_directory)
29
+ index_filename = files[0] if files else None
30
+ if index_filename is None:
31
+ raise ValueError("Index file not found.")
32
+
33
+ shutil.rmtree(index_temp)
34
+
35
+ model_path = "assets/weights/" + model_filename
36
+ index_path = os.path.join('logs', model_name, index_filename)
37
+
38
+ if not os.path.exists(input_path):
39
+ raise ValueError(f"{input_path} was not found.")
40
+
41
+ os.environ['index_root'] = os.path.dirname(index_path)
42
+ index_path = os.path.basename(index_path)
43
+
44
+ os.environ['weight_root'] = os.path.dirname(model_path)
45
+
46
+ # Run the command
47
+ cmd = f"python tools/cmd/infer_cli.py --f0up_key {pitch} --input_path {input_path} --index_path {index_path} --f0method {f0_method} --opt_path {save_as} --model_name {os.path.basename(model_path)} --index_rate {index_rate} --device 'cuda:0' --is_half True --filter_radius 3 --resample_sr 0 --rms_mix_rate {volume_normalization} --protect {consonant_protection}"
48
+ os.system(f"rm -f {save_as}")
49
+ os.system(cmd)
50
+
51
+ return f"Inference completed, output saved at {save_as}.", save_as
52
+
53
+ # Gradio Interface
54
+
55
+ with gr.Blocks() as demo:
56
+ with gr.Row():
57
+ gr.Markdown("# RVC V2 - EASY GUI")
58
+ with gr.Row():
59
+ model_name = gr.Textbox(label="Model Name For Inference")
60
+ with gr.Row():
61
+ input_path = gr.Audio(label="Input Audio Path", type="filepath")
62
+ pitch = gr.Slider(minimum=-12, maximum=12, step=1, label="Pitch", value=0)
63
+ f0_method = gr.Dropdown(choices=["rmvpe", "pm", "harvest"], label="f0 Method", value="rmvpe")
64
+ index_rate = gr.Slider(minimum=0, maximum=1, step=0.01, label="Index Rate", value=0.5)
65
+ volume_normalization = gr.Slider(minimum=0, maximum=1, step=0.01, label="Volume Normalization", value=0)
66
+ consonant_protection = gr.Slider(minimum=0, maximum=1, step=0.01, label="Consonant Protection", value=0.5)
67
+ save_as = gr.Textbox(value="/content/RVC/audios/output_audio.wav", label="Output Audio Path")
68
+
69
+ run_btn = gr.Button("Run Inference")
70
+ with gr.Row():
71
+ output_message = gr.Textbox(label="Output Message")
72
+ output_audio = gr.Audio(label="Output Audio",interactive=False)
73
+
74
+ #run_btn.click(run_inference, [model_name, pitch, input_path, f0_method, save_as, index_rate, volume_normalization, consonant_protection], output_message)
75
+
76
+ demo.launch()