GeezerVison is showing github.com — feat: v0.0.2 - add upscale() + face_restore() methods (sync + async) · useknockout/python@2c3308a
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: pyproject.toml +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -4,7 +4,7 @@ build-backend = "hatchling.build" | 4 | 4 |
| 5 | 5 | [project] | 6 | 6 | name = "useknockout" | 7 | | -version = "0.0.1" | | 7 | +version = "0.0.2" | 8 | 8 | description = "Python SDK for useknockout — state-of-the-art background removal API." | 9 | 9 | readme = "README.md" | 10 | 10 | license = { text = "MIT" } | |
Collapse file Copy file name to clipboard +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 1 | | -__version__ = "0.0.1" | | 1 | +__version__ = "0.0.2" |
Collapse file Copy file name to clipboardExpand all lines: src/useknockout/async_client.py +31Lines changed: 31 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -323,3 +323,34 @@ async def estimate(self, endpoint: str, width: int, height: int) -> Dict[str, An | 323 | 323 | "/estimate", | 324 | 324 | json={"endpoint": endpoint, "width": width, "height": height}, | 325 | 325 | ) | | 326 | + | | 327 | + async def upscale( | | 328 | + self, | | 329 | + file: FileInput, | | 330 | + *, | | 331 | + scale: int = 4, | | 332 | + face_enhance: bool = False, | | 333 | + format: str = "png", | | 334 | + ) -> bytes: | | 335 | + if scale not in (2, 4): | | 336 | + raise ValueError("scale must be 2 or 4") | | 337 | + return await self._request_bytes( | | 338 | + "POST", | | 339 | + "/upscale", | | 340 | + files=_multipart_files(file), | | 341 | + data=_form({"scale": scale, "face_enhance": face_enhance, "format": format}), | | 342 | + ) | | 343 | + | | 344 | + async def face_restore( | | 345 | + self, | | 346 | + file: FileInput, | | 347 | + *, | | 348 | + only_center_face: bool = False, | | 349 | + format: str = "png", | | 350 | + ) -> bytes: | | 351 | + return await self._request_bytes( | | 352 | + "POST", | | 353 | + "/face-restore", | | 354 | + files=_multipart_files(file), | | 355 | + data=_form({"only_center_face": only_center_face, "format": format}), | | 356 | + ) |
Collapse file Copy file name to clipboardExpand all lines: src/useknockout/client.py +42Lines changed: 42 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -352,3 +352,45 @@ def estimate(self, endpoint: str, width: int, height: int) -> Dict[str, Any]: | 352 | 352 | "/estimate", | 353 | 353 | json={"endpoint": endpoint, "width": width, "height": height}, | 354 | 354 | ) | | 355 | + | | 356 | + def upscale( | | 357 | + self, | | 358 | + file: FileInput, | | 359 | + *, | | 360 | + scale: int = 4, | | 361 | + face_enhance: bool = False, | | 362 | + format: str = "png", | | 363 | + ) -> bytes: | | 364 | + """POST /upscale — Real-ESRGAN x2/x4 super-resolution. | | 365 | +
| | 366 | + ``face_enhance=True`` routes through GFPGAN for sharper facial detail | | 367 | + (slower; use for portraits). | | 368 | + """ | | 369 | + if scale not in (2, 4): | | 370 | + raise ValueError("scale must be 2 or 4") | | 371 | + return self._request_bytes( | | 372 | + "POST", | | 373 | + "/upscale", | | 374 | + files=_multipart_files(file), | | 375 | + data=_form({"scale": scale, "face_enhance": face_enhance, "format": format}), | | 376 | + ) | | 377 | + | | 378 | + def face_restore( | | 379 | + self, | | 380 | + file: FileInput, | | 381 | + *, | | 382 | + only_center_face: bool = False, | | 383 | + format: str = "png", | | 384 | + ) -> bytes: | | 385 | + """POST /face-restore — GFPGAN v1.4 portrait restoration. | | 386 | +
| | 387 | + Fixes blurry / damaged / low-res faces; background is 2x upscaled by | | 388 | + Real-ESRGAN. ``only_center_face=True`` restores just the most prominent | | 389 | + face (faster). | | 390 | + """ | | 391 | + return self._request_bytes( | | 392 | + "POST", | | 393 | + "/face-restore", | | 394 | + files=_multipart_files(file), | | 395 | + data=_form({"only_center_face": only_center_face, "format": format}), | | 396 | + ) |
|