otadump: init at 0.1.2 (#329129)
[NixPkgs.git] / pkgs / by-name / ba / backgroundremover / package.nix
blob3c9eab61566aa3c080c72c40d0123bc0fb0a6b52
2   python3,
3   lib,
4   runCommand,
5   fetchFromGitHub,
6   fetchurl,
7   gitUpdater,
8 }:
10 let
11   p = python3.pkgs;
12   self = p.buildPythonApplication rec {
13     pname = "backgroundremover";
14     version = "0.2.8";
15     pyproject = true;
17     src = fetchFromGitHub {
18       owner = "nadermx";
19       repo = "backgroundremover";
20       rev = "v${version}";
21       hash = "sha256-LjVT4j0OzfbVSQgU0z/gzRTLm7N0RQRrfxtTugWwOxs=";
22     };
24     models = runCommand "background-remover-models" { } ''
25       mkdir $out
26       cat ${src}/models/u2a{a,b,c,d} > $out/u2net.pth
27       cat ${src}/models/u2ha{a,b,c,d} > $out/u2net_human_seg.pth
28       cp ${src}/models/u2netp.pth $out
29     '';
31     postPatch = ''
32       substituteInPlace backgroundremover/bg.py backgroundremover/u2net/detect.py \
33         --replace-fail 'os.path.expanduser(os.path.join("~", ".u2net", model_name + ".pth"))' "os.path.join(\"$models\", model_name + \".pth\")"
34     '';
36     nativeBuildInputs = [
37       p.setuptools
38       p.wheel
39     ];
41     pythonRelaxDeps = [
42       "pillow"
43       "torchvision"
44     ];
46     propagatedBuildInputs = [
47       p.certifi
48       p.charset-normalizer
49       p.ffmpeg-python
50       p.filelock
51       p.filetype
52       p.hsh
53       p.idna
54       p.more-itertools
55       p.moviepy
56       p.numpy
57       p.pillow
58       p.pymatting
59       p.pysocks
60       p.requests
61       p.scikit-image
62       p.scipy
63       p.six
64       p.torch
65       p.torchvision
66       p.tqdm
67       p.urllib3
68       p.waitress
69     ];
71     pythonImportsCheck = [ "backgroundremover" ];
73     passthru = {
74       inherit models;
75       tests = {
76         image =
77           let
78             # random no copyright car image from the internet
79             demoImage = fetchurl {
80               url = "https://pics.craiyon.com/2023-07-16/38653769ac3b4e068181cb5ab1e542a1.webp";
81               hash = "sha256-Kvd06eZdibgDbabVVe0+cNTeS1rDnMXIZZpPlHIlfBo=";
82             };
83           in
84           runCommand "backgroundremover-image-test.png"
85             {
86               buildInputs = [ self ];
87             }
88             ''
89               export NUMBA_CACHE_DIR=$(mktemp -d)
90               backgroundremover -i ${demoImage} -o $out
91             '';
92       };
93       updateScript = gitUpdater { rev-prefix = "v"; };
94     };
96     doCheck = false; # no tests
98     meta = with lib; {
99       mainProgram = "backgroundremover";
100       description = "Command line tool to remove background from image and video, made by nadermx to power";
101       homepage = "https://BackgroundRemoverAI.com";
102       downloadPage = "https://github.com/nadermx/backgroundremover/releases";
103       license = licenses.mit;
104       maintainers = [ maintainers.lucasew ];
105     };
106   };
108 self