| | import os |
| | import subprocess |
| | import shutil |
| | from concurrent.futures import ThreadPoolExecutor, as_completed |
| | from tqdm.notebook import tqdm |
| | from pathlib import Path |
| | import requests |
| |
|
| | def run_script(): |
| | def run_cmd(cmd): |
| | process = subprocess.run(cmd, shell=True, check=True, text=True) |
| | return process.stdout |
| |
|
| | |
| | os.chdir('/content/') |
| | print("Changing dir to /content/") |
| |
|
| | |
| | def edit_file(file_path): |
| | temp_file_path = "/tmp/temp_file.py" |
| | changes_made = False |
| | with open(file_path, "r") as file, open(temp_file_path, "w") as temp_file: |
| | previous_line = "" |
| | second_previous_line = "" |
| | for line in file: |
| | new_line = line.replace("value=160", "value=128") |
| | if new_line != line: |
| | print("Replaced 'value=160' with 'value=128'") |
| | changes_made = True |
| | line = new_line |
| |
|
| | new_line = line.replace("crepe hop length: 160", "crepe hop length: 128") |
| | if new_line != line: |
| | print("Replaced 'crepe hop length: 160' with 'crepe hop length: 128'") |
| | changes_made = True |
| | line = new_line |
| |
|
| | new_line = line.replace("value=0.88", "value=0.75") |
| | if new_line != line: |
| | print("Replaced 'value=0.88' with 'value=0.75'") |
| | changes_made = True |
| | line = new_line |
| |
|
| | if "label=i18n(\"输入源音量包络替换输出音量包络融合比例,越靠近1越使用输出包络\")" in previous_line and "value=1," in line: |
| | new_line = line.replace("value=1,", "value=0.25,") |
| | if new_line != line: |
| | print("Replaced 'value=1,' with 'value=0.25,' based on the condition") |
| | changes_made = True |
| | line = new_line |
| |
|
| | if "label=i18n(\"总训练轮数total_epoch\")" in previous_line and "value=20," in line: |
| | new_line = line.replace("value=20,", "value=500,") |
| | if new_line != line: |
| | print("Replaced 'value=20,' with 'value=500,' based on the condition for DEFAULT EPOCH") |
| | changes_made = True |
| | line = new_line |
| |
|
| | if 'choices=["pm", "harvest", "dio", "crepe", "crepe-tiny", "mangio-crepe", "mangio-crepe-tiny"], # Fork Feature. Add Crepe-Tiny' in previous_line: |
| | if 'value="pm",' in line: |
| | new_line = line.replace('value="pm",', 'value="mangio-crepe",') |
| | if new_line != line: |
| | print("Replaced 'value=\"pm\",' with 'value=\"mangio-crepe\",' based on the condition") |
| | changes_made = True |
| | line = new_line |
| |
|
| | new_line = line.replace('label=i18n("输入训练文件夹路径"), value="E:\\\\语音音频+标注\\\\米津玄师\\\\src"', 'label=i18n("输入训练文件夹路径"), value="/content/dataset/"') |
| | if new_line != line: |
| | print("Replaced 'label=i18n(\"输入训练文件夹路径\"), value=\"E:\\\\语音音频+标注\\\\米津玄师\\\\src\"' with 'label=i18n(\"输入训练文件夹路径\"), value=\"/content/dataset/\"'") |
| | changes_made = True |
| | line = new_line |
| |
|
| | if 'label=i18n("是否仅保存最新的ckpt文件以节省硬盘空间"),' in second_previous_line: |
| | if 'value=i18n("否"),' in line: |
| | new_line = line.replace('value=i18n("否"),', 'value=i18n("是"),') |
| | if new_line != line: |
| | print("Replaced 'value=i18n(\"否\"),' with 'value=i18n(\"是\"),' based on the condition for SAVE ONLY LATEST") |
| | changes_made = True |
| | line = new_line |
| |
|
| | if 'label=i18n("是否在每次保存时间点将最终小模型保存至weights文件夹"),' in second_previous_line: |
| | if 'value=i18n("否"),' in line: |
| | new_line = line.replace('value=i18n("否"),', 'value=i18n("是"),') |
| | if new_line != line: |
| | print("Replaced 'value=i18n(\"否\"),' with 'value=i18n(\"是\"),' based on the condition for SAVE SMALL WEIGHTS") |
| | changes_made = True |
| | line = new_line |
| |
|
| | temp_file.write(line) |
| | second_previous_line = previous_line |
| | previous_line = line |
| |
|
| | |
| | import shutil |
| | shutil.move(temp_file_path, file_path) |
| |
|
| | if changes_made: |
| | print("Changes made and file saved successfully.") |
| | else: |
| | print("No changes were needed.") |
| |
|
| | |
| | repo_path = '/content/Retrieval-based-Voice-Conversion-WebUI' |
| |
|
| | def copy_all_files_in_directory(src_dir, dest_dir): |
| | |
| | for item in Path(src_dir).glob('*'): |
| | if item.is_file(): |
| | |
| | shutil.copy(item, dest_dir) |
| | else: |
| | |
| | new_dest = Path(dest_dir) / item.name |
| | new_dest.mkdir(exist_ok=True) |
| | copy_all_files_in_directory(str(item), str(new_dest)) |
| |
|
| | def clone_and_copy_repo(repo_path): |
| | |
| | new_repo_link = "https://github.com/kalomaze/Mangio-Kalo-Tweaks.git" |
| | |
| | temp_repo_path = "/content/temp_Mangio-RVC-Fork" |
| | |
| | new_folder_name = "Mangio-RVC-Fork" |
| |
|
| | |
| | run_cmd(f"git clone {new_repo_link} {temp_repo_path}") |
| | os.chdir(temp_repo_path) |
| |
|
| | run_cmd("git checkout bf0ffdbc35da09b57306e429c6deda84496948a1") |
| |
|
| | run_cmd("wget https://github.com/kalomaze/Mangio-Kalo-Tweaks/raw/patch-1/EasierGUI.py") |
| |
|
| | |
| | edit_file(f"{temp_repo_path}/infer-web.py") |
| |
|
| | |
| | copy_all_files_in_directory(temp_repo_path, repo_path) |
| | print(f"Copying all {new_folder_name} files from GitHub.") |
| |
|
| | |
| | os.chdir('/content/') |
| | print("Changed path back to /content/") |
| | |
| | |
| | shutil.rmtree(temp_repo_path) |
| |
|
| | |
| | clone_and_copy_repo(repo_path) |
| |
|
| | |
| | os.makedirs('/content/Retrieval-based-Voice-Conversion-WebUI/stats/', exist_ok=True) |
| | run_cmd("wget -q https://cdn.discordapp.com/attachments/945486970883285045/1114717554481569802/peppy-generator-388800-07722f17a188.json -O /content/Retrieval-based-Voice-Conversion-WebUI/stats/peppy-generator-388800-07722f17a188.json") |
| |
|
| | |
| | shutil.rmtree('/content/Retrieval-based-Voice-Conversion-WebUI/torchcrepe', ignore_errors=True) |
| | shutil.rmtree('/content/torchcrepe', ignore_errors=True) |
| |
|
| | |
| | run_cmd("git clone https://github.com/maxrmorrison/torchcrepe.git") |
| | shutil.move('/content/torchcrepe/torchcrepe', '/content/Retrieval-based-Voice-Conversion-WebUI/') |
| | shutil.rmtree('/content/torchcrepe', ignore_errors=True) |
| |
|
| | |
| | os.chdir('/content/Retrieval-based-Voice-Conversion-WebUI') |
| | os.makedirs('pretrained', exist_ok=True) |
| | os.makedirs('uvr5_weights', exist_ok=True) |
| |
|
| | def download_file(url, filepath): |
| | response = requests.get(url, stream=True) |
| | response.raise_for_status() |
| |
|
| | with open(filepath, "wb") as file: |
| | for chunk in response.iter_content(chunk_size=8192): |
| | if chunk: |
| | file.write(chunk) |
| |
|
| | def download_pretrained_models(): |
| | pretrained_models = { |
| | "pretrained": [ |
| | "D40k.pth", |
| | "G40k.pth", |
| | "f0D40k.pth", |
| | "f0G40k.pth" |
| | ], |
| | "pretrained_v2": [ |
| | "D40k.pth", |
| | "G40k.pth", |
| | "f0D40k.pth", |
| | "f0G40k.pth", |
| | "f0G48k.pth", |
| | "f0D48k.pth" |
| | ], |
| | "uvr5_weights": [ |
| | "HP2-人声vocals+非人声instrumentals.pth", |
| | "HP5-主旋律人声vocals+其他instrumentals.pth" |
| | ] |
| | } |
| |
|
| | base_url = "https://huggingface.co/lj1995/VoiceConversionWebUI/resolve/main/" |
| | base_path = "/content/Retrieval-based-Voice-Conversion-WebUI/" |
| |
|
| | |
| | total_files = sum(len(files) for files in pretrained_models.values()) + 1 |
| |
|
| | with tqdm(total=total_files, desc="Downloading files") as pbar: |
| | for folder, models in pretrained_models.items(): |
| | folder_path = os.path.join(base_path, folder) |
| | os.makedirs(folder_path, exist_ok=True) |
| | for model in models: |
| | url = base_url + folder + "/" + model |
| | filepath = os.path.join(folder_path, model) |
| | download_file(url, filepath) |
| | pbar.update() |
| |
|
| | |
| | hubert_url = base_url + "hubert_base.pt" |
| | hubert_filepath = os.path.join(base_path, "hubert_base.pt") |
| | download_file(hubert_url, hubert_filepath) |
| | pbar.update() |
| |
|
| | def clone_repository(run_download): |
| | with ThreadPoolExecutor(max_workers=2) as executor: |
| | executor.submit(run_script) |
| | if run_download: |
| | executor.submit(download_pretrained_models) |