From 2c52a8085ae8b7d72449b4af8e8603992c725446 Mon Sep 17 00:00:00 2001 From: oitsjustjose Date: Wed, 25 Jun 2025 14:55:19 -0500 Subject: [PATCH] Streamlit integration maybe? --- requirements.cuda.txt | Bin 221 -> 2536 bytes src/processor.py | 12 +++++++---- src/web.py | 49 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 57 insertions(+), 4 deletions(-) create mode 100644 src/web.py diff --git a/requirements.cuda.txt b/requirements.cuda.txt index d8754c06e42459bb9a83cbb214b14e30b2007da0..88f6fbcefd84b7e7b6220a9cdc9b973e8acd6e22 100644 GIT binary patch literal 2536 zcmai$PjAyu5X9dZiBE!pNYVy4aNvND5S5U6;#9ebQ_?1Oh@H0K!vpi%@yko43RI;K z@4wmE*>(T?uF^X7sYtnY{4K zUPSlGwA6XGSdc4!i6h?Gv2K;S zmc0rdn2vcc3iGrW5L_us9ZbMT#$vSYxmGu@vmNSDi_TrImIi8JnjT}B_uJ@$3BUo} zX3oq7@y3yTdga;57X(zFoOpDqjBOs)GEX=$iW^nxh2lCq3M1~|b6CHfsFf;tDraII zURR25#6+_OD6Yv ztJ$N%y`rhaJYdV5uT`JztA)vY!DgA)Iz7t1j!5`}1+#Ra$eonE7uT2i|57d!} z;C*@YDJak?{d0{rV#+n1BHc!YJN-sGjedi}cf!5k(MS{3z%v+14R(AT%6^E*@lmy& z5Gt2=pX9}D;Nq`@GtcvB6jRFYfRVDJj9MKNW0k=hn8ChP^-i|ZU9Vef z=CjhRMzDVu;*0e4h_$GY`-VRG7oC?0;xmoToClAe!c#}xyjA#s%bSl6@1?^@9;-HM zb|>TuW$-%>yv9;45bwU_FlTJz$nQQo?ZZksXye`1JUgpS9z~~PZF8>ONyBX1Hh7?7 z;Q=l|&(3ob`tUJ!=9KI2Rh>;>D#ge9&&GA?y=)xuV=9U6b1MB3ipzm#7eC~7B1Wiet?AD*al)!^03X{TPq5>oim)FR8J`=Y8>i` z=3rNSN<%y_hJJL`D})@C6ZLQvmx8>QR=2SIevSV_rY4?A)$7lXRK z9ud8pl^PnTzVsBMcF8FFzkI}GTuG{vQh<1UFL^09Py=7T>kCpDjsNANdKh<`VFd#C E69g+ncK`qY diff --git a/src/processor.py b/src/processor.py index 2788615..c18c111 100644 --- a/src/processor.py +++ b/src/processor.py @@ -38,8 +38,8 @@ class FolderProcessor: self.model_name = model_name self.verbose: bool = verbose - @classmethod - def from_args(self, args: argset, output: CliOutput): + @staticmethod + def from_args(args: argset, output: CliOutput): """Creates a FolderProcessor instance using an argparse argument set Args: @@ -48,7 +48,8 @@ class FolderProcessor: """ return FolderProcessor(args.input_dir, args.output_dir, args.model, output, args.verbose) - def _is_ffmpeg_present(self) -> bool: + @staticmethod + def is_ffmpeg_present() -> bool: """Determines if ffmpeg is installed and accessible Returns: @@ -69,7 +70,7 @@ class FolderProcessor: Also ensures that metadata is copied from the old file to the new one to provide the best user experience in the end """ - if not self._is_ffmpeg_present(): + if not FolderProcessor.is_ffmpeg_present(): raise Exception("FFMpeg is not installed! Please install it from here: https://www.ffmpeg.org/download.html") src: Path = Path(self.input_dir) @@ -130,6 +131,9 @@ class FolderProcessor: original_tag: Tag = original_file.get_tag() no_drums_audiofile = eyed3.load(str(no_drums_path)) + if not no_drums_audiofile: + raise Exception(f"Failed to load eyed3 tags from {str(no_drums_path)}") + no_drums_audiofile.tag = original_tag no_drums_audiofile.tag.title = f"{original_tag.title} (No Drums)" no_drums_audiofile.tag.save(version=ID3_V2_4) diff --git a/src/web.py b/src/web.py new file mode 100644 index 0000000..62f9f64 --- /dev/null +++ b/src/web.py @@ -0,0 +1,49 @@ +from pathlib import Path +from typing import List +from uuid import uuid4 +from os import makedirs + +import streamlit as st + +from common import SUPPORTED_EXTS, MODEL_CHOICES +from music_file import MusicFile +from dataclasses import dataclass + + +@dataclass +class ConvertedFile: + name: str + path: Path + + +st.set_page_config(page_title="Drum Track Converter", page_icon="🥁", layout="centered") + +st.header("Drum Track Converter") +st.subheader("Take any audio file and strip the drums out of it for drum practice!") + +model_name = st.selectbox("DEMUCS Model", MODEL_CHOICES) +files = st.file_uploader( + type=SUPPORTED_EXTS, + accept_multiple_files=True, + label="Select your music files you'd like to convert", +) + +converted_files: List[ConvertedFile] = [] + +if files: + job_id = str(uuid4()) + prog = st.progress(value=0, text="Working on it..") + for idx, file in enumerate(files): + makedirs(f"./.tmp/{job_id}") + file_name = Path(f"./.tmp/{job_id}/{file.name}").resolve() + with open(file_name, "wb") as fh: + fh.write(file.read()) + + music_file = MusicFile(file_name, MODEL_CHOICES[model_name]) + converted_files.append(ConvertedFile(name=file.name, path=music_file.separate())) + prog.progress(idx + 1) + + prog.empty() + + for conv in converted_files: + st.download_button(conv.name, conv.path.read_bytes())