Spaces:
Sleeping
Sleeping
add ui.py
Browse files
ui.py
ADDED
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import os
|
3 |
+
import subprocess
|
4 |
+
|
5 |
+
# Function to save uploaded file
|
6 |
+
def save_uploaded_file(uploaded_file):
|
7 |
+
try:
|
8 |
+
with open(os.path.join("uploaded_files", uploaded_file.name), "wb") as f:
|
9 |
+
f.write(uploaded_file.getbuffer())
|
10 |
+
return True
|
11 |
+
except:
|
12 |
+
return False
|
13 |
+
|
14 |
+
# Function to process audio file with demucs
|
15 |
+
def process_audio_with_demucs(audio_file_path):
|
16 |
+
try:
|
17 |
+
subprocess.run(['demucs',"--mp3", audio_file_path], check=True)
|
18 |
+
return True
|
19 |
+
except subprocess.CalledProcessError as e:
|
20 |
+
st.error(f"Error executing demucs command: {e}")
|
21 |
+
return False
|
22 |
+
|
23 |
+
# Create a directory to save uploaded files
|
24 |
+
if not os.path.exists('uploaded_files'):
|
25 |
+
os.mkdir('uploaded_files')
|
26 |
+
|
27 |
+
st.title('SoundForge: Agile CI/CD for Improved Audio Separation')
|
28 |
+
|
29 |
+
uploaded_file = st.file_uploader("Choose an audio file", type=['mp3', 'wav'])
|
30 |
+
|
31 |
+
if uploaded_file is not None:
|
32 |
+
# Display the file details
|
33 |
+
file_details = {"FileName": uploaded_file.name, "FileType": uploaded_file.type}
|
34 |
+
|
35 |
+
if save_uploaded_file(uploaded_file):
|
36 |
+
st.success("File Saved Successfully")
|
37 |
+
|
38 |
+
# Display audio player for original file
|
39 |
+
audio_file_path = os.path.join("uploaded_files", uploaded_file.name)
|
40 |
+
audio_bytes = open(audio_file_path, "rb").read()
|
41 |
+
|
42 |
+
# Display side-by-side columns
|
43 |
+
col1, col2 = st.columns(2)
|
44 |
+
with col1:
|
45 |
+
st.markdown("### Original Audio")
|
46 |
+
st.audio(audio_bytes, format='audio/mp3', start_time=0)
|
47 |
+
|
48 |
+
with col2:
|
49 |
+
st.markdown("### Processed Audio (Demucs)")
|
50 |
+
if st.button("Process Audio with Demucs"):
|
51 |
+
if process_audio_with_demucs(audio_file_path):
|
52 |
+
processed_audio_file_path = os.path.join("separated", "htdemucs", os.path.splitext(uploaded_file.name)[0], "vocals.mp3")
|
53 |
+
if os.path.exists(processed_audio_file_path):
|
54 |
+
processed_audio_bytes = open(processed_audio_file_path, "rb").read()
|
55 |
+
st.audio(processed_audio_bytes, format='audio/mp3', start_time=0)
|
56 |
+
else:
|
57 |
+
st.error("Processed audio file not found.")
|
58 |
+
else:
|
59 |
+
st.error("Error processing audio with Demucs.")
|