diff --git a/cli/api-checkpoint.py b/cli/api-checkpoint.py index ff939f64e..61c799d83 100755 --- a/cli/api-checkpoint.py +++ b/cli/api-checkpoint.py @@ -24,7 +24,7 @@ def auth(): return None -def get(endpoint: str, dct: dict = None): +def get(endpoint: str, dct: dict | None = None): req = requests.get(f'{sd_url}{endpoint}', json = dct, timeout=300, verify=False, auth=auth()) if req.status_code != 200: return { 'error': req.status_code, 'reason': req.reason, 'url': req.url } diff --git a/cli/api-control.py b/cli/api-control.py index 0e73e94be..865e5b54d 100755 --- a/cli/api-control.py +++ b/cli/api-control.py @@ -30,7 +30,7 @@ def auth(): return None -def post(endpoint: str, dct: dict = None): +def post(endpoint: str, dct: dict | None = None): req = requests.post(f'{sd_url}{endpoint}', json = dct, timeout=300, verify=False, auth=auth()) if req.status_code != 200: return { 'error': req.status_code, 'reason': req.reason, 'url': req.url } diff --git a/cli/api-detect.py b/cli/api-detect.py index ca121b220..8d1ab2b7a 100755 --- a/cli/api-detect.py +++ b/cli/api-detect.py @@ -23,7 +23,7 @@ def auth(): return None -def post(endpoint: str, dct: dict = None): +def post(endpoint: str, dct: dict | None = None): req = requests.post(f'{sd_url}{endpoint}', json = dct, timeout=300, verify=False, auth=auth()) if req.status_code != 200: return { 'error': req.status_code, 'reason': req.reason, 'url': req.url } diff --git a/cli/api-enhance.py b/cli/api-enhance.py index 520625edd..0acb7d1ab 100755 --- a/cli/api-enhance.py +++ b/cli/api-enhance.py @@ -24,7 +24,7 @@ def auth(): return None -def post(endpoint: str, dct: dict = None): +def post(endpoint: str, dct: dict | None = None): req = requests.post(f'{sd_url}{endpoint}', json = dct, timeout=300, verify=False, auth=auth()) if req.status_code != 200: return { 'error': req.status_code, 'reason': req.reason, 'url': req.url } diff --git a/cli/api-faceid.py b/cli/api-faceid.py index 18f1d3503..bf9c8a1f0 100755 --- a/cli/api-faceid.py +++ b/cli/api-faceid.py @@ -29,7 +29,7 @@ def auth(): return None -def post(endpoint: str, dct: dict = None): +def post(endpoint: str, dct: dict | None = None): req = requests.post(f'{sd_url}{endpoint}', json = dct, timeout=300, verify=False, auth=auth()) if req.status_code != 200: return { 'error': req.status_code, 'reason': req.reason, 'url': req.url } diff --git a/cli/api-grid.py b/cli/api-grid.py index e41276bb9..769fbab35 100755 --- a/cli/api-grid.py +++ b/cli/api-grid.py @@ -79,7 +79,7 @@ def generate(x: int, y: int): # pylint: disable=redefined-outer-name return images -def merge(images: list[Image.Image], horizontal: bool, labels: list[str] = None): +def merge(images: list[Image.Image], horizontal: bool, labels: list[str] | None = None): rows = 1 if horizontal else len(images) cols = math.ceil(len(images) / rows) w = max([i.size[0] for i in images]) diff --git a/cli/api-img2img.py b/cli/api-img2img.py index 99ab5ac34..49b23b5d7 100755 --- a/cli/api-img2img.py +++ b/cli/api-img2img.py @@ -29,7 +29,7 @@ def auth(): return None -def post(endpoint: str, dct: dict = None): +def post(endpoint: str, dct: dict | None = None): req = requests.post(f'{sd_url}{endpoint}', json = dct, timeout=300, verify=False, auth=auth()) if req.status_code != 200: return { 'error': req.status_code, 'reason': req.reason, 'url': req.url } diff --git a/cli/api-info.py b/cli/api-info.py index 1056ddf2a..8032a628c 100755 --- a/cli/api-info.py +++ b/cli/api-info.py @@ -24,7 +24,7 @@ def auth(): return None -def get(endpoint: str, dct: dict = None): +def get(endpoint: str, dct: dict | None = None): req = requests.get(f'{sd_url}{endpoint}', json=dct, timeout=300, verify=False, auth=auth()) if req.status_code != 200: return { 'error': req.status_code, 'reason': req.reason, 'url': req.url } @@ -32,7 +32,7 @@ def get(endpoint: str, dct: dict = None): return req.json() -def post(endpoint: str, dct: dict = None): +def post(endpoint: str, dct: dict | None = None): req = requests.post(f'{sd_url}{endpoint}', json = dct, timeout=300, verify=False, auth=auth()) if req.status_code != 200: return { 'error': req.status_code, 'reason': req.reason, 'url': req.url } diff --git a/cli/api-json.py b/cli/api-json.py index 61e5ec3ce..d0e657af6 100755 --- a/cli/api-json.py +++ b/cli/api-json.py @@ -28,7 +28,7 @@ def auth(): return None -def post(endpoint: str, payload: dict = None): +def post(endpoint: str, payload: dict | None = None): if 'sdapi' not in endpoint: endpoint = f'sdapi/v1/{endpoint}' if 'http' not in endpoint: diff --git a/cli/api-mask.py b/cli/api-mask.py index 38aae3018..f8ee56a10 100755 --- a/cli/api-mask.py +++ b/cli/api-mask.py @@ -26,7 +26,7 @@ def auth(): return None -def get(endpoint: str, dct: dict = None): +def get(endpoint: str, dct: dict | None = None): req = requests.get(f'{sd_url}{endpoint}', json=dct, timeout=300, verify=False, auth=auth()) if req.status_code != 200: return { 'error': req.status_code, 'reason': req.reason, 'url': req.url } @@ -34,7 +34,7 @@ def get(endpoint: str, dct: dict = None): return req.json() -def post(endpoint: str, dct: dict = None): +def post(endpoint: str, dct: dict | None = None): req = requests.post(f'{sd_url}{endpoint}', json = dct, timeout=300, verify=False, auth=auth()) if req.status_code != 200: return { 'error': req.status_code, 'reason': req.reason, 'url': req.url } diff --git a/cli/api-preprocess.py b/cli/api-preprocess.py index abb6a9d2f..b51bfbed9 100755 --- a/cli/api-preprocess.py +++ b/cli/api-preprocess.py @@ -26,7 +26,7 @@ def auth(): return None -def get(endpoint: str, dct: dict = None): +def get(endpoint: str, dct: dict | None = None): req = requests.get(f'{sd_url}{endpoint}', json=dct, timeout=300, verify=False, auth=auth()) if req.status_code != 200: return { 'error': req.status_code, 'reason': req.reason, 'url': req.url } @@ -34,7 +34,7 @@ def get(endpoint: str, dct: dict = None): return req.json() -def post(endpoint: str, dct: dict = None): +def post(endpoint: str, dct: dict | None = None): req = requests.post(f'{sd_url}{endpoint}', json = dct, timeout=300, verify=False, auth=auth()) if req.status_code != 200: return { 'error': req.status_code, 'reason': req.reason, 'url': req.url } diff --git a/cli/api-txt2img.py b/cli/api-txt2img.py index 19ee6d474..648b72576 100755 --- a/cli/api-txt2img.py +++ b/cli/api-txt2img.py @@ -28,7 +28,7 @@ def auth(): return None -def post(endpoint: str, dct: dict = None): +def post(endpoint: str, dct: dict | None = None): req = requests.post(f'{sd_url}{endpoint}', json = dct, timeout=300, verify=False, auth=auth()) if req.status_code != 200: return { 'error': req.status_code, 'reason': req.reason, 'url': req.url } diff --git a/cli/api-upscale.py b/cli/api-upscale.py index 488f2db45..2498da964 100755 --- a/cli/api-upscale.py +++ b/cli/api-upscale.py @@ -24,7 +24,7 @@ def auth(): return None -def get(endpoint: str, dct: dict = None): +def get(endpoint: str, dct: dict | None = None): req = requests.get(f'{sd_url}{endpoint}', json=dct, timeout=300, verify=False, auth=auth()) if req.status_code != 200: return { 'error': req.status_code, 'reason': req.reason, 'url': req.url } @@ -32,7 +32,7 @@ def get(endpoint: str, dct: dict = None): return req.json() -def post(endpoint: str, dct: dict = None): +def post(endpoint: str, dct: dict | None = None): req = requests.post(f'{sd_url}{endpoint}', json = dct, timeout=300, verify=False, auth=auth()) if req.status_code != 200: return { 'error': req.status_code, 'reason': req.reason, 'url': req.url } diff --git a/cli/api-vqa.py b/cli/api-vqa.py index 87a3ef2b6..b93d8a15f 100755 --- a/cli/api-vqa.py +++ b/cli/api-vqa.py @@ -24,7 +24,7 @@ def auth(): return None -def get(endpoint: str, dct: dict = None): +def get(endpoint: str, dct: dict | None = None): req = requests.get(f'{sd_url}{endpoint}', json=dct, timeout=300, verify=False, auth=auth()) if req.status_code != 200: return { 'error': req.status_code, 'reason': req.reason, 'url': req.url } @@ -32,7 +32,7 @@ def get(endpoint: str, dct: dict = None): return req.json() -def post(endpoint: str, dct: dict = None): +def post(endpoint: str, dct: dict | None = None): req = requests.post(f'{sd_url}{endpoint}', json = dct, timeout=300, verify=False, auth=auth()) if req.status_code != 200: return { 'error': req.status_code, 'reason': req.reason, 'url': req.url } diff --git a/cli/api-xyz.py b/cli/api-xyz.py index e82fa23a8..50a0f3ecf 100755 --- a/cli/api-xyz.py +++ b/cli/api-xyz.py @@ -30,7 +30,7 @@ def auth(): return None -def post(endpoint: str, dct: dict = None): +def post(endpoint: str, dct: dict | None = None): req = requests.post(f'{sd_url}{endpoint}', json = dct, timeout=300, verify=False, auth=auth()) if req.status_code != 200: return { 'error': req.status_code, 'reason': req.reason, 'url': req.url } diff --git a/cli/api-xyzenum.py b/cli/api-xyzenum.py index e5eb12f83..0decd02f3 100755 --- a/cli/api-xyzenum.py +++ b/cli/api-xyzenum.py @@ -24,7 +24,7 @@ def auth(): return None -def get(endpoint: str, dct: dict = None): +def get(endpoint: str, dct: dict | None = None): req = requests.get(f'{sd_url}{endpoint}', json = dct, timeout=300, verify=False, auth=auth()) if req.status_code != 200: return { 'error': req.status_code, 'reason': req.reason, 'url': req.url } diff --git a/cli/civitai-search.py b/cli/civitai-search.py index cdb29c7ab..b8fbc68b3 100755 --- a/cli/civitai-search.py +++ b/cli/civitai-search.py @@ -99,10 +99,10 @@ def search_civitai( types:str = '', # (Checkpoint, TextualInversion, Hypernetwork, AestheticGradient, LORA, Controlnet, Poses) sort:str = '', # (Highest Rated, Most Downloaded, Newest) period:str = '', # (AllTime, Year, Month, Week, Day) - nsfw:bool = None, # optional:bool + nsfw:bool | None = None, # optional:bool limit:int = 0, base:list[str] = [], # list - token:str = None, + token:str | None = None, exact:bool = True, ): import requests @@ -169,7 +169,7 @@ def search_civitai( return exact_models if len(exact_models) > 0 else models -def models_to_dct(all_models:list, model_id:int=None): +def models_to_dct(all_models:list, model_id:int | None=None): dct = [] for model in all_models: if model_id is not None and model.id != model_id: diff --git a/cli/gen-styles.py b/cli/gen-styles.py index ec1f1089f..1171265a5 100755 --- a/cli/gen-styles.py +++ b/cli/gen-styles.py @@ -33,7 +33,7 @@ def pil_to_b64(img: Image, size: int, quality: int): return f'data:image/jpeg;base64,{b64encoded}' -def post(endpoint: str, dct: dict = None): +def post(endpoint: str, dct: dict | None = None): req = requests.post(endpoint, json = dct, timeout=300, verify=False) if req.status_code != 200: return { 'error': req.status_code, 'reason': req.reason, 'url': req.url } diff --git a/cli/image-search.py b/cli/image-search.py index 8b740a82e..5be923e6e 100755 --- a/cli/image-search.py +++ b/cli/image-search.py @@ -19,7 +19,7 @@ class ImageDB: def __init__(self, name:str='db', fmt:str='json', - cache_dir:str=None, + cache_dir:str | None=None, dtype:torch.dtype=torch.float16, device:torch.device=torch.device('cpu'), model:str='openai/clip-vit-large-patch14', # 'facebook/dinov2-small' @@ -123,8 +123,8 @@ class ImageDB: self.df = rec self.index.add(embed) - def search(self, filename: str = None, metadata: str = None, embed: np.ndarray = None, k=10, d=1.0): # search by filename/metadata/prompt-embed/image-embed - def dct(record: pd.DataFrame, mode: str, distance: float = None): + def search(self, filename: str | None = None, metadata: str | None = None, embed: np.ndarray = None, k=10, d=1.0): # search by filename/metadata/prompt-embed/image-embed + def dct(record: pd.DataFrame, mode: str, distance: float | None = None): if distance is not None: return {'type': mode, 'filename': record[1]['filename'], 'metadata': record[1]['metadata'], 'distance': round(distance, 2)} else: diff --git a/cli/process.py b/cli/process.py index 3461e8f04..dcb4278d9 100644 --- a/cli/process.py +++ b/cli/process.py @@ -21,7 +21,7 @@ all_images_by_type = {} class Result(): - def __init__(self, typ: str, fn: str, tag: str = None, requested: list = []): + def __init__(self, typ: str, fn: str, tag: str | None = None, requested: list = []): self.type = typ self.input = fn self.output = '' @@ -144,7 +144,7 @@ def upscale_restore_image(res: Result, upscale: bool = False): return res -def caption_image(res: Result, tag: str = None): +def caption_image(res: Result, tag: str | None = None): caption = '' tags = [] for model in options.process.caption_model: diff --git a/cli/sdapi.py b/cli/sdapi.py index a91910b1b..6c01d7de3 100755 --- a/cli/sdapi.py +++ b/cli/sdapi.py @@ -93,7 +93,7 @@ def resultsync(req: requests.Response): return res -async def get(endpoint: str, json: dict = None): +async def get(endpoint: str, json: dict | None = None): global sess # pylint: disable=global-statement sess = sess if sess is not None else await session() try: @@ -105,7 +105,7 @@ async def get(endpoint: str, json: dict = None): return {} -def getsync(endpoint: str, json: dict = None): +def getsync(endpoint: str, json: dict | None = None): try: req = requests.get(f'{sd_url}{endpoint}', json=json, verify=False, auth=authsync()) # pylint: disable=missing-timeout res = resultsync(req) @@ -115,7 +115,7 @@ def getsync(endpoint: str, json: dict = None): return {} -async def post(endpoint: str, json: dict = None): +async def post(endpoint: str, json: dict | None = None): global sess # pylint: disable=global-statement # sess = sess if sess is not None else await session() if sess and not sess.closed: @@ -130,7 +130,7 @@ async def post(endpoint: str, json: dict = None): return {} -def postsync(endpoint: str, json: dict = None): +def postsync(endpoint: str, json: dict | None = None): req = requests.post(f'{sd_url}{endpoint}', json=json, verify=False, auth=authsync()) # pylint: disable=missing-timeout res = resultsync(req) return res