Merge pull request #277394 from lucasew/python/backgroundremover

backgroundremover: init at 0.2.6
This commit is contained in:
Sandro 2024-03-25 23:08:41 +01:00 committed by GitHub
commit 07518c851b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 261 additions and 0 deletions

View File

@ -0,0 +1,92 @@
{ python3
, lib
, runCommand
, fetchFromGitHub
, fetchurl
}:
let
p = python3.pkgs;
self = p.buildPythonApplication rec {
pname = "backgroundremover";
version = "0.2.6";
pyproject = true;
src = fetchFromGitHub {
owner = "nadermx";
repo = "backgroundremover";
rev = "v${version}";
hash = "sha256-dDOo7NPwvdfV+ae2oMUytCGC+2HF6xUI7dyKk2we23w=";
};
models = runCommand "background-remover-models" {} ''
mkdir $out
cat ${src}/models/u2a{a,b,c,d} > $out/u2net.pth
cat ${src}/models/u2ha{a,b,c,d} > $out/u2net_human_seg.pth
cp ${src}/models/u2netp.pth $out
'';
postPatch = ''
substituteInPlace backgroundremover/bg.py backgroundremover/u2net/detect.py \
--replace 'os.path.expanduser(os.path.join("~", ".u2net", model_name + ".pth"))' "os.path.join(\"$models\", model_name + \".pth\")"
'';
nativeBuildInputs = [ p.setuptools p.wheel ];
propagatedBuildInputs = [
p.certifi
p.charset-normalizer
p.ffmpeg-python
p.filelock
p.filetype
p.hsh
p.idna
p.more-itertools
p.moviepy
p.numpy
p.pillow
p.pymatting
p.pysocks
p.requests
p.scikit-image
p.scipy
p.six
p.torch
p.torchvision
p.tqdm
p.urllib3
p.waitress
];
pythonImportsCheck = [ "backgroundremover" ];
passthru = {
inherit models;
tests = {
image = let
# random no copyright car image from the internet
demoImage = fetchurl {
url = "https://pics.craiyon.com/2023-07-16/38653769ac3b4e068181cb5ab1e542a1.webp";
hash = "sha256-Kvd06eZdibgDbabVVe0+cNTeS1rDnMXIZZpPlHIlfBo=";
};
in runCommand "backgroundremover-image-test.png" {
buildInputs = [ self ];
} ''
export NUMBA_CACHE_DIR=$(mktemp -d)
backgroundremover -i ${demoImage} -o $out
'';
};
};
doCheck = false; # no tests
meta = with lib; {
mainProgram = "backgroundremover";
description = "Command line tool to remove background from image and video, made by nadermx to power";
homepage = "https://BackgroundRemoverAI.com";
downloadPage = "https://github.com/nadermx/backgroundremover/releases";
license = licenses.mit;
maintainers = [ maintainers.lucasew ];
};
};
in self

View File

@ -0,0 +1,20 @@
from argparse import ArgumentParser
from pathlib import Path
import backgroundremover.utilities as utilities
from backgroundremover import bg
parser = ArgumentParser()
parser.add_argument('input', type=Path)
parser.add_argument('output', type=Path)
args = parser.parse_args()
input_bytes = args.input.read_bytes()
output_bytes = bg.remove(
input_bytes,
)
args.output.write_bytes(output_bytes)

View File

@ -0,0 +1,42 @@
{ buildPythonPackage
, fetchFromGitHub
, lib
, commandlines
, unittestCheckHook
, pexpect
, naked
, nix-update-script
, setuptools
, wheel
}:
buildPythonPackage rec {
pname = "hsh";
version = "1.1.0";
pyproject = true;
src = fetchFromGitHub {
owner = "chrissimpkins";
repo = "hsh";
rev = "v${version}";
hash = "sha256-bAAytoidFHH2dSXqN9aqBd2H4p/rwTWXIZa1t5Djdz0=";
};
propagatedBuildInputs = [ commandlines ];
nativeBuildInputs = [ setuptools wheel ];
nativeCheckInputs = [ unittestCheckHook pexpect naked ];
preCheck = "cd tests";
pythonImportsCheck = [ "hsh" ];
meta = with lib; {
description = "Cross-platform command line application that generates file hash digests and performs file integrity checks via file hash digest comparisons";
homepage = "https://github.com/chrissimpkins/hsh";
downloadPage = "https://github.com/chrissimpkins/hsh/releases";
license = licenses.mit;
maintainers = [ maintainers.lucasew ];
};
}

View File

@ -0,0 +1,103 @@
{ buildPythonPackage
, fetchFromGitHub
, lib
, requests
, pyyaml
, setuptools
, wheel
, nodejs
, ruby
, pytestCheckHook
}:
buildPythonPackage rec {
pname = "naked";
version = "0.1.32";
pyproject = true;
src = fetchFromGitHub {
owner = "chrissimpkins";
repo = "naked";
rev = "v${version}";
hash = "sha256-KhygnURFggvUTR9wwWtORtfQES8ANd5sIaCONvIhfRM=";
};
postPatch = ''
# fix hardcoded absolute paths
substituteInPlace **/*.* \
--replace /Users/ces/Desktop/code/naked /build/source
'';
nativeBuildInputs = [ wheel setuptools ];
propagatedBuildInputs = [
requests
pyyaml
];
nativeCheckInputs = [ pytestCheckHook nodejs ruby ];
preCheck =''
cd tests
PATH=$PATH:$out/bin
'';
disabledTestPaths = [ "testfiles" ];
disabledTests = [
# test_NETWORK.py
"test_http_get"
"test_http_get_binary_file_absent"
"test_http_get_binary_file_exists"
"test_http_get_bin_type"
"test_http_get_follow_redirects"
"test_http_get_follow_redirects_false_content"
"test_http_get_follow_redirects_false_on_nofollow_arg"
"test_http_get_response_check_200"
"test_http_get_response_check_301"
"test_http_get_response_check_404"
"test_http_get_response_obj_present"
"test_http_get_ssl"
"test_http_get_status_check_true"
"test_http_get_status_ssl"
"test_http_get_status_ssl_redirect"
"test_http_get_text_absent"
"test_http_get_text_exists_request_overwrite"
"test_http_get_type"
"test_http_post"
"test_http_post_binary_file_absent"
"test_http_post_binary_file_present"
"test_http_post_binary_file_present_request_overwrite"
"test_http_post_reponse_status_200"
"test_http_post_response_status_200_ssl"
"test_http_post_ssl"
"test_http_post_status_check_true"
"test_http_post_text_file_absent"
"test_http_post_text_file_present_request_overwrite"
"test_http_post_type"
# test_SHELL.py
"test_muterun_missing_option_exitcode"
# test_SYSTEM.py
"test_sys_list_all_files"
"test_sys_list_all_files_cwd"
"test_sys_list_all_files_emptydir"
"test_sys_list_filter_files"
"test_sys_match_files"
"test_sys_match_files_fullpath"
"test_sys_meta_file_mod"
# test_TYPES.py
"test_xdict_key_random"
"test_xdict_key_random_sample"
];
pythonImportsCheck = [ "Naked" ];
meta = with lib; {
description = "A Python command line application framework";
homepage = "https://github.com/chrissimpkins/naked";
downloadPage = "https://github.com/chrissimpkins/naked/tags";
license = licenses.mit;
maintainers = [ maintainers.lucasew ];
};
}

View File

@ -5374,6 +5374,8 @@ self: super: with self; {
hsaudiotag3k = callPackage ../development/python-modules/hsaudiotag3k { };
hsh = callPackage ../development/python-modules/hsh { };
hsluv = callPackage ../development/python-modules/hsluv { };
hstspreload = callPackage ../development/python-modules/hstspreload { };
@ -8389,6 +8391,8 @@ self: super: with self; {
nagiosplugin = callPackage ../development/python-modules/nagiosplugin { };
naked = callPackage ../development/python-modules/naked { };
namedlist = callPackage ../development/python-modules/namedlist { };
nameparser = callPackage ../development/python-modules/nameparser { };