mirror of https://github.com/vladmandic/automatic
RUF013 compatibility
parent
783f20b5d7
commit
8e10ec3fec
|
|
@ -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 }
|
||||
|
|
|
|||
|
|
@ -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 }
|
||||
|
|
|
|||
|
|
@ -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 }
|
||||
|
|
|
|||
|
|
@ -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 }
|
||||
|
|
|
|||
|
|
@ -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 }
|
||||
|
|
|
|||
|
|
@ -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])
|
||||
|
|
|
|||
|
|
@ -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 }
|
||||
|
|
|
|||
|
|
@ -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 }
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -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 }
|
||||
|
|
|
|||
|
|
@ -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 }
|
||||
|
|
|
|||
|
|
@ -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 }
|
||||
|
|
|
|||
|
|
@ -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 }
|
||||
|
|
|
|||
|
|
@ -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 }
|
||||
|
|
|
|||
|
|
@ -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 }
|
||||
|
|
|
|||
|
|
@ -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 }
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -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 }
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in New Issue