Spaces:
Build error
Build error
import streamlit as st | |
import tempfile | |
import shutil | |
import os | |
import random | |
import string | |
import subprocess | |
# os.system("conda install -c conda-forge ffmpeg libsndfile -y") | |
st.set_page_config(page_title='Music Vocabulary Splitter', layout='wide', initial_sidebar_state='collapsed') | |
st.title('Music Vocabulary Splitter') | |
# Adding space for aesthetics | |
st.markdown('<br>', unsafe_allow_html=True) | |
st.header('Welcome to the Music Vocabulary Splitter :musical_note:') | |
st.markdown(""" | |
This application is designed to help you **analyze and split the vocabulary** associated with your music files. Whether you're looking to categorize lyrics, analyze word usage, or better understand the thematic elements of your songs, **Music Vocabulary Splitter** is your go-to tool. | |
With Music Vocabulary Splitter, you can: | |
- :musical_note: Split and categorize words from lyrics or song descriptions. | |
- :bar_chart: Generate insights into the frequency and distribution of words. | |
- :mag: Apply these insights to understand themes and patterns across your music collection. | |
:microphone: Upload your music files and let's get started! | |
""", unsafe_allow_html=True) | |
# Adding space for aesthetics | |
st.markdown('<br>', unsafe_allow_html=True) | |
def run_shell_command(command): | |
process = subprocess.Popen( | |
command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True, shell=True | |
) | |
while True: | |
output = process.stdout.readline() | |
if output == '' and process.poll() is not None: | |
break | |
if output: | |
st.write(output.strip()) | |
rc = process.poll() | |
return rc | |
def create_download_link(video_file): | |
with open(video_file.name, "rb") as f: | |
file_bytes = f.read() | |
b64 = base64.b64encode(file_bytes).decode() | |
download_link = f'<a href="data:video/mp4;base64,{b64}" download="{video_file.name}">Download video file</a>' | |
st.markdown(download_link, unsafe_allow_html=True) | |
def save_uploaded_file(uploaded_file): | |
save_dir = "/tmp/uploaded_videos" # Change this to the desired folder | |
if not os.path.exists(save_dir): | |
os.makedirs(save_dir) | |
with open(os.path.join(save_dir, uploaded_file.name), "wb") as f: | |
f.write(uploaded_file.getbuffer()) | |
st.success(f"File '{uploaded_file.name}' saved to folder '{save_dir}'") | |
return uploaded_file.name, save_dir | |
video_file = st.file_uploader("Upload a video file", type=['mp4', 'mov', 'avi', 'flv', 'wmv', 'webm','mp3']) | |
if video_file is not None: | |
tfile = tempfile.NamedTemporaryFile(delete=False) | |
tfile.write(video_file.read()) | |
st.video(tfile.name) | |
filename, video_path = save_uploaded_file(video_file) | |
# create_download_link(video_file) | |
save_dir = "/tmp/vocals" | |
ip_dir = video_path + "/" + filename | |
# print(f"spleeter separate -o {save_dir} '{ip_dir}'") | |
# Example command to run | |
command = f"spleeter separate -o {save_dir} '{ip_dir}'" | |
# Run the shell command and display live results | |
return_code = run_shell_command(command) | |
st.write(f"\nCommand finished with return code: {return_code}") | |
op_file_vocals = save_dir + "/" + filename.split(".")[0] + "/vocals.wav" | |
op_file_music = save_dir + "/" + filename.split(".")[0] + "/accompaniment.wav" | |
st.success(f"File '{ip_dir}' processed into vocals {op_file_vocals} and music {op_file_music}") | |
st.audio(op_file_vocals) | |
# create_download_link(op_file_vocals) | |
st.audio(op_file_music) | |
# create_download_link(op_file_music) | |
if st.button("Clear Data"): | |
command = f"rm -R uploaded_videos" | |
run_shell_command(command) | |
command = f"rm -R vocals" | |
run_shell_command(command) | |