Streamlit integration maybe?

This commit is contained in:
oitsjustjose 2025-06-25 14:55:19 -05:00
commit 2c52a8085a
3 changed files with 57 additions and 4 deletions

Binary file not shown.

View file

@ -38,8 +38,8 @@ class FolderProcessor:
self.model_name = model_name self.model_name = model_name
self.verbose: bool = verbose self.verbose: bool = verbose
@classmethod @staticmethod
def from_args(self, args: argset, output: CliOutput): def from_args(args: argset, output: CliOutput):
"""Creates a FolderProcessor instance using an argparse argument set """Creates a FolderProcessor instance using an argparse argument set
Args: Args:
@ -48,7 +48,8 @@ class FolderProcessor:
""" """
return FolderProcessor(args.input_dir, args.output_dir, args.model, output, args.verbose) 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 """Determines if ffmpeg is installed and accessible
Returns: 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 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") raise Exception("FFMpeg is not installed! Please install it from here: https://www.ffmpeg.org/download.html")
src: Path = Path(self.input_dir) src: Path = Path(self.input_dir)
@ -130,6 +131,9 @@ class FolderProcessor:
original_tag: Tag = original_file.get_tag() original_tag: Tag = original_file.get_tag()
no_drums_audiofile = eyed3.load(str(no_drums_path)) 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 = original_tag
no_drums_audiofile.tag.title = f"{original_tag.title} (No Drums)" no_drums_audiofile.tag.title = f"{original_tag.title} (No Drums)"
no_drums_audiofile.tag.save(version=ID3_V2_4) no_drums_audiofile.tag.save(version=ID3_V2_4)

49
src/web.py Normal file
View file

@ -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())