Blane187 commited on
Commit
0c1b49d
·
verified ·
1 Parent(s): deaa4a8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -46
app.py CHANGED
@@ -1,53 +1,29 @@
1
- from pathlib import Path
2
- import subprocess
3
-
4
- from dotenv import load_dotenv
5
- from scipy.io import wavfile
6
  import gradio as gr
 
7
 
8
- from rvc.modules.vc.modules import VC
9
-
10
-
11
- def initialize_rvc():
12
- subprocess.run(["rvc", "init"], check=True)
13
- subprocess.run(["rvc", "dlmodel"], check=True)
14
- subprocess.run(["rvc", "env", "create"], check=True)
15
- return "RVC initialized, model downloaded, and environment created."
16
-
17
-
18
- def process_audio(model_path, input_audio, output_path):
19
- vc = VC()
20
- vc.get_vc(model_path)
21
- tgt_sr, audio_opt, times, _ = vc.vc_single(1, Path(input_audio))
22
- wavfile.write(output_path, tgt_sr, audio_opt)
23
- return "Processing complete!"
24
-
25
 
26
- def main():
27
- with gr.Blocks() as demo:
28
- with gr.Tab("Initialize RVC"):
29
- init_button = gr.Button("Initialize RVC")
30
- init_message = gr.Textbox(label="Initialization Message", interactive=False)
31
- init_button.click(
32
- fn=initialize_rvc,
33
- inputs=[],
34
- outputs=[init_message]
35
- )
36
 
37
- with gr.Tab("process Audio"):
38
- model_path = gr.Textbox(label="Model Path", placeholder="Enter model path (e.g., model.pth)")
39
- input_audio = gr.Audio(label="Input Audio", type="filepath")
40
- output_path = gr.Textbox(label="Output Path", placeholder="Enter output path (e.g., output.wav)")
41
- process_button = gr.Button("Process")
42
- output_message = gr.Textbox(label="Output Message", interactive=False)
43
- process_button.click(
44
- fn=process_audio,
45
- inputs=[model_path, input_audio, output_path],
46
- outputs=[output_message]
47
- )
48
 
49
- demo.launch()
 
 
50
 
 
 
51
 
52
- if __name__ == "__main__":
53
- main()
 
 
 
 
 
 
1
  import gradio as gr
2
+ import subprocess
3
 
4
+ def rvc_infer(model, input_wav, fu):
5
+ output_wav = "output.wav" # Define a path for the output file
6
+ command = f"rvc infer -m {model} -i {input_wav} -o {output_wav} -fu {fu}"
7
+ result = subprocess.run(command, shell=True, capture_output=True, text=True)
8
+ return output_wav, result.stdout
 
 
 
 
 
 
 
 
 
 
 
 
9
 
10
+ with gr.Blocks() as demo:
11
+ gr.Markdown("# RVC Infer")
12
+
13
+ with gr.Row():
14
+ model_path = gr.Textbox(label="Model Path", placeholder="Enter model path (e.g., model.pth)")
15
+ input_audio = gr.Audio(label="Input Audio", type="filepath")
 
 
 
 
16
 
17
+ fu_value = gr.Slider(label="pitch", minimum=-12, maximum=12, step=1, value=0)
18
+
19
+ output_audio = gr.Audio(label="Output Audio")
20
+ command_output = gr.Textbox(label="Command Output")
 
 
 
 
 
 
 
21
 
22
+ def infer(model, input_wav, fu):
23
+ output_wav, result = rvc_infer(model, input_wav, fu)
24
+ return output_wav, result
25
 
26
+ infer_button = gr.Button("Run Inference")
27
+ infer_button.click(infer, inputs=[model_path, input_audio, fu_value], outputs=[output_audio, command_output])
28
 
29
+ demo.launch()