From 1b460f28fcf03ea6b31a9f58b4895fcc6aef6a51 Mon Sep 17 00:00:00 2001 From: Zhong Jianxin Date: Thu, 10 Mar 2022 21:52:28 +0800 Subject: [PATCH 1/3] python3Packages.torchlibrosa: init at 0.0.9 --- .../python-modules/torchlibrosa/default.nix | 50 +++++++++++++++++++ pkgs/top-level/python-packages.nix | 2 + 2 files changed, 52 insertions(+) create mode 100644 pkgs/development/python-modules/torchlibrosa/default.nix diff --git a/pkgs/development/python-modules/torchlibrosa/default.nix b/pkgs/development/python-modules/torchlibrosa/default.nix new file mode 100644 index 000000000000..bab73b0dae93 --- /dev/null +++ b/pkgs/development/python-modules/torchlibrosa/default.nix @@ -0,0 +1,50 @@ +{ stdenv +, lib +, buildPythonPackage +, fetchPypi +, fetchpatch +, librosa +, numpy +, torch +}: + +buildPythonPackage rec { + pname = "torchlibrosa"; + version = "0.0.9"; + format = "setuptools"; + + src = fetchPypi { + inherit pname version; + hash = "sha256-+LzejKvLlJIIwWm9rYPCWQDSueIwnG5gbkwNE+wbv0A="; + }; + + propagatedBuildInputs = [ + librosa + numpy + torch + ]; + + patches = [ + # Fix run against librosa 0.9.0, https://github.com/qiuqiangkong/torchlibrosa/pull/8 + (fetchpatch { + url = "https://github.com/qiuqiangkong/torchlibrosa/commit/eec7e7559a47d0ef0017322aee29a31dad0572d5.patch"; + hash = "sha256-c1x3MA14Plm7+lVuqiuLWgSY6FW615qnKbcWAfbrcas="; + }) + ]; + + # Project has no tests. + # In order to make pythonImportsCheck work, NUMBA_CACHE_DIR env var need to + # be set to a writable dir (https://github.com/numba/numba/issues/4032#issuecomment-488102702). + # pythonImportsCheck has no pre* hook, use checkPhase to workaround that. + checkPhase = '' + export NUMBA_CACHE_DIR="$(mktemp -d)" + ''; + pythonImportsCheck = [ "torchlibrosa" ]; + + meta = with lib; { + description = "PyTorch implemention of part of librosa functions"; + homepage = "https://github.com/qiuqiangkong/torchlibrosa"; + license = licenses.mit; + maintainers = with maintainers; [ azuwis ]; + }; +} diff --git a/pkgs/top-level/python-packages.nix b/pkgs/top-level/python-packages.nix index b6aaa8a203bd..1b3aab316282 100644 --- a/pkgs/top-level/python-packages.nix +++ b/pkgs/top-level/python-packages.nix @@ -11349,6 +11349,8 @@ self: super: with self; { torchinfo = callPackage ../development/python-modules/torchinfo { }; + torchlibrosa = callPackage ../development/python-modules/torchlibrosa { }; + torchvision = callPackage ../development/python-modules/torchvision { }; torchvision-bin = callPackage ../development/python-modules/torchvision/bin.nix { }; From 540861c5f87007068fb0841ebb7df31b252d9c31 Mon Sep 17 00:00:00 2001 From: Zhong Jianxin Date: Thu, 10 Mar 2022 21:58:37 +0800 Subject: [PATCH 2/3] python3Packages.piano-transcription-inference: init at 0.0.5 --- .../piano-transcription-inference/default.nix | 75 +++++++++++++++++++ pkgs/top-level/python-packages.nix | 2 + 2 files changed, 77 insertions(+) create mode 100644 pkgs/development/python-modules/piano-transcription-inference/default.nix diff --git a/pkgs/development/python-modules/piano-transcription-inference/default.nix b/pkgs/development/python-modules/piano-transcription-inference/default.nix new file mode 100644 index 000000000000..272f3f6810bf --- /dev/null +++ b/pkgs/development/python-modules/piano-transcription-inference/default.nix @@ -0,0 +1,75 @@ +{ stdenv +, lib +, buildPythonPackage +, fetchPypi +, fetchpatch +, fetchurl +, librosa +, matplotlib +, mido +, torch +, torchlibrosa +}: + +buildPythonPackage rec { + pname = "piano-transcription-inference"; + version = "0.0.5"; + format = "setuptools"; + + src = fetchPypi { + inherit pname version; + hash = "sha256-nbhuSkXuWrekFxwdNHaspuag+3K1cKwq90IpATBpWPY="; + }; + + checkpoint = fetchurl { + name = "piano-transcription-inference.pth"; + # The download url can be found in + # https://github.com/qiuqiangkong/piano_transcription_inference/blob/master/piano_transcription_inference/inference.py + url = "https://zenodo.org/record/4034264/files/CRNN_note_F1%3D0.9677_pedal_F1%3D0.9186.pth?download=1"; + hash = "sha256-w/qXMHJb9Kdi8cFLyAzVmG6s2gGwJvWkolJc1geHYUE="; + }; + + propagatedBuildInputs = [ + librosa + matplotlib + mido + torch + torchlibrosa + ]; + + patches = [ + # Fix run against librosa 0.9.0 + # https://github.com/qiuqiangkong/piano_transcription_inference/pull/10 + (fetchpatch { + url = "https://github.com/qiuqiangkong/piano_transcription_inference/commit/b2d448916be771cd228f709c23c474942008e3e8.patch"; + hash = "sha256-8O4VtFij//k3fhcbMRz4J8Iz4AdOPLkuk3UTxuCSy8U="; + }) + ]; + + postPatch = '' + substituteInPlace piano_transcription_inference/inference.py --replace \ + "checkpoint_path='{}/piano_transcription_inference_data/note_F1=0.9677_pedal_F1=0.9186.pth'.format(str(Path.home()))" \ + "checkpoint_path='$out/share/checkpoint.pth'" + ''; + + postInstall = '' + mkdir "$out/share" + ln -s "${checkpoint}" "$out/share/checkpoint.pth" + ''; + + # Project has no tests. + # In order to make pythonImportsCheck work, NUMBA_CACHE_DIR env var need to + # be set to a writable dir (https://github.com/numba/numba/issues/4032#issuecomment-488102702). + # pythonImportsCheck has no pre* hook, use checkPhase to wordaround that. + checkPhase = '' + export NUMBA_CACHE_DIR="$(mktemp -d)" + ''; + pythonImportsCheck = [ "piano_transcription_inference" ]; + + meta = with lib; { + description = "A piano transcription inference package"; + homepage = "https://github.com/qiuqiangkong/piano_transcription_inference"; + license = licenses.mit; + maintainers = with maintainers; [ azuwis ]; + }; +} diff --git a/pkgs/top-level/python-packages.nix b/pkgs/top-level/python-packages.nix index 1b3aab316282..2491f5462b82 100644 --- a/pkgs/top-level/python-packages.nix +++ b/pkgs/top-level/python-packages.nix @@ -6960,6 +6960,8 @@ self: super: with self; { pi1wire = callPackage ../development/python-modules/pi1wire { }; + piano-transcription-inference = callPackage ../development/python-modules/piano-transcription-inference { }; + piccata = callPackage ../development/python-modules/piccata { }; pick = callPackage ../development/python-modules/pick { }; From e2fa5eea4540e49880d91790ba239fdff5701847 Mon Sep 17 00:00:00 2001 From: Zhong Jianxin Date: Thu, 10 Mar 2022 22:24:07 +0800 Subject: [PATCH 3/3] pianotrans: init at 1.0 --- .../applications/audio/pianotrans/default.nix | 38 +++++++++++++++++++ pkgs/top-level/all-packages.nix | 2 + 2 files changed, 40 insertions(+) create mode 100644 pkgs/applications/audio/pianotrans/default.nix diff --git a/pkgs/applications/audio/pianotrans/default.nix b/pkgs/applications/audio/pianotrans/default.nix new file mode 100644 index 000000000000..89e0716a0adc --- /dev/null +++ b/pkgs/applications/audio/pianotrans/default.nix @@ -0,0 +1,38 @@ +{ lib +, fetchFromGitHub +, python3 +, ffmpeg +}: + +python3.pkgs.buildPythonApplication rec { + pname = "pianotrans"; + version = "1.0"; + format = "setuptools"; + + src = fetchFromGitHub { + owner = "azuwis"; + repo = pname; + rev = "v${version}"; + hash = "sha256-6Otup1Yat1dBZdSoR4lDfpytUQ2RbDXC6ieo835Nw+U="; + }; + + propagatedBuildInputs = with python3.pkgs; [ + piano-transcription-inference + torch + tkinter + ]; + + # Project has no tests + doCheck = false; + + makeWrapperArgs = [ + ''--prefix PATH : "${lib.makeBinPath [ ffmpeg ]}"'' + ]; + + meta = with lib; { + description = "Simple GUI for ByteDance's Piano Transcription with Pedals"; + homepage = "https://github.com/azuwis/pianotrans"; + license = licenses.mit; + maintainers = with maintainers; [ azuwis ]; + }; +} diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 8e15d2571837..7a888082d764 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -31606,6 +31606,8 @@ with pkgs; pianoteq = callPackage ../applications/audio/pianoteq { }; + pianotrans = callPackage ../applications/audio/pianotrans { }; + picard = callPackage ../applications/audio/picard { }; picocom = callPackage ../tools/misc/picocom {