useknockout 0.1.0__tar.gz → 0.2.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: useknockout
3
- Version: 0.1.0
3
+ Version: 0.2.0
4
4
  Summary: Python SDK for useknockout — state-of-the-art background removal API.
5
5
  Project-URL: Homepage, https://useknockout.com
6
6
  Project-URL: Documentation, https://github.com/useknockout/python
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "useknockout"
7
- version = "0.1.0"
7
+ version = "0.2.0"
8
8
  description = "Python SDK for useknockout — state-of-the-art background removal API."
9
9
  readme = "README.md"
10
10
  license = { text = "MIT" }
@@ -0,0 +1 @@
1
+ __version__ = "0.2.0"
@@ -2,7 +2,7 @@
2
2
 
3
3
  from __future__ import annotations
4
4
 
5
- from typing import Any, Dict, List, Optional
5
+ from typing import Any, Dict, List, Optional, Tuple
6
6
 
7
7
  import httpx
8
8
 
@@ -14,6 +14,7 @@ from useknockout._helpers import (
14
14
  _multipart_batch,
15
15
  _multipart_files,
16
16
  _resolve_token,
17
+ _to_bytes_and_name,
17
18
  )
18
19
  from useknockout._version import __version__
19
20
  from useknockout.errors import KnockoutError, raise_for_status
@@ -376,3 +377,48 @@ class AsyncKnockout:
376
377
  files=_multipart_files(file),
377
378
  data=_form({"format": format}),
378
379
  )
380
+
381
+ async def silhouette(
382
+ self,
383
+ file: FileInput,
384
+ *,
385
+ subject_color: str = "#7C3AED",
386
+ bg_color: str = "#FFFFFF",
387
+ format: str = "png",
388
+ ) -> bytes:
389
+ """POST /silhouette — two-tone silhouette portrait. Async."""
390
+ return await self._request_bytes(
391
+ "POST",
392
+ "/silhouette",
393
+ files=_multipart_files(file),
394
+ data=_form({
395
+ "subject_color": subject_color,
396
+ "bg_color": bg_color,
397
+ "format": format,
398
+ }),
399
+ )
400
+
401
+ async def inpaint(
402
+ self,
403
+ file: FileInput,
404
+ *,
405
+ mask: Optional[FileInput] = None,
406
+ bbox: Optional[Tuple[int, int, int, int]] = None,
407
+ dilation: int = 8,
408
+ format: str = "png",
409
+ ) -> bytes:
410
+ """POST /inpaint — LaMa-based image inpainting. Async."""
411
+ files = _multipart_files(file)
412
+ if mask is not None:
413
+ mdata, mname = _to_bytes_and_name(mask, default_name="mask.png")
414
+ files.append(("mask", (mname, mdata, "application/octet-stream")))
415
+ data = {"dilation": str(int(dilation)), "format": format}
416
+ if bbox is not None:
417
+ x, y, w, h = bbox
418
+ data.update({"x": str(int(x)), "y": str(int(y)), "w": str(int(w)), "h": str(int(h))})
419
+ return await self._request_bytes(
420
+ "POST",
421
+ "/inpaint",
422
+ files=files,
423
+ data=_form(data),
424
+ )
@@ -2,7 +2,7 @@
2
2
 
3
3
  from __future__ import annotations
4
4
 
5
- from typing import Any, Dict, List, Optional
5
+ from typing import Any, Dict, List, Optional, Tuple
6
6
 
7
7
  import httpx
8
8
 
@@ -14,6 +14,7 @@ from useknockout._helpers import (
14
14
  _multipart_batch,
15
15
  _multipart_files,
16
16
  _resolve_token,
17
+ _to_bytes_and_name,
17
18
  )
18
19
  from useknockout._version import __version__
19
20
  from useknockout.errors import KnockoutError, raise_for_status
@@ -425,3 +426,66 @@ class Knockout:
425
426
  files=_multipart_files(file),
426
427
  data=_form({"format": format}),
427
428
  )
429
+
430
+ def silhouette(
431
+ self,
432
+ file: FileInput,
433
+ *,
434
+ subject_color: str = "#7C3AED",
435
+ bg_color: str = "#FFFFFF",
436
+ format: str = "png",
437
+ ) -> bytes:
438
+ """POST /silhouette — two-tone silhouette portrait.
439
+
440
+ Subject filled with one solid color, background filled with another.
441
+ Apple Music / Spotify avatar style. Reuses BiRefNet's mask path; no
442
+ new model load.
443
+
444
+ Added in v0.1.1; requires API ≥ v0.7.1.
445
+ """
446
+ return self._request_bytes(
447
+ "POST",
448
+ "/silhouette",
449
+ files=_multipart_files(file),
450
+ data=_form({
451
+ "subject_color": subject_color,
452
+ "bg_color": bg_color,
453
+ "format": format,
454
+ }),
455
+ )
456
+
457
+ def inpaint(
458
+ self,
459
+ file: FileInput,
460
+ *,
461
+ mask: Optional[FileInput] = None,
462
+ bbox: Optional[Tuple[int, int, int, int]] = None,
463
+ dilation: int = 8,
464
+ format: str = "png",
465
+ ) -> bytes:
466
+ """POST /inpaint — LaMa-based image inpainting.
467
+
468
+ Three auto-detected modes:
469
+ - ``mask`` provided → user-supplied mask
470
+ - ``bbox=(x, y, w, h)`` → rectangular region
471
+ - neither → auto-subject (BiRefNet, inverted)
472
+
473
+ ``dilation`` (0..32, default 8) expands the mask before LaMa runs
474
+ to reduce ghost outlines.
475
+
476
+ Added in v0.2.0; requires API ≥ v0.8.0.
477
+ """
478
+ files = _multipart_files(file)
479
+ if mask is not None:
480
+ mdata, mname = _to_bytes_and_name(mask, default_name="mask.png")
481
+ files.append(("mask", (mname, mdata, "application/octet-stream")))
482
+ data = {"dilation": str(int(dilation)), "format": format}
483
+ if bbox is not None:
484
+ x, y, w, h = bbox
485
+ data.update({"x": str(int(x)), "y": str(int(y)), "w": str(int(w)), "h": str(int(h))})
486
+ return self._request_bytes(
487
+ "POST",
488
+ "/inpaint",
489
+ files=files,
490
+ data=_form(data),
491
+ )
@@ -1 +0,0 @@
1
- __version__ = "0.1.0"
File without changes
File without changes
File without changes