Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -24,6 +24,7 @@ from threading import Lock
|
|
| 24 |
import scipy.io.wavfile
|
| 25 |
import subprocess
|
| 26 |
import spaces
|
|
|
|
| 27 |
|
| 28 |
# Logging setup
|
| 29 |
logging.basicConfig(level=logging.INFO)
|
|
@@ -635,7 +636,7 @@ def auto_ensemble_process(audio, model_keys, state, seg_size=64, overlap=0.1, ou
|
|
| 635 |
extracted_audio_path = os.path.join("/tmp", f"extracted_audio_{os.path.basename(audio)}.wav")
|
| 636 |
logger.info(f"Extracting audio from video file: {audio}")
|
| 637 |
ffmpeg_command = [
|
| 638 |
-
"ffmpeg", "-i", audio, "-vn", "-acodec", "pcm_s16le", "-ar", "
|
| 639 |
extracted_audio_path, "-y"
|
| 640 |
]
|
| 641 |
try:
|
|
@@ -716,25 +717,50 @@ def auto_ensemble_process(audio, model_keys, state, seg_size=64, overlap=0.1, ou
|
|
| 716 |
continue
|
| 717 |
all_stems.extend(stems_dict[stem_type])
|
| 718 |
|
| 719 |
-
|
| 720 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 721 |
raise ValueError("No valid stems found for ensemble after excluding specified stems.")
|
| 722 |
|
| 723 |
-
weights = [float(w.strip()) for w in weights_str.split(',')] if weights_str.strip() else [1.0] * len(
|
| 724 |
-
if len(weights) != len(
|
| 725 |
-
weights = [1.0] * len(
|
| 726 |
logger.info("Weights mismatched, defaulting to 1.0")
|
| 727 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 728 |
ensemble_args = [
|
| 729 |
-
"--files", *
|
| 730 |
"--type", ensemble_method,
|
| 731 |
"--weights", *[str(w) for w in weights],
|
| 732 |
"--output", output_file
|
| 733 |
]
|
| 734 |
logger.info(f"Running ensemble with args: {ensemble_args}")
|
| 735 |
-
|
| 736 |
-
|
| 737 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 738 |
|
| 739 |
state["current_model_idx"] = 0
|
| 740 |
state["current_audio"] = None
|
|
@@ -745,7 +771,7 @@ def auto_ensemble_process(audio, model_keys, state, seg_size=64, overlap=0.1, ou
|
|
| 745 |
logger.info(f"Ensemble completed, output: {output_file}, took {elapsed:.2f}s")
|
| 746 |
progress(1.0, desc="Ensemble completed")
|
| 747 |
status = f"Ensemble completed with {ensemble_method}, excluded: {exclude_stems if exclude_stems else 'None'}, {len(model_keys)} models in {elapsed:.2f}s<br>Download files:<ul>"
|
| 748 |
-
file_list = [output_file] +
|
| 749 |
for file in file_list:
|
| 750 |
file_name = os.path.basename(file)
|
| 751 |
status += f"<li><a href='file={file}' download>{file_name}</a></li>"
|
|
@@ -848,7 +874,12 @@ def auto_ensemble_process(audio, model_keys, state, seg_size=64, overlap=0.1, ou
|
|
| 848 |
|
| 849 |
except Exception as e:
|
| 850 |
logger.error(f"Ensemble error: {e}")
|
| 851 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 852 |
raise RuntimeError(error_msg)
|
| 853 |
|
| 854 |
finally:
|
|
|
|
| 24 |
import scipy.io.wavfile
|
| 25 |
import subprocess
|
| 26 |
import spaces
|
| 27 |
+
import torchaudio
|
| 28 |
|
| 29 |
# Logging setup
|
| 30 |
logging.basicConfig(level=logging.INFO)
|
|
|
|
| 636 |
extracted_audio_path = os.path.join("/tmp", f"extracted_audio_{os.path.basename(audio)}.wav")
|
| 637 |
logger.info(f"Extracting audio from video file: {audio}")
|
| 638 |
ffmpeg_command = [
|
| 639 |
+
"ffmpeg", "-i", audio, "-vn", "-acodec", "pcm_s16le", "-ar", "44100", "-ac", "2",
|
| 640 |
extracted_audio_path, "-y"
|
| 641 |
]
|
| 642 |
try:
|
|
|
|
| 717 |
continue
|
| 718 |
all_stems.extend(stems_dict[stem_type])
|
| 719 |
|
| 720 |
+
# Dosyaların gerçekten var olduğundan emin ol
|
| 721 |
+
valid_stems = []
|
| 722 |
+
for stem in all_stems:
|
| 723 |
+
if os.path.exists(stem):
|
| 724 |
+
valid_stems.append(stem)
|
| 725 |
+
else:
|
| 726 |
+
logger.warning(f"Stem file not found: {stem}")
|
| 727 |
+
|
| 728 |
+
if not valid_stems:
|
| 729 |
raise ValueError("No valid stems found for ensemble after excluding specified stems.")
|
| 730 |
|
| 731 |
+
weights = [float(w.strip()) for w in weights_str.split(',')] if weights_str.strip() else [1.0] * len(valid_stems)
|
| 732 |
+
if len(weights) != len(valid_stems):
|
| 733 |
+
weights = [1.0] * len(valid_stems)
|
| 734 |
logger.info("Weights mismatched, defaulting to 1.0")
|
| 735 |
+
|
| 736 |
+
# Mutlak yol kullanarak çıktı dosyasını belirle
|
| 737 |
+
output_file = os.path.abspath(os.path.join(output_dir, f"{base_name}_ensemble_{ensemble_method}.{out_format}"))
|
| 738 |
+
# Çıktı dizinini oluştur
|
| 739 |
+
os.makedirs(os.path.dirname(output_file), exist_ok=True)
|
| 740 |
+
|
| 741 |
ensemble_args = [
|
| 742 |
+
"--files", *valid_stems,
|
| 743 |
"--type", ensemble_method,
|
| 744 |
"--weights", *[str(w) for w in weights],
|
| 745 |
"--output", output_file
|
| 746 |
]
|
| 747 |
logger.info(f"Running ensemble with args: {ensemble_args}")
|
| 748 |
+
try:
|
| 749 |
+
# Ensemble işlemini denetimli çalıştır
|
| 750 |
+
result = ensemble_files(ensemble_args)
|
| 751 |
+
except Exception as e:
|
| 752 |
+
logger.error(f"Ensemble processing failed: {str(e)}")
|
| 753 |
+
raise RuntimeError(f"Ensemble processing failed: {str(e)}")
|
| 754 |
+
|
| 755 |
+
# Çıktı dosyasının oluştuğundan emin ol
|
| 756 |
+
if not os.path.exists(output_file):
|
| 757 |
+
# Alternatif yol deneyelim
|
| 758 |
+
alt_path = os.path.join(output_dir, f"{base_name}_ensemble_{ensemble_method}.{out_format}")
|
| 759 |
+
if os.path.exists(alt_path):
|
| 760 |
+
logger.info(f"Found ensemble output at alternative path: {alt_path}")
|
| 761 |
+
output_file = alt_path
|
| 762 |
+
else:
|
| 763 |
+
raise RuntimeError(f"Ensemble output file not created: {output_file}")
|
| 764 |
|
| 765 |
state["current_model_idx"] = 0
|
| 766 |
state["current_audio"] = None
|
|
|
|
| 771 |
logger.info(f"Ensemble completed, output: {output_file}, took {elapsed:.2f}s")
|
| 772 |
progress(1.0, desc="Ensemble completed")
|
| 773 |
status = f"Ensemble completed with {ensemble_method}, excluded: {exclude_stems if exclude_stems else 'None'}, {len(model_keys)} models in {elapsed:.2f}s<br>Download files:<ul>"
|
| 774 |
+
file_list = [output_file] + valid_stems
|
| 775 |
for file in file_list:
|
| 776 |
file_name = os.path.basename(file)
|
| 777 |
status += f"<li><a href='file={file}' download>{file_name}</a></li>"
|
|
|
|
| 874 |
|
| 875 |
except Exception as e:
|
| 876 |
logger.error(f"Ensemble error: {e}")
|
| 877 |
+
# Daha açıklayıcı hata mesajı
|
| 878 |
+
error_msg = f"Processing failed: {e}\n\nPossible solutions:\n"
|
| 879 |
+
error_msg += "1. Try fewer models (max 6)\n"
|
| 880 |
+
error_msg += "2. Upload a local WAV/MP4 file instead of YouTube URL\n"
|
| 881 |
+
error_msg += "3. Reduce segment size or overlap\n"
|
| 882 |
+
error_msg += "4. Check if output directory has write permissions"
|
| 883 |
raise RuntimeError(error_msg)
|
| 884 |
|
| 885 |
finally:
|