RUF013 compatibility

pull/4706/head
awsr 2026-03-20 18:42:44 -07:00
parent 783f20b5d7
commit 8e10ec3fec
No known key found for this signature in database
21 changed files with 34 additions and 34 deletions

View File

@ -24,7 +24,7 @@ def auth():
return None 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()) req = requests.get(f'{sd_url}{endpoint}', json = dct, timeout=300, verify=False, auth=auth())
if req.status_code != 200: if req.status_code != 200:
return { 'error': req.status_code, 'reason': req.reason, 'url': req.url } return { 'error': req.status_code, 'reason': req.reason, 'url': req.url }

View File

@ -30,7 +30,7 @@ def auth():
return None 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()) req = requests.post(f'{sd_url}{endpoint}', json = dct, timeout=300, verify=False, auth=auth())
if req.status_code != 200: if req.status_code != 200:
return { 'error': req.status_code, 'reason': req.reason, 'url': req.url } return { 'error': req.status_code, 'reason': req.reason, 'url': req.url }

View File

@ -23,7 +23,7 @@ def auth():
return None 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()) req = requests.post(f'{sd_url}{endpoint}', json = dct, timeout=300, verify=False, auth=auth())
if req.status_code != 200: if req.status_code != 200:
return { 'error': req.status_code, 'reason': req.reason, 'url': req.url } return { 'error': req.status_code, 'reason': req.reason, 'url': req.url }

View File

@ -24,7 +24,7 @@ def auth():
return None 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()) req = requests.post(f'{sd_url}{endpoint}', json = dct, timeout=300, verify=False, auth=auth())
if req.status_code != 200: if req.status_code != 200:
return { 'error': req.status_code, 'reason': req.reason, 'url': req.url } return { 'error': req.status_code, 'reason': req.reason, 'url': req.url }

View File

@ -29,7 +29,7 @@ def auth():
return None 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()) req = requests.post(f'{sd_url}{endpoint}', json = dct, timeout=300, verify=False, auth=auth())
if req.status_code != 200: if req.status_code != 200:
return { 'error': req.status_code, 'reason': req.reason, 'url': req.url } return { 'error': req.status_code, 'reason': req.reason, 'url': req.url }

View File

@ -79,7 +79,7 @@ def generate(x: int, y: int): # pylint: disable=redefined-outer-name
return images 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) rows = 1 if horizontal else len(images)
cols = math.ceil(len(images) / rows) cols = math.ceil(len(images) / rows)
w = max([i.size[0] for i in images]) w = max([i.size[0] for i in images])

View File

@ -29,7 +29,7 @@ def auth():
return None 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()) req = requests.post(f'{sd_url}{endpoint}', json = dct, timeout=300, verify=False, auth=auth())
if req.status_code != 200: if req.status_code != 200:
return { 'error': req.status_code, 'reason': req.reason, 'url': req.url } return { 'error': req.status_code, 'reason': req.reason, 'url': req.url }

View File

@ -24,7 +24,7 @@ def auth():
return None 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()) req = requests.get(f'{sd_url}{endpoint}', json=dct, timeout=300, verify=False, auth=auth())
if req.status_code != 200: if req.status_code != 200:
return { 'error': req.status_code, 'reason': req.reason, 'url': req.url } 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() 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()) req = requests.post(f'{sd_url}{endpoint}', json = dct, timeout=300, verify=False, auth=auth())
if req.status_code != 200: if req.status_code != 200:
return { 'error': req.status_code, 'reason': req.reason, 'url': req.url } return { 'error': req.status_code, 'reason': req.reason, 'url': req.url }

View File

@ -28,7 +28,7 @@ def auth():
return None return None
def post(endpoint: str, payload: dict = None): def post(endpoint: str, payload: dict | None = None):
if 'sdapi' not in endpoint: if 'sdapi' not in endpoint:
endpoint = f'sdapi/v1/{endpoint}' endpoint = f'sdapi/v1/{endpoint}'
if 'http' not in endpoint: if 'http' not in endpoint:

View File

