TheStinger commited on
Commit
68173e6
โ€ข
1 Parent(s): 7822118

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +48 -22
app.py CHANGED
@@ -2,7 +2,7 @@ import gradio as gr
2
  import requests
3
  import random
4
  import os
5
- import zipfile
6
  import librosa
7
  import time
8
  from infer_rvc_python import BaseLoader
@@ -11,7 +11,8 @@ from tts_voice import tts_order_voice
11
  import edge_tts
12
  import tempfile
13
  import anyio
14
-
 
15
 
16
  language_dict = tts_order_voice
17
 
@@ -25,6 +26,7 @@ async def text_to_speech_edge(text, language_code):
25
 
26
  return tmp_path
27
 
 
28
  try:
29
  import spaces
30
  spaces_status = True
@@ -32,7 +34,7 @@ except ImportError:
32
  spaces_status = False
33
 
34
  separator = Separator()
35
- converter = BaseLoader(only_cpu=False, hubert_path=None, rmvpe_path=None) # <- yeah so like this handles rvc
36
 
37
  global pth_file
38
  global index_file
@@ -50,55 +52,79 @@ PITCH_ALGO_OPT = [
50
  "rmvpe",
51
  "rmvpe+",
52
  ]
53
- UVR_5_MODELS = [
54
- {"model_name": "BS-Roformer-Viperx-1297", "checkpoint": "model_bs_roformer_ep_317_sdr_12.9755.ckpt"},
55
- {"model_name": "MDX23C-InstVoc HQ 2", "checkpoint": "MDX23C-8KFFT-InstVoc_HQ_2.ckpt"},
56
- {"model_name": "Kim Vocal 2", "checkpoint": "Kim_Vocal_2.onnx"},
57
- {"model_name": "5_HP-Karaoke", "checkpoint": "5_HP-Karaoke-UVR.pth"},
58
- {"model_name": "UVR-DeNoise by FoxJoy", "checkpoint": "UVR-DeNoise.pth"},
59
- {"model_name": "UVR-DeEcho-DeReverb by FoxJoy", "checkpoint": "UVR-DeEcho-DeReverb.pth"},
60
- ]
61
 
62
  os.makedirs(TEMP_DIR, exist_ok=True)
63
 
64
  def unzip_file(file):
65
- filename = os.path.basename(file).split(".")[0]
66
  with zipfile.ZipFile(file, 'r') as zip_ref:
67
- zip_ref.extractall(os.path.join(TEMP_DIR, filename))
68
  return True
69
-
70
 
71
- def progress_bar(total, current):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
72
  return "[" + "=" * int(current / total * 20) + ">" + " " * (20 - int(current / total * 20)) + "] " + str(int(current / total * 100)) + "%"
73
 
74
  def download_from_url(url, filename=None):
75
  if "/blob/" in url:
76
- url = url.replace("/blob/", "/resolve/")
77
  if "huggingface" not in url:
78
  return ["The URL must be from huggingface", "Failed", "Failed"]
79
  if filename is None:
80
  filename = os.path.join(TEMP_DIR, MODEL_PREFIX + str(random.randint(1, 1000)) + ".zip")
81
  response = requests.get(url)
82
- total = int(response.headers.get('content-length', 0))
83
  if total > 500000000:
84
 
85
  return ["The file is too large. You can only download files up to 500 MB in size.", "Failed", "Failed"]
86
  current = 0
87
  with open(filename, "wb") as f:
88
- for data in response.iter_content(chunk_size=4096):
89
  f.write(data)
90
  current += len(data)
91
  print(progress_bar(total, current), end="\r")
92
 
93
 
 
94
  try:
95
  unzip_file(filename)
96
  except Exception as e:
97
- return ["Failed to unzip the file", "Failed", "Failed"]
98
- unzipped_dir = os.path.join(TEMP_DIR, os.path.basename(filename).split(".")[0])
99
  pth_files = []
100
  index_files = []
101
- for root, dirs, files in os.walk(unzipped_dir):
102
  for file in files:
103
  if file.endswith(".pth"):
104
  pth_files.append(os.path.join(root, file))
@@ -158,7 +184,7 @@ def calculate_remaining_time(epochs, seconds_per_epoch):
158
  else:
159
  return f"{int(hours)} hours and {int(minutes)} minutes"
160
 
161
- def inf_handler(audio, model_name):
162
  model_found = False
163
  for model_info in UVR_5_MODELS:
164
  if model_info["model_name"] == model_name:
 
2
  import requests
3
  import random
4
  import os
5
+ import zipfile
6
  import librosa
