File size: 3,681 Bytes
f7c1917
 
 
 
 
 
 
 
 
 
cf83079
f7c1917
cf83079
6b4e793
cf83079
 
 
 
 
 
6b4e793
 
cf83079
 
 
 
 
 
6b4e793
cf83079
 
6b4e793
 
 
f7c1917
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
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)