@ -26,7 +26,7 @@ def auth():
return None 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()) req = requests.get(f'{sd_url}{endpoint}', json=dct, timeout=300, verify=False, auth=auth())
if req.status_code != 200: if req.status_code != 200:
return { 'error': req.status_code, 'reason': req.reason, 'url': req.url } 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() 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()) req = requests.post(f'{sd_url}{endpoint}', json = dct, timeout=300, verify=False, auth=auth())
if req.status_code != 200: if req.status_code != 200:
return { 'error': req.status_code, 'reason': req.reason, 'url': req.url } return { 'error': req.status_code, 'reason': req.reason, 'url': req.url }

View File

@ -26,7 +26,7 @@ def auth():
return None 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()) req = requests.get(f'{sd_url}{endpoint}', json=dct, timeout=300, verify=False, auth=auth())
if req.status_code != 200: if req.status_code != 200:
return { 'error': req.status_code, 'reason': req.reason, 'url': req.url } 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() 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()) req = requests.post(f'{sd_url}{endpoint}', json = dct, timeout=300, verify=False, auth=auth())
if req.status_code != 200: if req.status_code != 200:
return { 'error': req.status_code, 'reason': req.reason, 'url': req.url } return { 'error': req.status_code, 'reason': req.reason, 'url': req.url }

View File

@ -28,7 +28,7 @@ def auth():
return None 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()) req = requests.post(f'{sd_url}{endpoint}', json = dct, timeout=300, verify=False, auth=auth())
if req.status_code != 200: if req.status_code != 200:
return { 'error': req.status_code, 'reason': req.reason, 'url': req.url } return { 'error': req.status_code, 'reason': req.reason, 'url': req.url }

View File

@ -24,7 +24,7 @@ def auth():
return None 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()) req = requests.get(f'{sd_url}{endpoint}', json=dct, timeout=300, verify=False, auth=auth())
if req.status_code != 200: if req.status_code != 200:
return { 'error': req.status_code, 'reason': req.reason, 'url': req.url } 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() 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()) req = requests.post(f'{sd_url}{endpoint}', json = dct, timeout=300, verify=False, auth=auth())
if req.status_code != 200: if req.status_code != 200:
return { 'error': req.status_code, 'reason': req.reason, 'url': req.url } return { 'error': req.status_code, 'reason': req.reason, 'url': req.url }

View File

@ -24,7 +24,7 @@ def auth():
return None 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()) req = requests.get(f'{sd_url}{endpoint}', json=dct, timeout=300, verify=False, auth=auth())
if req.status_code != 200: if req.status_code != 200:
return { 'error': req.status_code, 'reason': req.reason, 'url': req.url } 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() 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()) req = requests.post(f'{sd_url}{endpoint}', json = dct, timeout=300, verify=False, auth=auth())
if req.status_code != 200: if req.status_code != 200:
return { 'error': req.status_code, 'reason': req.reason, 'url': req.url } return { 'error': req.status_code, 'reason': req.reason, 'url': req.url }

View File

@ -30,7 +30,7 @@ def auth():
return None 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()) req = requests.post(f'{sd_url}{endpoint}', json = dct, timeout=300, verify=False, auth=auth())
if req.status_code != 200: if req.status_code != 200:
return { 'error': req.status_code, 'reason': req.reason, 'url': req.url } return { 'error': req.status_code, 'reason': req.reason, 'url': req.url }

View File

@ -24,7 +24,7 @@ def auth():
return None 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()) req = requests.get(f'{sd_url}{endpoint}', json = dct, timeout=300, verify=False, auth=auth())
if req.status_code != 200: if req.status_code != 200:
return { 'error': req.status_code, 'reason': req.reason, 'url': req.url } return { 'error': req.status_code, 'reason': req.reason, 'url': req.url }

View File

