11 self = p.buildPythonApplication rec {
12 pname = "backgroundremover";
16 src = fetchFromGitHub {
18 repo = "backgroundremover";
20 hash = "sha256-LjVT4j0OzfbVSQgU0z/gzRTLm7N0RQRrfxtTugWwOxs=";
23 models = runCommand "background-remover-models" {} ''
25 cat ${src}/models/u2a{a,b,c,d} > $out/u2net.pth
26 cat ${src}/models/u2ha{a,b,c,d} > $out/u2net_human_seg.pth
27 cp ${src}/models/u2netp.pth $out
31 substituteInPlace backgroundremover/bg.py backgroundremover/u2net/detect.py \
32 --replace-fail 'os.path.expanduser(os.path.join("~", ".u2net", model_name + ".pth"))' "os.path.join(\"$models\", model_name + \".pth\")"
35 nativeBuildInputs = [ p.setuptools p.wheel ];
37 pythonRelaxDeps = [ "pillow" "torchvision" ];
39 propagatedBuildInputs = [
64 pythonImportsCheck = [ "backgroundremover" ];
70 # random no copyright car image from the internet
71 demoImage = fetchurl {
72 url = "https://pics.craiyon.com/2023-07-16/38653769ac3b4e068181cb5ab1e542a1.webp";
73 hash = "sha256-Kvd06eZdibgDbabVVe0+cNTeS1rDnMXIZZpPlHIlfBo=";
75 in runCommand "backgroundremover-image-test.png" {
76 buildInputs = [ self ];
78 export NUMBA_CACHE_DIR=$(mktemp -d)
79 backgroundremover -i ${demoImage} -o $out
82 updateScript = gitUpdater { rev-prefix = "v"; };
85 doCheck = false; # no tests
88 mainProgram = "backgroundremover";
89 description = "Command line tool to remove background from image and video, made by nadermx to power";
90 homepage = "https://BackgroundRemoverAI.com";
91 downloadPage = "https://github.com/nadermx/backgroundremover/releases";
92 license = licenses.mit;
93 maintainers = [ maintainers.lucasew ];