ASesYusuf1/SESA_Audio_Separation
14
1# Kaggle için gerekli kütüphaneleri yükleme2import os3import glob4import subprocess5import time6import gc7import shutil8import sys9from datetime import datetime10import torch11import yaml12import numpy as np13import requests14import json15import locale16import re17import psutil18import concurrent.futures19from tqdm import tqdm20from urllib.parse import urlparse, quote21 22# Ses işleme kütüphaneleri23!pip install librosa soundfile24import librosa25import soundfile as sf26 27# Uyarıları görmezden gel28import warnings29warnings.filterwarnings("ignore")30 31# Kaggle dizin ayarları32BASE_DIR = "/kaggle/working/" # Kaggle'da çalışma dizini33INFERENCE_PATH = os.path.join(BASE_DIR, "inference.py") # inference.py varsa buraya kopyalanmalı34OUTPUT_DIR = os.path.join(BASE_DIR, "output") # Çıkış dizini35AUTO_ENSEMBLE_OUTPUT = os.path.join(BASE_DIR, "ensemble_output") # Ensemble çıkış dizini36 37# Çıkış dizinlerini oluştur38os.makedirs(OUTPUT_DIR, exist_ok=True)39os.makedirs(AUTO_ENSEMBLE_OUTPUT, exist_ok=True)40 41def clean_model_name(model):42 """43 Clean and standardize model names for filename44 """45 model_name_mapping = {46 'VOCALS-InstVocHQ': 'InstVocHQ',47 'VOCALS-MelBand-Roformer (by KimberleyJSN)': 'KimberleyJSN',48 'VOCALS-BS-Roformer_1297 (by viperx)': 'VOCALS_BS_Roformer1297',49 'VOCALS-BS-Roformer_1296 (by viperx)': 'VOCALS-BS-Roformer_1296',50 'VOCALS-BS-RoformerLargev1 (by unwa)': 'UnwaLargeV1',51 'VOCALS-Mel-Roformer big beta 4 (by unwa)': 'UnwaBigBeta4',52 'VOCALS-Melband-Roformer BigBeta5e (by unwa)': 'UnwaBigBeta5e',53 'INST-Mel-Roformer v1 (by unwa)': 'UnwaInstV1',54 'INST-Mel-Roformer v2 (by unwa)': 'UnwaInstV2',55 'INST-VOC-Mel-Roformer a.k.a. duality (by unwa)': 'UnwaDualityV1',56 'INST-VOC-Mel-Roformer a.k.a. duality v2 (by unwa)': 'UnwaDualityV2',57 'KARAOKE-MelBand-Roformer (by aufr33 & viperx)': 'KaraokeMelBandRoformer',58 'VOCALS-VitLarge23 (by ZFTurbo)': 'VitLarge23',59 'VOCALS-MelBand-Roformer (by Becruily)': 'BecruilyVocals',60 'INST-MelBand-Roformer (by Becruily)': 'BecruilyInst',61 'VOCALS-MelBand-Roformer Kim FT (by Unwa)': 'KimFT',62 'INST-MelBand-Roformer Kim FT (by Unwa)': 'KimFTInst',63 'OTHER-BS-Roformer_1053 (by viperx)': 'OtherViperx1053',64 'CROWD-REMOVAL-MelBand-Roformer (by aufr33)': 'CrowdRemovalRoformer',65 'CINEMATIC-BandIt_Plus (by kwatcharasupat)': 'CinematicBandItPlus',66 'DRUMSEP-MDX23C_DrumSep_6stem (by aufr33 & jarredou)': 'DrumSepMDX23C',67 '4STEMS-SCNet_MUSDB18 (by starrytong)': 'FourStemsSCNet',68 'DE-REVERB-MDX23C (by aufr33 & jarredou)': 'DeReverbMDX23C',69 'DENOISE-MelBand-Roformer-1 (by aufr33)': 'DenoiseMelBand1',70 'DENOISE-MelBand-Roformer-2 (by aufr33)': 'DenoiseMelBand2',71 'INST-MelBand-Roformer (by Becruily)': 'BecruilyInst',72 '4STEMS-SCNet_XL_MUSDB18 (by ZFTurbo)': 'FourStemsSCNetXL',73 '4STEMS-SCNet_Large (by starrytong)': 'FourStemsSCNetLarge',74 '4STEMS-BS-Roformer_MUSDB18 (by ZFTurbo)': 'FourStemsBSRoformer',75 'DE-REVERB-MelBand-Roformer aggr./v2/19.1729 (by anvuew)': 'DeReverbMelBandAggr',76 'DE-REVERB-Echo-MelBand-Roformer (by Sucial)': 'DeReverbEchoMelBand',77 'bleed_suppressor_v1 (by unwa)': 'BleedSuppressorV1',78 'inst_v1e (by unwa)': 'InstV1E',79 'inst_gabox (by Gabox)': 'InstGabox',80 'inst_gaboxBV1 (by Gabox)': 'InstGaboxBV1',81 'inst_gaboxBV2 (by Gabox)': 'InstGaboxBV2',82 'inst_gaboxBFV1 (by Gabox)': 'InstGaboxBFV1',83 'inst_gaboxFV2 (by Gabox)': 'InstGaboxFV2',84 'inst_gaboxFV1 (by Gabox)': 'InstGaboxFV1',85 'dereverb_mel_band_roformer_less_aggressive_anvuew': 'DereverbMelBandRoformerLessAggressive',86 'dereverb_mel_band_roformer_anvuew': 'DereverbMelBandRoformer',87 'VOCALS-Male Female-BS-RoFormer Male Female Beta 7_2889 (by aufr33)': 'MaleFemale-BS-RoFormer-(by aufr33)',88 'VOCALS-MelBand-Roformer (by Becruily)': 'Vocals-MelBand-Roformer-(by Becruily)',89 'VOCALS-MelBand-Roformer Kim FT 2 (by Unwa)': 'Vocals-MelBand-Roformer-KİM-FT-2(by Unwa)',90 'voc_gaboxMelRoformer (by Gabox)': 'voc_gaboxMelRoformer',91 'voc_gaboxBSroformer (by Gabox)': 'voc_gaboxBSroformer',92 'voc_gaboxMelRoformerFV1 (by Gabox)': 'voc_gaboxMelRoformerFV1',93 'voc_gaboxMelRoformerFV2 (by Gabox)': 'voc_gaboxMelRoformerFV2',94 'SYH99999/MelBandRoformerSYHFTB1(by Amane)': 'MelBandRoformerSYHFTB1',95 'inst_V5 (by Gabox)': 'INSTV5-(by Gabox)',96 'inst_Fv4Noise (by Gabox)': 'Inst_Fv4Noise-(by Gabox)',97 'Intrumental_Gabox (by Gabox)': 'Intrumental_Gabox-(by Gabox)',98 'inst_GaboxFv3 (by Gabox)': 'INST_GaboxFv3-(by Gabox)',99 'SYH99999/MelBandRoformerSYHFTB1_Model1 (by Amane)': 'MelBandRoformerSYHFTB1_model1',100 'SYH99999/MelBandRoformerSYHFTB1_Model2 (by Amane)': 'MelBandRoformerSYHFTB1_model2',101 'SYH99999/MelBandRoformerSYHFTB1_Model3 (by Amane)': 'MelBandRoformerSYHFTB1_model3',102 'VOCALS-MelBand-Roformer Kim FT 2 Blendless (by unwa)': 'VOCALS-MelBand-Roformer-Kim-FT-2-Blendless-(by unwa)',103 'inst_gaboxFV6 (by Gabox)': 'inst_gaboxFV6-(by Gabox)',104 'denoisedebleed (by Gabox)': 'denoisedebleed-(by Gabox)',105 'INSTV5N (by Gabox)': 'INSTV5N_(by Gabox)',106 'Voc_Fv3 (by Gabox)': 'Voc_Fv3_(by Gabox)',107 'MelBandRoformer4StemFTLarge (SYH99999)': 'MelBandRoformer4StemFTLarge_(SYH99999)',108 'dereverb_mel_band_roformer_mono (by anvuew)': 'dereverb_mel_band_roformer_mono_(by anvuew)',109 'INSTV6N (by Gabox)': 'INSTV6N_(by Gabox)',110 'KaraokeGabox': 'KaraokeGabox',111 'FullnessVocalModel (by Amane)': 'FullnessVocalModel',112 'Inst_GaboxV7 (by Gabox)': 'Inst_GaboxV7_(by Gabox)',113 }114 115 if model in model_name_mapping:116 return model_name_mapping[model]117 118 cleaned = re.sub(r'\s*\(.*?\)', '', model) # Remove parenthetical info119 cleaned = cleaned.replace('-', '_')120 cleaned = ''.join(char for char in cleaned if char.isalnum() or char == '_')121 122 return cleaned123 124def shorten_filename(filename, max_length=30):125 """126 Shortens a filename to a specified maximum length127 """128 base, ext = os.path.splitext(filename)129 if len(base) <= max_length:130 return filename131 shortened = base[:15] + "..." + base[-10:] + ext132 return shortened133 134def clean_filename(filename):135 """136 Temizlenmiş dosya adını döndürür137 """138 cleanup_patterns = [139 r'_\d{8}_\d{6}_\d{6}$', # _20231215_123456_123456140 r'_\d{14}$', # _20231215123456141 r'_\d{10}$', # _1702658400142 r'_\d+$' # Herhangi bir sayı143 ]144 145 base, ext = os.path.splitext(filename)146 for pattern in cleanup_patterns:147 base = re.sub(pattern, '', base)148 149 file_types = ['vocals', 'instrumental', 'drum', 'bass', 'other', 'effects', 'speech', 'music', 'dry', 'male', 'female']150 for type_keyword in file_types:151 base = base.replace(f'_{type_keyword}', '')152 153 detected_type = None154 for type_keyword in file_types:155 if type_keyword in base.lower():156 detected_type = type_keyword157 break158 159 clean_base = base.strip('_- ')160 return clean_base, detected_type, ext161 162# Örnek kullanım (Kaggle veri setinden dosya okuma)163# Veri setiniz /kaggle/input/ altında olmalı164# Örnek: input_file = "/kaggle/input/your-dataset/sample_audio.wav"165# clean_base, detected_type, ext = clean_filename("example_vocals_20231215.wav")166# print(clean_base, detected_type, ext)167 