Skip to content

Commit

Permalink
5.1.3 photomaker
Browse files Browse the repository at this point in the history
  • Loading branch information
zenafey committed May 9, 2024
1 parent e7b28eb commit cf51ce6
Show file tree
Hide file tree
Showing 21 changed files with 169 additions and 34 deletions.
8 changes: 8 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/inspectionProfiles/profiles_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions .idea/prodiapy-github.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions prodiapy/__init__.py
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
Expand Down
1 change: 1 addition & 0 deletions prodiapy/_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ def __init__(

general = resources.General(self)

self.photomaker = general.photomaker
self.faceswap = general.faceswap
self.upscale = general.upscale
self.create = general.create
Expand Down
1 change: 1 addition & 0 deletions prodiapy/aio.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ def __init__(

general = resources.AsyncGeneral(self)

self.photomaker = general.photomaker
self.faceswap = general.faceswap
self.upscale = general.upscale
self.create = general.create
Expand Down
6 changes: 1 addition & 5 deletions prodiapy/resources/__init__.py
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
5 changes: 1 addition & 4 deletions prodiapy/resources/engine.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

import aiohttp
import requests
from typing import Literal, Optional, Union
Expand Down Expand Up @@ -46,7 +47,3 @@ def __init__(self, client: Union[SyncAPIClient, AsyncAPIClient]) -> None:
self._client = client
self._get = client.get
self._post = client.post




3 changes: 3 additions & 0 deletions prodiapy/resources/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from prodiapy.resources.facerestore import FaceRestore, AsyncFaceRestore
from prodiapy.resources.faceswap import FaceSwap, AsyncFaceSwap
from prodiapy.resources.upscale import Upscale, AsyncUpscale
from prodiapy.resources.photomaker import PhotoMaker, AsyncPhotoMaker
from prodiapy.resources.response import ProdiaResponse
from prodiapy.resources.utils import form_body
from prodiapy.resources import logger
Expand All @@ -21,6 +22,7 @@ class General(APIResource):

def __init__(self, client: SyncAPIClient) -> None:
super().__init__(client)
self.photomaker = PhotoMaker(client).photomaker
self.facerestore = FaceRestore(client).facerestore
self.faceswap = FaceSwap(client).faceswap
self.upscale = Upscale(client).upscale
Expand Down Expand Up @@ -106,6 +108,7 @@ class AsyncGeneral(APIResource):

def __init__(self, client: AsyncAPIClient) -> None:
super().__init__(client)
self.photomaker = AsyncPhotoMaker(client).photomaker
self.facerestore = AsyncFaceRestore(client).facerestore
self.faceswap = AsyncFaceSwap(client).faceswap
self.upscale = AsyncUpscale(client).upscale
Expand Down
85 changes: 85 additions & 0 deletions prodiapy/resources/photomaker.py
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
)
)

10 changes: 5 additions & 5 deletions prodiapy/resources/response.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ class ProdiaResponse:
job_id: id of the job
image_url: URL of generated image
failed: is job failed or not(boolean)
json: JSON response(raw)
json: JSON response(dictionary)
"""
def __init__(self, output: dict):
self.job_id = output.get('job')
self.image_url = output.get('imageUrl')
self.failed = output.get('failed', False)
self.json = output
self.job_id: str | None = output.get('job')
self.image_url: str | None = output.get('imageUrl')
self.failed: bool = output.get('failed', False)
self.json: dict = output
2 changes: 2 additions & 0 deletions prodiapy/resources/stablediffusion/__init__.py
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,8 +1,7 @@
from __future__ import annotations

from prodiapy.resources.engine import APIResource
from typing import Union, Optional, Literal
from prodiapy.resources.stablediffusiongeneral import StableDiffusionGeneral, AsyncStableDiffusionGeneral
from prodiapy.resources.stablediffusion.template import StableDiffusionGeneral, AsyncStableDiffusionGeneral
from prodiapy.resources.engine import SyncAPIClient, AsyncAPIClient
from prodiapy.resources.utils import form_body

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

from prodiapy.resources.stablediffusiongeneral import StableDiffusionGeneral, AsyncStableDiffusionGeneral
from prodiapy.resources.stablediffusion.template import StableDiffusionGeneral, AsyncStableDiffusionGeneral


class StableDiffusionXL(StableDiffusionGeneral):
Expand Down
22 changes: 6 additions & 16 deletions prodiapy/resources/utils.py
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)


2 changes: 1 addition & 1 deletion pyproject.toml
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"
Expand Down

0 comments on commit cf51ce6

Please sign in to comment.