Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,4 +1,51 @@
|
|
| 1 |
import streamlit as st
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
-
|
| 4 |
-
st.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
import os
|
| 3 |
+
import tempfile
|
| 4 |
+
import subprocess
|
| 5 |
|
| 6 |
+
# Set Streamlit app title
|
| 7 |
+
st.title("Audio Processing App")
|
| 8 |
+
|
| 9 |
+
# Function to process the audio file
|
| 10 |
+
def separate_audio(audio_path):
|
| 11 |
+
|
| 12 |
+
print(f"{audio_path=}")
|
| 13 |
+
head, tail = os.path.split(audio_path)
|
| 14 |
+
|
| 15 |
+
gradio_temp_path = head
|
| 16 |
+
audio_filename = tail.split('.')[0]
|
| 17 |
+
print(f"{gradio_temp_path=}")
|
| 18 |
+
print(f"{audio_filename=}")
|
| 19 |
+
|
| 20 |
+
# command = f"spleeter separate -o {gradio_temp_path} -p spleeter:2stems {audio_path}"
|
| 21 |
+
# command = f"ls {gradio_temp_path}"
|
| 22 |
+
command = f"cp {audio_path} output/test.wav"
|
| 23 |
+
command = command.split()
|
| 24 |
+
print(f"{command=}")
|
| 25 |
+
|
| 26 |
+
result = subprocess.run(command)
|
| 27 |
+
print(result)
|
| 28 |
+
|
| 29 |
+
print("--------")
|
| 30 |
+
accompaniment_path = f"{gradio_temp_path}/{audio_filename}/accompaniment.wav"
|
| 31 |
+
vocals_path = f"{gradio_temp_path}/{audio_filename}/vocals.wav"
|
| 32 |
+
print(f"{accompaniment_path=}")
|
| 33 |
+
print(os.path.exists(accompaniment_path))
|
| 34 |
+
print(f"{vocals_path=}")
|
| 35 |
+
print(os.path.exists(vocals_path))
|
| 36 |
+
|
| 37 |
+
return vocals_path, accompaniment_path
|
| 38 |
+
|
| 39 |
+
# Streamlit app content
|
| 40 |
+
st.write("Upload an audio file (.wav)")
|
| 41 |
+
|
| 42 |
+
uploaded_file = st.file_uploader("Choose a file", type=["wav"])
|
| 43 |
+
|
| 44 |
+
if uploaded_file is not None:
|
| 45 |
+
# Process the uploaded audio file
|
| 46 |
+
vocals_path, accompaniment_path = process_audio(uploaded_file)
|
| 47 |
+
|
| 48 |
+
# Display the output files for download
|
| 49 |
+
st.write("Output Files:")
|
| 50 |
+
st.audio(vocals_path, format="audio/wav", start_time=0)
|
| 51 |
+
st.audio(accompaniment_path, format="audio/wav", start_time=0)
|