-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
- Loading branch information
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
|
||
from . import _exceptions, resources, aio | ||
from .resources.logger import logger | ||
from ._client import Prodia | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,3 @@ | ||
from .logger import logger | ||
from .stablediffusion import StableDiffusion, AsyncStableDiffusion | ||
from .stablediffusionxl import StableDiffusionXL, AsyncStableDiffusionXL | ||
from .upscale import Upscale, AsyncUpscale | ||
from .faceswap import FaceSwap, AsyncFaceSwap | ||
from .facerestore import FaceRestore, AsyncFaceRestore | ||
from .stablediffusion import StableDiffusion, StableDiffusionXL, AsyncStableDiffusion, AsyncStableDiffusionXL | ||
from .general import General, AsyncGeneral |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
|
||
from prodiapy.resources.engine import APIResource, SyncAPIClient, AsyncAPIClient | ||
from typing import Union, Literal, Optional | ||
from prodiapy.resources.utils import form_body | ||
|
||
|
||
class PhotoMaker(APIResource): | ||
def __init__(self, client: SyncAPIClient) -> None: | ||
super().__init__(client) | ||
|
||
def photomaker( | ||
self, | ||
image_urls: Optional[list[str]] = None, | ||
image_data: Optional[list[str]] = None, | ||
prompt: Optional[str] = None, | ||
negative_prompt: Optional[str] = None, | ||
style_preset: Optional[str] = None, | ||
strength: Optional[int] = None, | ||
steps: Optional[int] = None, | ||
seed: Optional[int] = None, | ||
dict_parameters: Optional[dict] = None, | ||
**kwargs | ||
) -> dict: | ||
""" | ||
Generate images with character consistency, source: https://docs.prodia.com/reference/photomaker | ||
Returns: | ||
Python dictionary containing job id | ||
""" | ||
return self._post( | ||
"/photomaker", | ||
body=form_body( | ||
dict_parameters=dict_parameters, | ||
imageUrls=image_urls, | ||
imageData=image_data, | ||
prompt=prompt, | ||
negative_prompt=negative_prompt, | ||
style_preset=style_preset, | ||
strength=strength, | ||
steps=steps, | ||
seed=seed, | ||
**kwargs | ||
) | ||
) | ||
|
||
|
||
class AsyncPhotoMaker(APIResource): | ||
def __init__(self, client: AsyncAPIClient) -> None: | ||
super().__init__(client) | ||
|
||
async def photomaker( | ||
self, | ||
image_urls: Optional[list[str]] = None, | ||
image_data: Optional[list[str]] = None, | ||
prompt: Optional[str] = None, | ||
negative_prompt: Optional[str] = None, | ||
style_preset: Optional[str] = None, | ||
strength: Optional[int] = None, | ||
steps: Optional[int] = None, | ||
seed: Optional[int] = None, | ||
dict_parameters: Optional[dict] = None, | ||
**kwargs | ||
) -> dict: | ||
""" | ||
Generate images with character consistency, source: https://docs.prodia.com/reference/photomaker | ||
Returns: | ||
Python dictionary containing job id | ||
""" | ||
return await self._post( | ||
"/upscale", | ||
body=form_body( | ||
dict_parameters=dict_parameters, | ||
imageUrls=image_urls, | ||
imageData=image_data, | ||
prompt=prompt, | ||
negative_prompt=negative_prompt, | ||
style_preset=style_preset, | ||
strength=strength, | ||
steps=steps, | ||
seed=seed, | ||
**kwargs | ||
) | ||
) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
from .sd15 import StableDiffusion, AsyncStableDiffusion | ||
from .sdxl import StableDiffusionXL, AsyncStableDiffusionXL |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,16 @@ | ||
|
||
from typing import Optional | ||
from prodiapy._exceptions import * | ||
|
||
|
||
def form_body(dict_parameters: Optional[dict] = None, **kwargs): | ||
if dict_parameters: | ||
body = dict_parameters | ||
else: | ||
body = {} | ||
for kwarg in kwargs: | ||
if kwargs.get(kwarg) is not None: | ||
body[kwarg] = kwargs.get(kwarg) | ||
|
||
return body | ||
def form_body(dict_parameters: Optional[dict] = None, **kwargs) -> dict: | ||
return dict_parameters or {k: v for k, v in kwargs.items() if v is not None} | ||
|
||
|
||
def raise_exception(status: int, message: str) -> None: | ||
message_body = f"Prodia API returned {status}. Details: {message}" | ||
if status == 200: | ||
pass | ||
elif status in exception_vocab: | ||
raise exception_vocab[status](message_body) | ||
else: | ||
raise UnknownError(message_body) | ||
exception = exception_vocab.get(status, UnknownError) | ||
if status != 200: | ||
raise exception(message_body) | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[tool.poetry] | ||
name = "prodiapy" | ||
version = "5.1.2" | ||
version = "5.1.3" | ||
description = "Package for using Prodia API" | ||
authors = ["zenafey <[email protected]>"] | ||
readme = "README.md" | ||
|