7
  import time
8
  from infer_rvc_python import BaseLoader
 
11
  import edge_tts
12
  import tempfile
13
  import anyio
14
+ import asyncio
15
+ from audio_separator.separator import Separator
16
 
17
  language_dict = tts_order_voice
18
 
 
26
 
27
  return tmp_path
28
 
29
+ # fucking dogshit toggle
30
  try:
31
  import spaces
32
  spaces_status = True
 
34
  spaces_status = False
35
 
36
  separator = Separator()
37
+ converter = BaseLoader(only_cpu=False, hubert_path=None, rmvpe_path=None)
38
 
39
  global pth_file
40
  global index_file
 
52
  "rmvpe",
53
  "rmvpe+",
54
  ]
 
 
 
 
 
 
 
 
55
 
56
  os.makedirs(TEMP_DIR, exist_ok=True)
57
 
58
  def unzip_file(file):
59
+ filename = os.path.basename(file).split(".")[0]
60
  with zipfile.ZipFile(file, 'r') as zip_ref:
61
+ zip_ref.extractall(os.path.join(TEMP_DIR, filename))
62
  return True
 
63
 
64
+ def get_training_info(audio_file):
65
+ if audio_file is None:
66
+ return 'Please provide an audio file!'
67
+ duration = get_audio_duration(audio_file)
68
+ sample_rate = wave.open(audio_file, 'rb').getframerate()
69
+
70
+ training_info = {
71
+ (0, 2): (150, 'OV2'),
72
+ (2, 3): (200, 'OV2'),
73
+ (3, 5): (250, 'OV2'),
74
+ (5, 10): (300, 'Normal'),
75
+ (10, 25): (500, 'Normal'),
76
+ (25, 45): (700, 'Normal'),
77
+ (45, 60): (1000, 'Normal')
78
+ }
79
+
80
+ for (min_duration, max_duration), (epochs, pretrain) in training_info.items():
81
+ if min_duration <= duration < max_duration:
82
+ break
83
+ else:
84
+ return 'Duration is not within the specified range!'
85
+
86
+ return f'You should use the **{pretrain}** pretrain with **{epochs}** epochs at **{sample_rate/1000}khz** sample rate.'
87
+
88
+ def on_button_click(audio_file_path):
89
+ return get_training_info(audio_file_path)
90
+
91
+ def get_audio_duration(audio_file_path):
92
+ audio_info = sf.info(audio_file_path)
93
+ duration_minutes = audio_info.duration / 60
94
+ return duration_minutes
95
+
96
+ def progress_bar(total, current): # best progress bar ever trust me sunglasses emoji ๐Ÿ˜Ž
97
  return "[" + "=" * int(current / total * 20) + ">" + " " * (20 - int(current / total * 20)) + "] " + str(int(current / total * 100)) + "%"
98
 
99
  def download_from_url(url, filename=None):
100
  if "/blob/" in url:
101
+ url = url.replace("/blob/", "/resolve/") # made it delik proof ๐Ÿ˜Ž
102
  if "huggingface" not in url:
103
  return ["The URL must be from huggingface", "Failed", "Failed"]
104
  if filename is None:
105
  filename = os.path.join(TEMP_DIR, MODEL_PREFIX + str(random.randint(1, 1000)) + ".zip")
106
  response = requests.get(url)
107
+ total = int(response.headers.get('content-length', 0)) # bytes to download (length of the file)
108
  if total > 500000000:
109
 
110
  return ["The file is too large. You can only download files up to 500 MB in size.", "Failed", "Failed"]
111
  current = 0
112
  with open(filename, "wb") as f:
113
+ for data in response.iter_content(chunk_size=4096):
114
  f.write(data)
115
  current += len(data)
116
  print(progress_bar(total, current), end="\r")
117
 
118
 
119
+
120
  try:
121
  unzip_file(filename)
122
  except Exception as e:
123
+ return ["Failed to unzip the file", "Failed", "Failed"]
124
+ unzipped_dir = os.path.join(TEMP_DIR, os.path.basename(filename).split(".")[0])
125
  pth_files = []
126
  index_files = []
127
+ for root, dirs, files in os.walk(unzipped_dir):
128
  for file in files:
129
  if file.endswith(".pth"):
130
  pth_files.append(os.path.join(root, file))
 
184
  else:
185
  return f"{int(hours)} hours and {int(minutes)} minutes"
186
 
187
+ def inf_handler(audio, model_name):
188
  model_found = False
189
  for model_info in UVR_5_MODELS:
190
  if model_info["model_name"] == model_name: