Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
@@ -51,7 +51,10 @@ HEADER = """
|
|
51 |
|
52 |
CACHE_EXAMPLES = os.getenv('CACHE_EXAMPLES', '1') == '1'
|
53 |
|
54 |
-
|
|
|
|
|
|
|
55 |
"""Compresses specific files in the specified folder into a .zip file"""
|
56 |
# List of the files to be compressed
|
57 |
wav_files = ['bass.wav', 'drums.wav', 'other.wav', 'vocals.wav']
|
@@ -59,7 +62,7 @@ def compress_files(folder_path, dissector_file, original_audio):
|
|
59 |
|
60 |
def convert_to_mp3(wav, mp3):
|
61 |
"""Utility function to run the ffmpeg command"""
|
62 |
-
command = ["ffmpeg", "-i", os.path.join(
|
63 |
process = Popen(command)
|
64 |
process.communicate()
|
65 |
|
@@ -67,11 +70,26 @@ def compress_files(folder_path, dissector_file, original_audio):
|
|
67 |
with ThreadPoolExecutor(max_workers=8) as executor:
|
68 |
list(executor.map(convert_to_mp3, wav_files, mp3_files))
|
69 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
70 |
# Compress the files
|
71 |
-
zip_path =
|
72 |
with zipfile.ZipFile(zip_path, 'w', zipfile.ZIP_DEFLATED) as zipf:
|
73 |
for mp3 in mp3_files:
|
74 |
-
zipf.write(os.path.join(
|
|
|
|
|
|
|
75 |
zipf.write(dissector_file, arcname='dissector.json') # Fixed name
|
76 |
zipf.write(original_audio, arcname='mixdown.mp3') # Added original audio
|
77 |
|
|
|
51 |
|
52 |
CACHE_EXAMPLES = os.getenv('CACHE_EXAMPLES', '1') == '1'
|
53 |
|
54 |
+
BASIC_PITCH_DIR = "/app/basic-pitch"
|
55 |
+
|
56 |
+
|
57 |
+
def compress_files(demucs_output_path, dissector_file, original_audio):
|
58 |
"""Compresses specific files in the specified folder into a .zip file"""
|
59 |
# List of the files to be compressed
|
60 |
wav_files = ['bass.wav', 'drums.wav', 'other.wav', 'vocals.wav']
|
|
|
62 |
|
63 |
def convert_to_mp3(wav, mp3):
|
64 |
"""Utility function to run the ffmpeg command"""
|
65 |
+
command = ["ffmpeg", "-i", os.path.join(demucs_output_path, wav), os.path.join(demucs_output_path, mp3)]
|
66 |
process = Popen(command)
|
67 |
process.communicate()
|
68 |
|
|
|
70 |
with ThreadPoolExecutor(max_workers=8) as executor:
|
71 |
list(executor.map(convert_to_mp3, wav_files, mp3_files))
|
72 |
|
73 |
+
if not os.path.exists(basic_pitch_dir):
|
74 |
+
os.makedirs(basic_pitch_dir)
|
75 |
+
command = [
|
76 |
+
"basic-pitch",
|
77 |
+
BASIC_PITCH_DIR,
|
78 |
+
os.path.join(demucs_output_path, 'bass.wav'),
|
79 |
+
os.path.join(demucs_output_path, 'vocals.wav'),
|
80 |
+
os.path.join(demucs_output_path, 'other.wav')
|
81 |
+
]
|
82 |
+
process = Popen(command)
|
83 |
+
process.communicate()
|
84 |
+
|
85 |
# Compress the files
|
86 |
+
zip_path = demucs_output_path + ".zip"
|
87 |
with zipfile.ZipFile(zip_path, 'w', zipfile.ZIP_DEFLATED) as zipf:
|
88 |
for mp3 in mp3_files:
|
89 |
+
zipf.write(os.path.join(demucs_output_path, mp3), arcname=mp3)
|
90 |
+
zipf.write('/app/basic-pitch/bass_basic_pitch.mid', arcname='bass_basic_pitch.mid')
|
91 |
+
zipf.write('/app/basic-pitch/vocals_basic_pitch.mid', arcname='vocals_basic_pitch.mid')
|
92 |
+
zipf.write('/app/basic-pitch/other_basic_pitch.mid', arcname='other_basic_pitch.mid')
|
93 |
zipf.write(dissector_file, arcname='dissector.json') # Fixed name
|
94 |
zipf.write(original_audio, arcname='mixdown.mp3') # Added original audio
|
95 |
|