John6666 commited on
Commit
6597bcb
Β·
verified Β·
1 Parent(s): a6130f0

Upload 4 files

Browse files
Files changed (3) hide show
  1. README.md +14 -14
  2. app.py +153 -139
  3. requirements.txt +2 -1
README.md CHANGED
@@ -1,15 +1,15 @@
1
- ---
2
- title: Rvc Inferpy
3
- emoji: πŸ˜‹
4
- colorFrom: purple
5
- colorTo: yellow
6
- sdk: gradio
7
- sdk_version: 3.42.0
8
- app_file: app.py
9
- pinned: true
10
- license: apache-2.0
11
-
12
- short_description: A easy to use rvc Fork
13
- ---
14
-
15
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
+ ---
2
+ title: Rvc Inferpy
3
+ emoji: πŸ˜‹
4
+ colorFrom: purple
5
+ colorTo: yellow
6
+ sdk: gradio
7
+ sdk_version: 4.44.0
8
+ app_file: app.py
9
+ pinned: true
10
+ license: apache-2.0
11
+
12
+ short_description: A easy to use rvc Fork
13
+ ---
14
+
15
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
app.py CHANGED
@@ -1,139 +1,153 @@
1
- import gradio as gr
2
- from rvc_inferpy import infer_audio
3
- import os
4
- import zipfile
5
- import shutil
6
- import urllib.request
7
- import gdown
8
-
9
- main_dir = os.getcwd()
10
- models_dir = os.path.join(main_dir, "models")
11
-
12
-
13
- audio_files=[]
14
- for filename in os.listdir("./audios"):
15
- if filename.endswith(('.wav','.mp3','.ogg','.flac','.m4a','.aac','.mp4')):
16
- audio_files.append(os.path.join('./audios',filename).replace('\\', '/'))
17
-
18
-
19
-
20
-
21
-
22
- def extract_zip(extraction_folder, zip_name):
23
- os.makedirs(extraction_folder)
24
- with zipfile.ZipFile(zip_name, 'r') as zip_ref:
25
- zip_ref.extractall(extraction_folder)
26
- os.remove(zip_name)
27
-
28
- index_filepath, model_filepath = None, None
29
- for root, dirs, files in os.walk(extraction_folder):
30
- for name in files:
31
- if name.endswith('.index') and os.stat(os.path.join(root, name)).st_size > 1024 * 100:
32
- index_filepath = os.path.join(root, name)
33
- if name.endswith('.pth') and os.stat(os.path.join(root, name)).st_size > 1024 * 1024 * 40:
34
- model_filepath = os.path.join(root, name)
35
-
36
- if not model_filepath:
37
- raise Exception(f'No .pth model file was found in the extracted zip. Please check {extraction_folder}.')
38
-
39
- os.rename(model_filepath, os.path.join(extraction_folder, os.path.basename(model_filepath)))
40
- if index_filepath:
41
- os.rename(index_filepath, os.path.join(extraction_folder, os.path.basename(index_filepath)))
42
-
43
- for filepath in os.listdir(extraction_folder):
44
- if os.path.isdir(os.path.join(extraction_folder, filepath)):
45
- shutil.rmtree(os.path.join(extraction_folder, filepath))
46
-
47
- def download_online_model(url, dir_name):
48
- try:
49
- print(f'[~] Downloading voice model with name {dir_name}...')
50
- zip_name = dir_name + ".zip"
51
- extraction_folder = os.path.join(models_dir, dir_name)
52
- if os.path.exists(extraction_folder):
53
- raise Exception(f'Voice model directory {dir_name} already exists! Choose a different name.')
54
-
55
- if 'drive.google.com' in url:
56
- gdown.download(url, output=zip_name, use_cookies=True, quiet=True, fuzzy=True)
57
- else:
58
- urllib.request.urlretrieve(url, zip_name)
59
-
60
- print('[~] Extracting zip file...')
61
- extract_zip(extraction_folder, zip_name)
62
- print(f'[+] {dir_name} Model successfully downloaded!')
63
-
64
- except Exception as e:
65
- raise Exception(str(e))
66
-
67
- def process_audio(model_name, sound_path, f0_change, f0_method, output_format):
68
- inferred_audio = infer_audio(
69
- MODEL_NAME=model_name,
70
- SOUND_PATH=sound_path,
71
- F0_CHANGE=f0_change,
72
- F0_METHOD=f0_method
73
- )
74
- # You might need additional logic for handling output_format here
75
- return inferred_audio
76
-
77
- def save_to_wav2(dropbox):
78
- file_path=dropbox.name
79
- shutil.move(file_path,'./audios')
80
- return os.path.join('./audios',os.path.basename(file_path))
81
-
82
-
83
- def get_name():
84
- if len(audio_files) > 0:
85
- return sorted(audio_files)[0]
86
- else:
87
- return ''
88
-
89
- def change_choices2():
90
- audio_files=[]
91
- for filename in os.listdir("./audios"):
92
- if filename.endswith(('.wav','.mp3','.ogg','.flac','.m4a','.aac','.mp4')):
93
- audio_files.append(os.path.join('./audios',filename).replace('\\', '/'))
94
- return {"choices": sorted(audio_files), "__type__": "update"}, {"__type__": "update"}
95
-
96
-
97
- with gr.Blocks(theme=gr.themes.Base(), title=" rvc inferpy") as demo:
98
- gr.Markdown("<h1><center>rvc inferpy (Neo RVC Fork)</center></h1>")
99
- gr.Markdown("most simplest RVC inference")
100
- with gr.Tabs():
101
- with gr.TabItem("Inference"):
102
- model_name_input = gr.Textbox(label="Model Name")
103
- with gr.Row():
104
- dropbox = gr.Audio(label="Upload Audio for inference")
105
- with gr.Row():
106
- input_audio0 = gr.Dropdown(
107
- label="Choose your audio.",
108
- value="",
109
- choices=audio_files
110
- )
111
- dropbox.upload(fn=save_to_wav2, inputs=[dropbox], outputs=[input_audio0])
112
- dropbox.upload(fn=change_choices2, inputs=[], outputs=[input_audio0])
113
- with gr.Row():
114
- f0_change_input = gr.Number(label="F0 Change", value=0)
115
- f0_method_input = gr.Dropdown(label="F0 Method", choices=["crepe", "dio", "harvest", "rmvpe", "fcpe", "hybrid[fcpe+rmvpe]"], value="crepe")
116
- output_format_input = gr.Dropdown(label="Output Format", choices=["wav", "mp3"], value="wav")
117
- submit_button = gr.Button("Run Inference")
118
- output_audio = gr.Audio(label="Inferred Audio", type="filepath")
119
-
120
- submit_button.click(
121
- fn=process_audio,
122
- inputs=[model_name_input, input_audio0, f0_change_input, f0_method_input, output_format_input],
123
- outputs=output_audio
124
- )
125
-
126
- with gr.TabItem("Download Models"):
127
- with gr.Row():
128
- url_input = gr.Textbox(label="Model URL")
129
- url_name_input = gr.Textbox(label="Model Name")
130
- download_button = gr.Button("Download")
131
- url_output = gr.Textbox(label="Output")
132
-
133
- download_button.click(
134
- fn=download_online_model,
135
- inputs=[url_input, url_name_input],
136
- outputs=url_output
137
- )
138
-
139
- demo.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from rvc_inferpy import infer_audio
3
+ import os
4
+ import zipfile
5
+ import shutil
6
+ import urllib.request
7
+ import gdown
8
+
9
+ main_dir = os.getcwd()
10
+ models_dir = os.path.join(main_dir, "models")
11
+ os.makedirs(models_dir, exist_ok=True)
12
+
13
+ audio_files=[]
14
+ for filename in os.listdir("./audios"):
15
+ if filename.endswith(('.wav','.mp3','.ogg','.flac','.m4a','.aac','.mp4')):
16
+ audio_files.append(os.path.join('./audios',filename).replace('\\', '/'))
17
+
18
+ def extract_zip(extraction_folder, zip_name):
19
+ os.makedirs(extraction_folder, exist_ok=True)
20
+ with zipfile.ZipFile(zip_name, 'r') as zip_ref:
21
+ zip_ref.extractall(extraction_folder)
22
+ os.remove(zip_name)
23
+
24
+ index_filepath, model_filepath = None, None
25
+ for root, dirs, files in os.walk(extraction_folder):
26
+ for name in files:
27
+ if name.endswith('.index') and os.stat(os.path.join(root, name)).st_size > 1024 * 100:
28
+ index_filepath = os.path.join(root, name)
29
+ if name.endswith('.pth') and os.stat(os.path.join(root, name)).st_size > 1024 * 1024 * 40:
30
+ model_filepath = os.path.join(root, name)
31
+
32
+ if not model_filepath:
33
+ raise Exception(f'No .pth model file was found in the extracted zip. Please check {extraction_folder}.')
34
+
35
+ os.rename(model_filepath, os.path.join(extraction_folder, os.path.basename(model_filepath)))
36
+ if index_filepath:
37
+ os.rename(index_filepath, os.path.join(extraction_folder, os.path.basename(index_filepath)))
38
+
39
+ for filepath in os.listdir(extraction_folder):
40
+ if os.path.isdir(os.path.join(extraction_folder, filepath)):
41
+ shutil.rmtree(os.path.join(extraction_folder, filepath))
42
+
43
+ def download_online_model(url, dir_name):
44
+ try:
45
+ print(f'[~] Downloading voice model with name {dir_name}...')
46
+ zip_name = dir_name + ".zip"
47
+ extraction_folder = os.path.join(models_dir, dir_name)
48
+ if os.path.exists(extraction_folder):
49
+ raise Exception(f'Voice model directory {dir_name} already exists! Choose a different name.')
50
+
51
+ if 'drive.google.com' in url:
52
+ gdown.download(url, output=zip_name, use_cookies=True, quiet=True, fuzzy=True)
53
+ else:
54
+ urllib.request.urlretrieve(url, zip_name)
55
+
56
+ print('[~] Extracting zip file...')
57
+ extract_zip(extraction_folder, zip_name)
58
+ print(f'[+] {dir_name} Model successfully downloaded!')
59
+
60
+ except Exception as e:
61
+ raise Exception(str(e))
62
+
63
+ def process_audio(model_name, sound_path, f0_change, f0_method, output_format):
64
+ try:
65
+ print(model_name, sound_path, f0_change, f0_method, output_format) #
66
+ # https://github.com/TheNeodev/rvc_inferpy/tree/main?tab=readme-ov-file#as-a-dependency-in-a-python-project <= wrong
67
+ # https://github.com/TheNeodev/rvc_inferpy/blob/main/rvc_inferpy/infer.py#L117 <= correct
68
+ inferred_audio = infer_audio(
69
+ model_name=model_name,
70
+ audio_path=sound_path,
71
+ f0_change=f0_change,
72
+ f0_method=f0_method
73
+ )
74
+ # You might need additional logic for handling output_format here
75
+ return inferred_audio
76
+ except Exception as e:
77
+ print(e)
78
+ raise gr.Error(e)
79
+
80
+ def save_to_wav2(dropbox):
81
+ file_path=dropbox
82
+ shutil.move(file_path,'./audios')
83
+ return os.path.join('./audios',os.path.basename(file_path))
84
+
85
+ def get_name():
86
+ if len(audio_files) > 0:
87
+ return sorted(audio_files)[0]
88
+ else:
89
+ return ''
90
+
91
+ def change_choices2():
92
+ audio_files=[]
93
+ for filename in os.listdir("./audios"):
94
+ if filename.endswith(('.wav','.mp3','.ogg','.flac','.m4a','.aac','.mp4')):
95
+ audio_files.append(os.path.join('./audios',filename).replace('\\', '/'))
96
+ return {"choices": sorted(audio_files), "__type__": "update"}, {"__type__": "update"}
97
+
98
+ def get_model_files():
99
+ model_files=[]
100
+ for root, dirs, files in os.walk(models_dir):
101
+ for name in files:
102
+ if filename.endswith(('.pth')):
103
+ model_files.append(os.path.join(root, name).replace('\\', '/'))
104
+ if len(model_files) == 0: model_files = [""]
105
+ return model_files
106
+
107
+ def update_model_name():
108
+ return gr.update(choices=get_model_files())
109
+
110
+ with gr.Blocks(theme=gr.themes.Base(), title=" rvc inferpy") as demo:
111
+ gr.Markdown("<h1><center>rvc inferpy (Neo RVC Fork)</center></h1>")
112
+ gr.Markdown("most simplest RVC inference")
113
+ with gr.Tabs():
114
+ with gr.TabItem("Inference"):
115
+ model_name_input = gr.Dropdown(label="Model Name", choices=get_model_files(), value=get_model_files()[0], allow_custom_value=True)
116
+ with gr.Row():
117
+ dropbox = gr.Audio(label="Upload Audio for inference")
118
+ with gr.Row():
119
+ input_audio0 = gr.Dropdown(
120
+ label="Choose your audio.",
121
+ value="",
122
+ choices=audio_files
123
+ )
124
+ dropbox.upload(fn=save_to_wav2, inputs=[dropbox], outputs=[input_audio0])\
125
+ .then(fn=change_choices2, inputs=None, outputs=[input_audio0])\
126
+ .then(fn=update_model_name, inputs=None, outputs=[model_name_input])
127
+ with gr.Row():
128
+ f0_change_input = gr.Number(label="F0 Change", value=0)
129
+ f0_method_input = gr.Dropdown(label="F0 Method", choices=["crepe", "dio", "harvest", "rmvpe", "fcpe", "hybrid[fcpe+rmvpe]"], value="crepe")
130
+ output_format_input = gr.Dropdown(label="Output Format", choices=["wav", "mp3"], value="wav")
131
+ submit_button = gr.Button("Run Inference")
132
+ output_audio = gr.Audio(label="Inferred Audio", type="filepath")
133
+
134
+ submit_button.click(
135
+ fn=process_audio,
136
+ inputs=[model_name_input, input_audio0, f0_change_input, f0_method_input, output_format_input],
137
+ outputs=output_audio
138
+ )
139
+
140
+ with gr.TabItem("Download Models"):
141
+ with gr.Row():
142
+ url_input = gr.Textbox(label="Model URL")
143
+ url_name_input = gr.Textbox(label="Model Name")
144
+ download_button = gr.Button("Download")
145
+ url_output = gr.Textbox(label="Output")
146
+
147
+ download_button.click(
148
+ fn=download_online_model,
149
+ inputs=[url_input, url_name_input],
150
+ outputs=url_output
151
+ )
152
+
153
+ demo.launch()
requirements.txt CHANGED
@@ -1,2 +1,3 @@
1
- rvc-inferpy
 
2
  gdown
 
1
+ rvc-inferpy
2
+ #git+https://github.com/TheNeodev/rvc_inferpy
3
  gdown