diff --git a/requirements.cuda.txt b/requirements.cuda.txt index d8754c0..88f6fbc 100644 Binary files a/requirements.cuda.txt and b/requirements.cuda.txt differ 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())