1{
2 lib,
3 buildPythonPackage,
4 fetchFromGitHub,
5 setuptools,
6 wheel,
7 versionCheckHook,
8 withCli ? false,
9
10 # dependencies
11 jsonschema,
12 numpy,
13 onnxruntime,
14 opencv-python-headless,
15 pillow,
16 pooch,
17 pymatting,
18 scikit-image,
19 scipy,
20 tqdm,
21
22 # optional-dependencies
23 aiohttp,
24 asyncer,
25 click,
26 fastapi,
27 filetype,
28 gradio,
29 python-multipart,
30 uvicorn,
31 watchdog,
32}:
33
34buildPythonPackage rec {
35 pname = "rembg";
36 version = "2.0.66";
37 pyproject = true;
38
39 src = fetchFromGitHub {
40 owner = "danielgatis";
41 repo = "rembg";
42 tag = "v${version}";
43 hash = "sha256-MTwi9Cy9JWcI0CgUKfnPiA3MFBl/Ie0rYQOm0jqgyS4=";
44 };
45
46 build-system = [
47 setuptools
48 wheel
49 ];
50
51 dependencies = [
52 jsonschema
53 numpy
54 opencv-python-headless
55 onnxruntime
56 pillow
57 pooch
58 pymatting
59 scikit-image
60 scipy
61 tqdm
62 ] ++ lib.optionals withCli optional-dependencies.cli;
63
64 optional-dependencies = {
65 cli = [
66 aiohttp
67 asyncer
68 click
69 fastapi
70 filetype
71 gradio
72 python-multipart
73 uvicorn
74 watchdog
75 ];
76 };
77
78 preConfigure = ''
79 export NUMBA_CACHE_DIR="$(mktemp -d)"
80 '';
81
82 postInstall = lib.optionalString (!withCli) "rm -r $out/bin";
83
84 # not running python tests, as they require network access
85 nativeCheckInputs = lib.optionals withCli [ versionCheckHook ];
86 versionCheckProgramArg = "--version";
87
88 pythonImportsCheck = [ "rembg" ];
89
90 meta = {
91 description = "Tool to remove background from images";
92 homepage = "https://github.com/danielgatis/rembg";
93 changelog = "https://github.com/danielgatis/rembg/releases/tag/${src.tag}";
94 license = lib.licenses.mit;
95 maintainers = with lib.maintainers; [ defelo ];
96 mainProgram = "rembg";
97 platforms = [ "x86_64-linux" ];
98 };
99}