r3gm commited on
Commit
d4e34b5
1 Parent(s): d3d48bc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +101 -5
app.py CHANGED
@@ -6,6 +6,16 @@ import random
6
  import logging
7
  import time
8
  import soundfile as sf
 
 
 
 
 
 
 
 
 
 
9
 
10
  PITCH_ALGO_OPT = [
11
  "pm",
@@ -15,13 +25,72 @@ PITCH_ALGO_OPT = [
15
  "rmvpe+",
16
  ]
17
 
18
- logging.getLogger("infer_rvc_python").setLevel(logging.ERROR)
19
 
20
- converter = BaseLoader(only_cpu=False, hubert_path=None, rmvpe_path=None)
 
 
 
 
 
 
21
 
22
- title = "<center><strong><font size='7'>RVC⚡ZERO</font></strong></center>"
23
- description = "This demo is provided for educational and research purposes only. The authors and contributors of this project do not endorse or encourage any misuse or unethical use of this software. Any use of this software for purposes other than those intended is solely at the user's own risk. The authors and contributors shall not be held responsible for any damages or liabilities arising from the use of this demo inappropriately."
24
- theme = "aliabid94/new-theme"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25
 
26
 
27
  @spaces.GPU()
@@ -51,6 +120,10 @@ def run(
51
  if isinstance(audio_files, str):
52
  audio_files = [audio_files]
53
 
 
 
 
 
54
  random_tag = "USER_"+str(random.randint(10000000, 99999999))
55
 
56
  converter.apply_conf(
@@ -221,6 +294,29 @@ def get_gui(theme):
221
  0.25,
222
  0.50,
223
  ],
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
224
  ],
225
  fn=run,
226
  inputs=[
 
6
  import logging
7
  import time
8
  import soundfile as sf
9
+ from infer_rvc_python.main import download_manager
10
+ import zipfile
11
+
12
+ logging.getLogger("infer_rvc_python").setLevel(logging.ERROR)
13
+
14
+ converter = BaseLoader(only_cpu=False, hubert_path=None, rmvpe_path=None)
15
+
16
+ title = "<center><strong><font size='7'>RVC⚡ZERO</font></strong></center>"
17
+ description = "This demo is provided for educational and research purposes only. The authors and contributors of this project do not endorse or encourage any misuse or unethical use of this software. Any use of this software for purposes other than those intended is solely at the user's own risk. The authors and contributors shall not be held responsible for any damages or liabilities arising from the use of this demo inappropriately."
18
+ theme = "aliabid94/new-theme"
19
 
20
  PITCH_ALGO_OPT = [
21
  "pm",
 
25
  "rmvpe+",
26
  ]
27
 
 
28
 
29
+ def find_files(directory):
30
+ file_paths = []
31
+ for filename in os.listdir(directory):
32
+ # Check if the file has the desired extension
33
+ if filename.endswith('.pth') or filename.endswith('.zip') or filename.endswith('.index'):
34
+ # If yes, add the file path to the list
35
+ file_paths.append(os.path.join(directory, filename))
36
 
37
+ return file_paths
38
+
39
+
40
+ def unzip_in_folder(my_zip, my_dir):
41
+ with zipfile.ZipFile(my_zip) as zip:
42
+ for zip_info in zip.infolist():
43
+ if zip_info.is_dir():
44
+ continue
45
+ zip_info.filename = os.path.basename(zip_info.filename)
46
+ zip.extract(zip_info, my_dir)
47
+
48
+
49
+ def find_my_model(a_, b_):
50
+
51
+ if a_ is None or a_.endswith(".pth"):
52
+ return a_, b_
53
+
54
+ txt_files = []
55
+ for base_file in [a_, b_]:
56
+ if base_file is not None and base_file.endswith(".txt"):
57
+ txt_files.append(base_file)
58
+
59
+ directory = os.path.dirname(a_)
60
+
61
+ for txt in txt_files:
62
+ with open(txt, 'r') as file:
63
+ first_line = file.readline()
64
+
65
+ download_manager(
66
+ url=first_line.strip(),
67
+ path=directory,
68
+ extension="",
69
+ )
70
+
71
+ for f in find_files(directory):
72
+ if f.endswith(".zip"):
73
+ unzip_in_folder(f, directory)
74
+
75
+ model = None
76
+ index = None
77
+ end_files = find_files(directory)
78
+
79
+ for ff in end_files:
80
+ if ff.endswith(".pth"):
81
+ model = os.path.join(directory, ff)
82
+ gr.Info(f"Model found: {ff}")
83
+ if ff.endswith(".index"):
84
+ index = os.path.join(directory, ff)
85
+ gr.Info(f"Index found: {ff}")
86
+
87
+ if not model:
88
+ gr.Error(f"Model not found in: {end_files}")
89
+
90
+ if not index:
91
+ gr.Warning("Index not found")
92
+
93
+ return model, index
94
 
95
 
96
  @spaces.GPU()
 
120
  if isinstance(audio_files, str):
121
  audio_files = [audio_files]
122
 
123
+ if file_m is not None and file_m.endswith(".txt"):
124
+ file_m, file_index = find_my_model(file_m, file_index)
125
+ print(file_m, file_index)
126
+
127
  random_tag = "USER_"+str(random.randint(10000000, 99999999))
128
 
129
  converter.apply_conf(
 
294
  0.25,
295
  0.50,
296
  ],
297
+ [
298
+ ["./example2/test2.ogg"],
299
+ "./example2/model_link.txt",
300
+ "rmvpe+",
301
+ 0,
302
+ "./example2/index_link.txt",
303
+ 0.75,
304
+ 3,
305
+ 0.25,
306
+ 0.50,
307
+ ],
308
+ [
309
+ ["./example3/test3.wav"],
310
+ "./example3/zip_link.txt",
311
+ "rmvpe+",
312
+ 0,
313
+ None,
314
+ 0.75,
315
+ 3,
316
+ 0.25,
317
+ 0.50,
318
+ ],
319
+
320
  ],
321
  fn=run,
322
  inputs=[