ASesYusuf1/SESA_Audio_Separation
14
1import os2import glob3import subprocess4import time5import gc6import shutil7import sys8from datetime import datetime9import torch10import yaml11import gradio as gr12import threading13import random14import librosa15import soundfile as sf16import numpy as np17import requests18import json19import locale20import re21import psutil22import concurrent.futures23from tqdm import tqdm24from google.oauth2.credentials import Credentials25import tempfile26from urllib.parse import urlparse, quote27 28import warnings29warnings.filterwarnings("ignore")30 31# BASE_DIR'i dinamik olarak güncel dizine ayarla32BASE_DIR = os.path.dirname(os.path.abspath(__file__)) # processing.py'nin bulunduğu dizin33INFERENCE_PATH = os.path.join(BASE_DIR, "inference.py") # inference.py'nin tam yolu34OUTPUT_DIR = os.path.join(BASE_DIR, "output") # Çıkış dizini BASE_DIR/output olarak güncellendi35AUTO_ENSEMBLE_OUTPUT = os.path.join(BASE_DIR, "ensemble_output") # Ensemble çıkış dizini36 37def clean_model_name(model):38 """39 Clean and standardize model names for filename40 """41 model_name_mapping = {42 'VOCALS-InstVocHQ': 'InstVocHQ',43 'VOCALS-MelBand-Roformer (by KimberleyJSN)': 'KimberleyJSN',44 'VOCALS-BS-Roformer_1297 (by viperx)': 'VOCALS_BS_Roformer1297',45 'VOCALS-BS-Roformer_1296 (by viperx)': 'VOCALS-BS-Roformer_1296',46 'VOCALS-BS-RoformerLargev1 (by unwa)': 'UnwaLargeV1',47 'VOCALS-Mel-Roformer big beta 4 (by unwa)': 'UnwaBigBeta4',48 'VOCALS-Melband-Roformer BigBeta5e (by unwa)': 'UnwaBigBeta5e',49 'INST-Mel-Roformer v1 (by unwa)': 'UnwaInstV1',50 'INST-Mel-Roformer v2 (by unwa)': 'UnwaInstV2',51 'INST-VOC-Mel-Roformer a.k.a. duality (by unwa)': 'UnwaDualityV1',52 'INST-VOC-Mel-Roformer a.k.a. duality v2 (by unwa)': 'UnwaDualityV2',53 'KARAOKE-MelBand-Roformer (by aufr33 & viperx)': 'KaraokeMelBandRoformer',54 'VOCALS-VitLarge23 (by ZFTurbo)': 'VitLarge23',55 'VOCALS-MelBand-Roformer (by Becruily)': 'BecruilyVocals',56 'INST-MelBand-Roformer (by Becruily)': 'BecruilyInst',57 'VOCALS-MelBand-Roformer Kim FT (by Unwa)': 'KimFT',58 'INST-MelBand-Roformer Kim FT (by Unwa)': 'KimFTInst',59 'OTHER-BS-Roformer_1053 (by viperx)': 'OtherViperx1053',60 'CROWD-REMOVAL-MelBand-Roformer (by aufr33)': 'CrowdRemovalRoformer',61 'CINEMATIC-BandIt_Plus (by kwatcharasupat)': 'CinematicBandItPlus',62 'DRUMSEP-MDX23C_DrumSep_6stem (by aufr33 & jarredou)': 'DrumSepMDX23C',63 '4STEMS-SCNet_MUSDB18 (by starrytong)': 'FourStemsSCNet',64 'DE-REVERB-MDX23C (by aufr33 & jarredou)': 'DeReverbMDX23C',65 'DENOISE-MelBand-Roformer-1 (by aufr33)': 'DenoiseMelBand1',66 'DENOISE-MelBand-Roformer-2 (by aufr33)': 'DenoiseMelBand2',67 'INST-MelBand-Roformer (by Becruily)': 'BecruilyInst',68 '4STEMS-SCNet_XL_MUSDB18 (by ZFTurbo)': 'FourStemsSCNetXL',69 '4STEMS-SCNet_Large (by starrytong)': 'FourStemsSCNetLarge',70 '4STEMS-BS-Roformer_MUSDB18 (by ZFTurbo)': 'FourStemsBSRoformer',71 'DE-REVERB-MelBand-Roformer aggr./v2/19.1729 (by anvuew)': 'DeReverbMelBandAggr',72 'DE-REVERB-Echo-MelBand-Roformer (by Sucial)': 'DeReverbEchoMelBand',73 'bleed_suppressor_v1 (by unwa)': 'BleedSuppressorV1',74 'inst_v1e (by unwa)': 'InstV1E',75 'inst_gabox (by Gabox)': 'InstGabox',76 'inst_gaboxBV1 (by Gabox)': 'InstGaboxBV1',77 'inst_gaboxBV2 (by Gabox)': 'InstGaboxBV2',78 'inst_gaboxBFV1 (by Gabox)': 'InstGaboxBFV1',79 'inst_gaboxFV2 (by Gabox)': 'InstGaboxFV2',80 'inst_gaboxFV1 (by Gabox)': 'InstGaboxFV1',81 'dereverb_mel_band_roformer_less_aggressive_anvuew': 'DereverbMelBandRoformerLessAggressive',82 'dereverb_mel_band_roformer_anvuew': 'DereverbMelBandRoformer',83 'VOCALS-Male Female-BS-RoFormer Male Female Beta 7_2889 (by aufr33)': 'MaleFemale-BS-RoFormer-(by aufr33)',84 'VOCALS-MelBand-Roformer (by Becruily)': 'Vocals-MelBand-Roformer-(by Becruily)',85 'VOCALS-MelBand-Roformer Kim FT 2 (by Unwa)': 'Vocals-MelBand-Roformer-KİM-FT-2(by Unwa)',86 'voc_gaboxMelRoformer (by Gabox)': 'voc_gaboxMelRoformer',87 'voc_gaboxBSroformer (by Gabox)': 'voc_gaboxBSroformer',88 'voc_gaboxMelRoformerFV1 (by Gabox)': 'voc_gaboxMelRoformerFV1',89 'voc_gaboxMelRoformerFV2 (by Gabox)': 'voc_gaboxMelRoformerFV2',90 'SYH99999/MelBandRoformerSYHFTB1(by Amane)': 'MelBandRoformerSYHFTB1',91 'inst_V5 (by Gabox)': 'INSTV5-(by Gabox)',92 'inst_Fv4Noise (by Gabox)': 'Inst_Fv4Noise-(by Gabox)',93 'Intrumental_Gabox (by Gabox)': 'Intrumental_Gabox-(by Gabox)',94 'inst_GaboxFv3 (by Gabox)': 'INST_GaboxFv3-(by Gabox)',95 'SYH99999/MelBandRoformerSYHFTB1_Model1 (by Amane)': 'MelBandRoformerSYHFTB1_model1',96 'SYH99999/MelBandRoformerSYHFTB1_Model2 (by Amane)': 'MelBandRoformerSYHFTB1_model2',97 'SYH99999/MelBandRoformerSYHFTB1_Model3 (by Amane)': 'MelBandRoformerSYHFTB1_model3',98 'VOCALS-MelBand-Roformer Kim FT 2 Blendless (by unwa)': 'VOCALS-MelBand-Roformer-Kim-FT-2-Blendless-(by unwa)',99 'inst_gaboxFV6 (by Gabox)': 'inst_gaboxFV6-(by Gabox)',100 'denoisedebleed (by Gabox)': 'denoisedebleed-(by Gabox)',101 'INSTV5N (by Gabox)': 'INSTV5N_(by Gabox)',102 'Voc_Fv3 (by Gabox)': 'Voc_Fv3_(by Gabox)',103 'MelBandRoformer4StemFTLarge (SYH99999)': 'MelBandRoformer4StemFTLarge_(SYH99999)',104 'dereverb_mel_band_roformer_mono (by anvuew)': 'dereverb_mel_band_roformer_mono_(by anvuew)',105 'INSTV6N (by Gabox)': 'INSTV6N_(by Gabox)',106 'KaraokeGabox': 'KaraokeGabox',107 'FullnessVocalModel (by Amane)': 'FullnessVocalModel',108 'Inst_GaboxV7 (by Gabox)': 'Inst_GaboxV7_(by Gabox)',109 }110 111 if model in model_name_mapping:112 return model_name_mapping[model]113 114 cleaned = re.sub(r'\s*\(.*?\)', '', model) # Remove parenthetical info115 cleaned = cleaned.replace('-', '_')116 cleaned = ''.join(char for char in cleaned if char.isalnum() or char == '_')117 118 return cleaned119 120def shorten_filename(filename, max_length=30):121 """122 Shortens a filename to a specified maximum length123 """124 base, ext = os.path.splitext(filename)125 if len(base) <= max_length:126 return filename127 shortened = base[:15] + "..." + base[-10:] + ext128 return shortened129 130def clean_filename(filename):131 """132 Temizlenmiş dosya adını döndürür133 """134 cleanup_patterns = [135 r'_\d{8}_\d{6}_\d{6}$', # _20231215_123456_123456136 r'_\d{14}$', # _20231215123456137 r'_\d{10}$', # _1702658400138 r'_\d+$' # Herhangi bir sayı139 ]140 141 base, ext = os.path.splitext(filename)142 for pattern in cleanup_patterns:143 base = re.sub(pattern, '', base)144 145 file_types = ['vocals', 'instrumental', 'drum', 'bass', 'other', 'effects', 'speech', 'music', 'dry', 'male', 'female']146 for type_keyword in file_types:147 base = base.replace(f'_{type_keyword}', '')148 149 detected_type = None150 for type_keyword in file_types:151 if type_keyword in base.lower():152 detected_type = type_keyword153 break154 155 clean_base = base.strip('_- ')156 return clean_base, detected_type, ext157 