@ -99,10 +99,10 @@ def search_civitai(
types:str = '', # (Checkpoint, TextualInversion, Hypernetwork, AestheticGradient, LORA, Controlnet, Poses) types:str = '', # (Checkpoint, TextualInversion, Hypernetwork, AestheticGradient, LORA, Controlnet, Poses)
sort:str = '', # (Highest Rated, Most Downloaded, Newest) sort:str = '', # (Highest Rated, Most Downloaded, Newest)
period:str = '', # (AllTime, Year, Month, Week, Day) period:str = '', # (AllTime, Year, Month, Week, Day)
nsfw:bool = None, # optional:bool nsfw:bool | None = None, # optional:bool
limit:int = 0, limit:int = 0,
base:list[str] = [], # list base:list[str] = [], # list
token:str = None, token:str | None = None,
exact:bool = True, exact:bool = True,
): ):
import requests import requests
@ -169,7 +169,7 @@ def search_civitai(
return exact_models if len(exact_models) > 0 else models 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 = [] dct = []
for model in all_models: for model in all_models:
if model_id is not None and model.id != model_id: if model_id is not None and model.id != model_id:

View File

@ -33,7 +33,7 @@ def pil_to_b64(img: Image, size: int, quality: int):
return f'data:image/jpeg;base64,{b64encoded}' 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) req = requests.post(endpoint, json = dct, timeout=300, verify=False)
if req.status_code != 200: if req.status_code != 200:
return { 'error': req.status_code, 'reason': req.reason, 'url': req.url } return { 'error': req.status_code, 'reason': req.reason, 'url': req.url }

View File

@ -19,7 +19,7 @@ class ImageDB:
def __init__(self, def __init__(self,
name:str='db', name:str='db',
fmt:str='json', fmt:str='json',
cache_dir:str=None, cache_dir:str | None=None,
dtype:torch.dtype=torch.float16, dtype:torch.dtype=torch.float16,
device:torch.device=torch.device('cpu'), device:torch.device=torch.device('cpu'),
model:str='openai/clip-vit-large-patch14', # 'facebook/dinov2-small' model:str='openai/clip-vit-large-patch14', # 'facebook/dinov2-small'
@ -123,8 +123,8 @@ class ImageDB:
self.df = rec self.df = rec
self.index.add(embed) 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 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): def dct(record: pd.DataFrame, mode: str, distance: float | None = None):
if distance is not None: if distance is not None:
return {'type': mode, 'filename': record[1]['filename'], 'metadata': record[1]['metadata'], 'distance': round(distance, 2)} return {'type': mode, 'filename': record[1]['filename'], 'metadata': record[1]['metadata'], 'distance': round(distance, 2)}
else: else:

View File

@ -21,7 +21,7 @@ all_images_by_type = {}
class Result(): 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.type = typ
self.input = fn self.input = fn
self.output = '' self.output = ''
@ -144,7 +144,7 @@ def upscale_restore_image(res: Result, upscale: bool = False):
return res return res
def caption_image(res: Result, tag: str = None): def caption_image(res: Result, tag: str | None = None):
caption = '' caption = ''
tags = [] tags = []
for model in options.process.caption_model: for model in options.process.caption_model:

View File

@ -93,7 +93,7 @@ def resultsync(req: requests.Response):
return res 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 global sess # pylint: disable=global-statement
sess = sess if sess is not None else await session() sess = sess if sess is not None else await session()
try: try:
@ -105,7 +105,7 @@ async def get(endpoint: str, json: dict = None):
return {} return {}
def getsync(endpoint: str, json: dict = None): def getsync(endpoint: str, json: dict | None = None):
try: try:
req = requests.get(f'{sd_url}{endpoint}', json=json, verify=False, auth=authsync()) # pylint: disable=missing-timeout req = requests.get(f'{sd_url}{endpoint}', json=json, verify=False, auth=authsync()) # pylint: disable=missing-timeout
res = resultsync(req) res = resultsync(req)
@ -115,7 +115,7 @@ def getsync(endpoint: str, json: dict = None):
return {} return {}
async def post(endpoint: str, json: dict = None): async def post(endpoint: str, json: dict | None = None):
global sess # pylint: disable=global-statement global sess # pylint: disable=global-statement
# sess = sess if sess is not None else await session() # sess = sess if sess is not None else await session()
if sess and not sess.closed: if sess and not sess.closed:
@ -130,7 +130,7 @@ async def post(endpoint: str, json: dict = None):
return {} 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 req = requests.post(f'{sd_url}{endpoint}', json=json, verify=False, auth=authsync()) # pylint: disable=missing-timeout
res = resultsync(req) res = resultsync(req)
return res return res