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.67";
37 pyproject = true;
38
39 src = fetchFromGitHub {
40 owner = "danielgatis";
41 repo = "rembg";
42 tag = "v${version}";
43 hash = "sha256-QHx1qa1tErneLC1H6df6mTbKTWPh3BzJUqeE65D2c4E=";
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 ]
63 ++ lib.optionals withCli optional-dependencies.cli;
64
65 optional-dependencies = {
66 cli = [
67 aiohttp
68 asyncer
69 click
70 fastapi
71 filetype
72 gradio
73 python-multipart
74 uvicorn
75 watchdog
76 ];
77 };
78
79 preConfigure = ''
80 export NUMBA_CACHE_DIR="$(mktemp -d)"
81 '';
82
83 postInstall = lib.optionalString (!withCli) "rm -r $out/bin";
84
85 # not running python tests, as they require network access
86 nativeCheckInputs = lib.optionals withCli [ versionCheckHook ];
87 versionCheckProgramArg = "--version";
88
89 pythonImportsCheck = [ "rembg" ];
90
91 meta = {
92 description = "Tool to remove background from images";
93 homepage = "https://github.com/danielgatis/rembg";
94 changelog = "https://github.com/danielgatis/rembg/releases/tag/${src.tag}";
95 license = lib.licenses.mit;
96 maintainers = with lib.maintainers; [ defelo ];
97 mainProgram = "rembg";
98 platforms = [ "x86_64-linux" ];
99 };
100}