-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
1,187 additions
and
1,271 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,10 @@ | ||
from . import _exceptions | ||
from . import resources | ||
from .resources.logger import logger | ||
from ._client import Prodia, AsyncProdia | ||
|
||
__all__ = [ | ||
"_exceptions", | ||
"resources", | ||
"Prodia", | ||
"AsyncProdia" | ||
] | ||
from . import _exceptions, resources, aio | ||
from .resources.logger import logger | ||
from ._client import Prodia | ||
|
||
__all__ = [ | ||
"_exceptions", | ||
"resources", | ||
"Prodia", | ||
"aio" | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,115 +1,55 @@ | ||
from prodiapy.resources.engine import SyncAPIClient, AsyncAPIClient | ||
from prodiapy import resources | ||
from prodiapy._exceptions import * | ||
from typing_extensions import override | ||
|
||
import os | ||
|
||
|
||
class Prodia(SyncAPIClient): | ||
sd: resources.StableDiffusion | ||
sdxl: resources.StableDiffusionXL | ||
|
||
api_key: str | ||
|
||
def __init__( | ||
self, | ||
api_key: str | None = None, | ||
base_url: str | None = None | ||
) -> None: | ||
"""Construct a new prodia client instance. | ||
This automatically infers the following arguments from their corresponding environment variables if they are not provided: | ||
- `api_key` from `PRODIA_API_KEY` | ||
""" | ||
if api_key is None: | ||
api_key = os.environ.get("PRODIA_API_KEY") | ||
if api_key is None: | ||
raise AuthenticationError( | ||
"The api_key client option must be set either by passing api_key to the client or by setting the \ | ||
PRODIA_API_KEY environment variable" | ||
) | ||
self.api_key = api_key | ||
|
||
if base_url is None: | ||
base_url = f"https://api.prodia.com/v1" | ||
|
||
super().__init__( | ||
base_url=base_url, | ||
headers=self.auth_headers | ||
) | ||
|
||
self.sd = resources.StableDiffusion(self) | ||
self.sdxl = resources.StableDiffusionXL(self) | ||
|
||
general = resources.General(self) | ||
upscale = resources.Upscale(self) | ||
faceswap = resources.FaceSwap(self) | ||
|
||
self.faceswap = faceswap.faceswap | ||
self.upscale = upscale.upscale | ||
self.create = general.create | ||
self.job = general.job | ||
self.constant = general.constant | ||
self.wait = general.wait | ||
|
||
|
||
@property | ||
@override | ||
def auth_headers(self) -> dict[str, str]: | ||
api_key = self.api_key | ||
return {'X-Prodia-Key': api_key, 'Content-Type': 'application/json'} | ||
|
||
|
||
class AsyncProdia(AsyncAPIClient): | ||
sd: resources.AsyncStableDiffusion | ||
sdxl: resources.AsyncStableDiffusionXL | ||
|
||
api_key: str | ||
|
||
def __init__( | ||
self, | ||
api_key: str | None = None, | ||
base_url: str | None = None | ||
) -> None: | ||
"""Construct a new async prodia client instance. | ||
This automatically infers the following arguments from their corresponding environment variables if they are not provided: | ||
- `api_key` from `PRODIA_API_KEY` | ||
""" | ||
if api_key is None: | ||
api_key = os.environ.get("PRODIA_API_KEY") | ||
if api_key is None: | ||
raise AuthenticationError( | ||
"The api_key client option must be set either by passing api_key to the client or by setting the \ | ||
PRODIA_API_KEY environment variable" | ||
) | ||
self.api_key = api_key | ||
|
||
if base_url is None: | ||
base_url = f"https://api.prodia.com/v1" | ||
|
||
super().__init__( | ||
base_url=base_url, | ||
headers=self.auth_headers | ||
) | ||
|
||
self.sd = resources.AsyncStableDiffusion(self) | ||
self.sdxl = resources.AsyncStableDiffusionXL(self) | ||
|
||
general = resources.AsyncGeneral(self) | ||
upscale = resources.AsyncUpscale(self) | ||
faceswap = resources.AsyncFaceSwap(self) | ||
|
||
self.faceswap = faceswap.faceswap | ||
self.upscale = upscale.upscale | ||
self.create = general.create | ||
self.job = general.job | ||
self.constant = general.constant | ||
self.wait = general.wait | ||
|
||
@property | ||
@override | ||
def auth_headers(self) -> dict[str, str]: | ||
api_key = self.api_key | ||
return {'X-Prodia-Key': api_key, 'Content-Type': 'application/json'} | ||
|
||
from prodiapy.resources.engine import SyncAPIClient | ||
from prodiapy import resources | ||
from typing import Optional | ||
from prodiapy._exceptions import * | ||
|
||
import os | ||
|
||
|
||
class Prodia(SyncAPIClient): | ||
api_key: str | ||
sd: resources.StableDiffusion | ||
sdxl: resources.StableDiffusionXL | ||
general: resources.General | ||
|
||
def __init__( | ||
self, | ||
api_key: Optional[str] = os.getenv("PRODIA_API_KEY"), | ||
base_url: str = os.getenv("PRODIA_API_BASE", "https://api.prodia.com/v1") | ||
): | ||
"""Construct a new prodia client instance. | ||
This automatically infers the following arguments from their corresponding environment variables if they are not provided: | ||
- `api_key` from `PRODIA_API_KEY` | ||
""" | ||
if api_key is None: | ||
raise AuthenticationError( | ||
"The api_key client option must be set either by passing api_key to the client or by setting the \ | ||
PRODIA_API_KEY environment variable" | ||
) | ||
self.api_key = api_key | ||
|
||
super().__init__( | ||
base_url=base_url, | ||
headers=self.auth_headers | ||
) | ||
|
||
self.sd = resources.StableDiffusion(self) | ||
self.sdxl = resources.StableDiffusionXL(self) | ||
|
||
general = resources.General(self) | ||
|
||
self.faceswap = general.faceswap | ||
self.upscale = general.upscale | ||
self.create = general.create | ||
self.job = general.job | ||
self.constant = general.constants | ||
self.wait = general.wait | ||
|
||
@property | ||
def auth_headers(self) -> dict: | ||
api_key = self.api_key | ||
return {'X-Prodia-Key': api_key, 'Content-Type': 'application/json'} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,35 @@ | ||
|
||
|
||
__all__ = [ | ||
"AuthenticationError", | ||
"InvalidParameterError", | ||
"UnknownError", | ||
"FailedJobError" | ||
] | ||
|
||
|
||
class ProdiaError(Exception): | ||
pass | ||
|
||
|
||
class AuthenticationError(ProdiaError): | ||
pass | ||
|
||
|
||
class InvalidParameterError(ProdiaError): | ||
pass | ||
|
||
|
||
class UnknownError(ProdiaError): | ||
pass | ||
|
||
|
||
class FailedJobError(ProdiaError): | ||
pass | ||
|
||
|
||
__all__ = [ | ||
"AuthenticationError", | ||
"InvalidParameterError", | ||
"UnknownError", | ||
"FailedJobError", | ||
"exception_vocab" | ||
] | ||
|
||
|
||
class ProdiaError(Exception): | ||
pass | ||
|
||
|
||
class AuthenticationError(ProdiaError): | ||
pass | ||
|
||
|
||
class InvalidParameterError(ProdiaError): | ||
pass | ||
|
||
|
||
class UnknownError(ProdiaError): | ||
pass | ||
|
||
|
||
class FailedJobError(ProdiaError): | ||
pass | ||
|
||
|
||
exception_vocab = { | ||
401 | 401: AuthenticationError, | ||
400: InvalidParameterError | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
|
||
from prodiapy.resources.engine import AsyncAPIClient | ||
from prodiapy import resources | ||
from typing import Optional | ||
from prodiapy._exceptions import * | ||
|
||
import os | ||
|
||
|
||
class Prodia(AsyncAPIClient): | ||
api_key: str | ||
sd: resources.AsyncStableDiffusion | ||
sdxl: resources.AsyncStableDiffusionXL | ||
general: resources.AsyncGeneral | ||
|
||
def __init__( | ||
self, | ||
api_key: Optional[str] = os.getenv("PRODIA_API_KEY"), | ||
base_url: str = os.getenv("PRODIA_API_BASE", "https://api.prodia.com/v1") | ||
) -> None: | ||
"""Construct a new async prodia client instance. | ||
This automatically infers the following arguments from their corresponding environment variables if they are not provided: | ||
- `api_key` from `PRODIA_API_KEY` | ||
""" | ||
if api_key is None: | ||
raise AuthenticationError( | ||
"The api_key client option must be set either by passing api_key to the client or by setting the \ | ||
PRODIA_API_KEY environment variable" | ||
) | ||
self.api_key = api_key | ||
|
||
super().__init__( | ||
base_url=base_url, | ||
headers=self.auth_headers | ||
) | ||
|
||
self.sd = resources.AsyncStableDiffusion(self) | ||
self.sdxl = resources.AsyncStableDiffusionXL(self) | ||
|
||
general = resources.AsyncGeneral(self) | ||
|
||
self.faceswap = general.faceswap | ||
self.upscale = general.upscale | ||
self.create = general.create | ||
self.job = general.job | ||
self.constant = general.constants | ||
self.wait = general.wait | ||
|
||
@property | ||
def auth_headers(self) -> dict: | ||
api_key = self.api_key | ||
return {'X-Prodia-Key': api_key, 'Content-Type': 'application/json'} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
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 .general import General, AsyncGeneral | ||
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 .general import General, AsyncGeneral |
Oops, something went wrong.