mirror of
https://github.com/Mangio621/Mangio-RVC-Fork.git
synced 2026-02-23 19:39:47 +01:00
Apply Code Formatter Change
This commit is contained in:
committed by
github-actions[bot]
parent
d688fcf075
commit
18dd5aa102
@@ -1,6 +1,7 @@
|
||||
from importlib.util import find_spec, LazyLoader, module_from_spec
|
||||
from sys import modules
|
||||
|
||||
|
||||
def lazyload(name):
|
||||
if name in modules:
|
||||
return modules[name]
|
||||
@@ -10,4 +11,4 @@ def lazyload(name):
|
||||
module = module_from_spec(spec)
|
||||
modules[name] = module
|
||||
loader.exec_module(module)
|
||||
return module
|
||||
return module
|
||||
|
||||
6
i18n.py
6
i18n.py
@@ -1,5 +1,6 @@
|
||||
import json
|
||||
|
||||
|
||||
def load_language_list(language):
|
||||
try:
|
||||
with open(f"./i18n/{language}.json", "r", encoding="utf-8") as f:
|
||||
@@ -20,8 +21,10 @@ class I18nAuto:
|
||||
>>> i18n.print()
|
||||
Using Language: en_US
|
||||
"""
|
||||
|
||||
def __init__(self, language=None):
|
||||
from locale import getdefaultlocale
|
||||
|
||||
language = language or getdefaultlocale()[0]
|
||||
if not self._language_exists(language):
|
||||
language = "en_US"
|
||||
@@ -32,6 +35,7 @@ class I18nAuto:
|
||||
@staticmethod
|
||||
def _language_exists(language):
|
||||
from os.path import exists
|
||||
|
||||
return exists(f"./i18n/{language}.json")
|
||||
|
||||
def __call__(self, key):
|
||||
@@ -40,4 +44,4 @@ class I18nAuto:
|
||||
|
||||
def print(self):
|
||||
"""Prints the language currently in use."""
|
||||
print(f"Using Language: {self.language}")
|
||||
print(f"Using Language: {self.language}")
|
||||
|
||||
1335
infer-web.py
1335
infer-web.py
File diff suppressed because it is too large
Load Diff
95
my_utils.py
95
my_utils.py
@@ -10,21 +10,24 @@ import random
|
||||
import csv
|
||||
|
||||
platform_stft_mapping = {
|
||||
'linux': 'stftpitchshift',
|
||||
'darwin': 'stftpitchshift',
|
||||
'win32': 'stftpitchshift.exe',
|
||||
"linux": "stftpitchshift",
|
||||
"darwin": "stftpitchshift",
|
||||
"win32": "stftpitchshift.exe",
|
||||
}
|
||||
|
||||
stft = platform_stft_mapping.get(sys.platform)
|
||||
|
||||
|
||||
def CSVutil(file, rw, type, *args):
|
||||
if type == 'formanting':
|
||||
if rw == 'r':
|
||||
if type == "formanting":
|
||||
if rw == "r":
|
||||
with open(file) as fileCSVread:
|
||||
csv_reader = list(csv.reader(fileCSVread))
|
||||
return (
|
||||
csv_reader[0][0], csv_reader[0][1], csv_reader[0][2]
|
||||
) if csv_reader is not None else (lambda: exec('raise ValueError("No data")'))()
|
||||
(csv_reader[0][0], csv_reader[0][1], csv_reader[0][2])
|
||||
if csv_reader is not None
|
||||
else (lambda: exec('raise ValueError("No data")'))()
|
||||
)
|
||||
else:
|
||||
if args:
|
||||
doformnt = args[0]
|
||||
@@ -32,65 +35,74 @@ def CSVutil(file, rw, type, *args):
|
||||
doformnt = False
|
||||
qfr = args[1] if len(args) > 1 else 1.0
|
||||
tmb = args[2] if len(args) > 2 else 1.0
|
||||
with open(file, rw, newline='') as fileCSVwrite:
|
||||
csv_writer = csv.writer(fileCSVwrite, delimiter=',')
|
||||
with open(file, rw, newline="") as fileCSVwrite:
|
||||
csv_writer = csv.writer(fileCSVwrite, delimiter=",")
|
||||
csv_writer.writerow([doformnt, qfr, tmb])
|
||||
elif type == 'stop':
|
||||
elif type == "stop":
|
||||
stop = args[0] if args else False
|
||||
with open(file, rw, newline='') as fileCSVwrite:
|
||||
csv_writer = csv.writer(fileCSVwrite, delimiter=',')
|
||||
with open(file, rw, newline="") as fileCSVwrite:
|
||||
csv_writer = csv.writer(fileCSVwrite, delimiter=",")
|
||||
csv_writer.writerow([stop])
|
||||
|
||||
|
||||
def load_audio(file, sr, DoFormant, Quefrency, Timbre):
|
||||
converted = False
|
||||
DoFormant, Quefrency, Timbre = CSVutil('csvdb/formanting.csv', 'r', 'formanting')
|
||||
DoFormant, Quefrency, Timbre = CSVutil("csvdb/formanting.csv", "r", "formanting")
|
||||
try:
|
||||
file = (
|
||||
file.strip(" ").strip('"').strip("\n").strip('"').strip(" ")
|
||||
)
|
||||
file = file.strip(" ").strip('"').strip("\n").strip('"').strip(" ")
|
||||
file_formanted = file.strip(" ").strip('"').strip("\n").strip('"').strip(" ")
|
||||
|
||||
if (DoFormant.lower() == 'true'):
|
||||
numerator = round(random.uniform(1,4), 4)
|
||||
|
||||
|
||||
if DoFormant.lower() == "true":
|
||||
numerator = round(random.uniform(1, 4), 4)
|
||||
|
||||
if not file.endswith(".wav"):
|
||||
|
||||
if not os.path.isfile(f"{file_formanted}.wav"):
|
||||
converted = True
|
||||
#print(f"\nfile = {file}\n")
|
||||
#print(f"\nfile_formanted = {file_formanted}\n")
|
||||
# print(f"\nfile = {file}\n")
|
||||
# print(f"\nfile_formanted = {file_formanted}\n")
|
||||
converting = (
|
||||
ffmpeg.input(file_formanted, threads = 0)
|
||||
ffmpeg.input(file_formanted, threads=0)
|
||||
.output(f"{RQuote(file_formanted)}.wav")
|
||||
.run(
|
||||
cmd=["ffmpeg", "-nostdin"], capture_stdout=True, capture_stderr=True
|
||||
cmd=["ffmpeg", "-nostdin"],
|
||||
capture_stdout=True,
|
||||
capture_stderr=True,
|
||||
)
|
||||
)
|
||||
else:
|
||||
pass
|
||||
file_formanted = f"{file_formanted}.wav" if not file_formanted.endswith(".wav") else file_formanted
|
||||
|
||||
file_formanted = (
|
||||
f"{file_formanted}.wav"
|
||||
if not file_formanted.endswith(".wav")
|
||||
else file_formanted
|
||||
)
|
||||
|
||||
print(f" · Formanting {file_formanted}...\n")
|
||||
|
||||
|
||||
command = (
|
||||
f'{RQuote(stft)} -i "{RQuote(file_formanted)}" -q "{RQuote(Quefrency)}" '
|
||||
f'-t "{RQuote(Timbre)}" -o "{RQuote(file_formanted)}FORMANTED_{RQuote(str(numerator))}.wav"'
|
||||
)
|
||||
os.system(command)
|
||||
|
||||
|
||||
print(f" · Formanted {file_formanted}!\n")
|
||||
|
||||
|
||||
out, _ = (
|
||||
ffmpeg.input(f"{file_formanted}FORMANTED_{str(numerator)}.wav", threads=0)
|
||||
ffmpeg.input(
|
||||
f"{file_formanted}FORMANTED_{str(numerator)}.wav", threads=0
|
||||
)
|
||||
.output("-", format="f32le", acodec="pcm_f32le", ac=1, ar=sr)
|
||||
.run(
|
||||
cmd=["ffmpeg", "-nostdin"], capture_stdout=True, capture_stderr=True
|
||||
)
|
||||
)
|
||||
|
||||
try: os.remove(f"{file_formanted}FORMANTED_{str(numerator)}.wav")
|
||||
except Exception as e: pass; print(f"couldn't remove formanted type of file due to {e}")
|
||||
|
||||
try:
|
||||
os.remove(f"{file_formanted}FORMANTED_{str(numerator)}.wav")
|
||||
except Exception as e:
|
||||
pass
|
||||
print(f"couldn't remove formanted type of file due to {e}")
|
||||
|
||||
else:
|
||||
out, _ = (
|
||||
ffmpeg.input(file, threads=0)
|
||||
@@ -101,12 +113,15 @@ def load_audio(file, sr, DoFormant, Quefrency, Timbre):
|
||||
)
|
||||
except Exception as e:
|
||||
raise RuntimeError(f"Failed to load audio: {e}")
|
||||
|
||||
|
||||
if converted:
|
||||
try: os.remove(file_formanted)
|
||||
except Exception as e: pass; print(f"Couldn't remove converted type of file due to {e}")
|
||||
try:
|
||||
os.remove(file_formanted)
|
||||
except Exception as e:
|
||||
pass
|
||||
print(f"Couldn't remove converted type of file due to {e}")
|
||||
converted = False
|
||||
|
||||
|
||||
return np.frombuffer(out, np.float32).flatten()
|
||||
|
||||
|
||||
@@ -119,7 +134,7 @@ def check_audio_duration(file):
|
||||
probe = ffmpeg.probe(file)
|
||||
|
||||
# Extract the duration from the probe result
|
||||
duration = float(probe['streams'][0]['duration'])
|
||||
duration = float(probe["streams"][0]["duration"])
|
||||
|
||||
# If the duration is less than 0.75 seconds, print the message and exit the loop
|
||||
if duration < 0.76:
|
||||
@@ -132,4 +147,4 @@ def check_audio_duration(file):
|
||||
|
||||
return True
|
||||
except Exception as e:
|
||||
raise RuntimeError(f"Failed to check audio duration: {e}")
|
||||
raise RuntimeError(f"Failed to check audio duration: {e}")
|
||||
|
||||
@@ -6,11 +6,12 @@ from re import search as RSearch
|
||||
import pandas as pd
|
||||
from ast import literal_eval as LEval
|
||||
|
||||
weights_dir = 'weights/'
|
||||
weights_dir = "weights/"
|
||||
|
||||
|
||||
def find_biggest_tensorboard(tensordir):
|
||||
try:
|
||||
files = [f for f in os.listdir(tensordir) if f.endswith('.0')]
|
||||
files = [f for f in os.listdir(tensordir) if f.endswith(".0")]
|
||||
if not files:
|
||||
print("No files with the '.0' extension found!")
|
||||
return
|
||||
@@ -32,92 +33,96 @@ def find_biggest_tensorboard(tensordir):
|
||||
print("Couldn't find your model!")
|
||||
return
|
||||
|
||||
|
||||
def main(model_name, save_freq, lastmdls):
|
||||
global lowestval_weight_dir, scl
|
||||
|
||||
tensordir = os.path.join('logs', model_name)
|
||||
tensordir = os.path.join("logs", model_name)
|
||||
lowestval_weight_dir = os.path.join(tensordir, "lowestvals")
|
||||
|
||||
|
||||
latest_file = find_biggest_tensorboard(tensordir)
|
||||
|
||||
|
||||
if latest_file is None:
|
||||
print("Couldn't find a valid tensorboard file!")
|
||||
return
|
||||
|
||||
|
||||
tfile = os.path.join(tensordir, latest_file)
|
||||
|
||||
ea = event_accumulator.EventAccumulator(tfile,
|
||||
|
||||
ea = event_accumulator.EventAccumulator(
|
||||
tfile,
|
||||
size_guidance={
|
||||
event_accumulator.COMPRESSED_HISTOGRAMS: 500,
|
||||
event_accumulator.IMAGES: 4,
|
||||
event_accumulator.AUDIO: 4,
|
||||
event_accumulator.SCALARS: 0,
|
||||
event_accumulator.HISTOGRAMS: 1,
|
||||
})
|
||||
event_accumulator.COMPRESSED_HISTOGRAMS: 500,
|
||||
event_accumulator.IMAGES: 4,
|
||||
event_accumulator.AUDIO: 4,
|
||||
event_accumulator.SCALARS: 0,
|
||||
event_accumulator.HISTOGRAMS: 1,
|
||||
},
|
||||
)
|
||||
|
||||
ea.Reload()
|
||||
ea.Tags()
|
||||
|
||||
scl = ea.Scalars('loss/g/total')
|
||||
scl = ea.Scalars("loss/g/total")
|
||||
|
||||
listwstep = {}
|
||||
|
||||
|
||||
for val in scl:
|
||||
if (val.step // save_freq) * save_freq in [val.step for val in scl]:
|
||||
listwstep[float(val.value)] = (val.step // save_freq) * save_freq
|
||||
|
||||
lowest_vals = sorted(listwstep.keys())[:lastmdls]
|
||||
|
||||
sorted_dict = {value: step for value, step in listwstep.items() if value in lowest_vals}
|
||||
|
||||
sorted_dict = {
|
||||
value: step for value, step in listwstep.items() if value in lowest_vals
|
||||
}
|
||||
|
||||
return sorted_dict
|
||||
|
||||
|
||||
def selectweights(model_name, file_dict, weights_dir, lowestval_weight_dir):
|
||||
os.makedirs(lowestval_weight_dir, exist_ok=True)
|
||||
logdir = []
|
||||
files = []
|
||||
lbldict = {
|
||||
'Values': {},
|
||||
'Names': {}
|
||||
}
|
||||
lbldict = {"Values": {}, "Names": {}}
|
||||
weights_dir_path = os.path.join(weights_dir, "")
|
||||
low_val_path = os.path.join(os.getcwd(), os.path.join(lowestval_weight_dir, ""))
|
||||
|
||||
|
||||
try:
|
||||
file_dict = LEval(file_dict)
|
||||
except Exception as e:
|
||||
except Exception as e:
|
||||
print(f"Error! {e}")
|
||||
return f"Couldn't load tensorboard file! {e}"
|
||||
|
||||
|
||||
weights = [f for f in os.scandir(weights_dir)]
|
||||
for key, value in file_dict.items():
|
||||
pattern = fr"^{model_name}_.*_s{value}\.pth$"
|
||||
matching_weights = [f.name for f in weights if f.is_file() and RSearch(pattern, f.name)]
|
||||
pattern = rf"^{model_name}_.*_s{value}\.pth$"
|
||||
matching_weights = [
|
||||
f.name for f in weights if f.is_file() and RSearch(pattern, f.name)
|
||||
]
|
||||
for weight in matching_weights:
|
||||
source_path = weights_dir_path + weight
|
||||
destination_path = os.path.join(lowestval_weight_dir, weight)
|
||||
|
||||
|
||||
copy2(source_path, destination_path)
|
||||
|
||||
logdir.append(f"File = {weight} Value: {key}, Step: {value}")
|
||||
|
||||
lbldict['Names'][weight] = weight
|
||||
lbldict['Values'][weight] = key
|
||||
lbldict["Names"][weight] = weight
|
||||
lbldict["Values"][weight] = key
|
||||
|
||||
files.append(low_val_path + weight)
|
||||
|
||||
print(f"File = {weight} Value: {key}, Step: {value}")
|
||||
|
||||
yield ('\n'.join(logdir), files, pd.DataFrame(lbldict))
|
||||
|
||||
yield ("\n".join(logdir), files, pd.DataFrame(lbldict))
|
||||
|
||||
return "".join(logdir), files, pd.DataFrame(lbldict)
|
||||
|
||||
return ''.join(logdir), files, pd.DataFrame(lbldict)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
model = str(input("Enter the name of the model: "))
|
||||
sav_freq = int(input("Enter save frequency of the model: "))
|
||||
ds = main(model, sav_freq)
|
||||
|
||||
if ds: selectweights(model, ds, weights_dir, lowestval_weight_dir)
|
||||
|
||||
|
||||
if ds:
|
||||
selectweights(model, ds, weights_dir, lowestval_weight_dir)
|
||||
|
||||
@@ -271,9 +271,11 @@ def load_wav_to_torch(full_path):
|
||||
|
||||
|
||||
def load_filepaths_and_text(filename, split="|"):
|
||||
with open(filename, encoding='utf-8') as f:
|
||||
with open(filename, encoding="utf-8") as f:
|
||||
filepaths_and_text = [line.strip().split(split) for line in f]
|
||||
filepaths_and_text = [item for item in filepaths_and_text if len(item) == 5] # ensure there are 5 items.
|
||||
filepaths_and_text = [
|
||||
item for item in filepaths_and_text if len(item) == 5
|
||||
] # ensure there are 5 items.
|
||||
return filepaths_and_text
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user