Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions .dev_scripts/diff_images.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,14 @@ def calc_images_mean_L1(image1_path, image2_path):
image2 = read_image_int16(image2_path)
assert image1.shape == image2.shape

mean_L1 = np.abs(image1 - image2).mean()
return mean_L1
return np.abs(image1 - image2).mean()
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function calc_images_mean_L1 refactored with the following changes:



def parse_args():
parser = argparse.ArgumentParser()
parser.add_argument('image1_path')
parser.add_argument('image2_path')
args = parser.parse_args()
return args
return parser.parse_args()
Comment on lines -25 to +24
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function parse_args refactored with the following changes:



if __name__ == '__main__':
Expand Down
20 changes: 8 additions & 12 deletions backend/invoke_ai_web_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ def setup_flask(self):
mimetypes.add_type('application/javascript', '.js')
mimetypes.add_type('text/css', '.css')
# Socket IO
logger = True if args.web_verbose else False
engineio_logger = True if args.web_verbose else False
logger = bool(args.web_verbose)
engineio_logger = bool(args.web_verbose)
Comment on lines -48 to +49
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function InvokeAIWebServer.setup_flask refactored with the following changes:

max_http_buffer_size = 10000000

socketio_args = {
Expand Down Expand Up @@ -162,7 +162,7 @@ def setup_app(self):
def load_socketio_listeners(self, socketio):
@socketio.on('requestSystemConfig')
def handle_request_capabilities():
print(f'>> System config requested')
print('>> System config requested')
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function InvokeAIWebServer.load_socketio_listeners refactored with the following changes:

config = self.get_system_config()
socketio.emit('systemConfig', config)

Expand Down Expand Up @@ -372,7 +372,7 @@ def handle_run_postprocessing(

@socketio.on('cancel')
def handle_cancel():
print(f'>> Cancel processing requested')
print('>> Cancel processing requested')
self.canceled.set()

# TODO: I think this needs a safety mechanism.
Expand Down Expand Up @@ -693,7 +693,6 @@ def image_done(image, seed, first_seed):
raise
except CanceledException:
self.socketio.emit('processingCanceled')
pass
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function InvokeAIWebServer.generate_images refactored with the following changes:

except Exception as e:
print(e)
self.socketio.emit('error', {'message': (str(e))})
Expand Down Expand Up @@ -753,9 +752,7 @@ def parameters_to_generated_image_metadata(self, parameters):
}
)

rfc_dict['postprocessing'] = (
postprocessing if len(postprocessing) > 0 else None
)
rfc_dict['postprocessing'] = postprocessing or None
Comment on lines -756 to +755
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function InvokeAIWebServer.parameters_to_generated_image_metadata refactored with the following changes:


# semantic drift
rfc_dict['sampler'] = parameters['sampler_name']
Expand Down Expand Up @@ -877,16 +874,15 @@ def save_result_image(

seed = 'unknown_seed'

if 'image' in metadata:
if 'seed' in metadata['image']:
seed = metadata['image']['seed']
if 'image' in metadata and 'seed' in metadata['image']:
seed = metadata['image']['seed']

filename = f'{prefix}.{seed}'

if step_index:
filename += f'.{step_index}'
if postprocessing:
filename += f'.postprocessed'
filename += '.postprocessed'
Comment on lines -880 to +885
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function InvokeAIWebServer.save_result_image refactored with the following changes:


filename += '.png'

Expand Down
6 changes: 3 additions & 3 deletions backend/modules/parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def parameters_to_command(params):
Converts dict of parameters into a `invoke.py` REPL command.
"""

switches = list()
switches = []
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function parameters_to_command refactored with the following changes:


if "prompt" in params:
switches.append(f'"{params["prompt"]}"')
Expand All @@ -35,7 +35,7 @@ def parameters_to_command(params):
if "sampler_name" in params:
switches.append(f'-A {params["sampler_name"]}')
if "seamless" in params and params["seamless"] == True:
switches.append(f"--seamless")
switches.append("--seamless")
if "init_img" in params and len(params["init_img"]) > 0:
switches.append(f'-I {params["init_img"]}')
if "init_mask" in params and len(params["init_mask"]) > 0:
Expand All @@ -45,7 +45,7 @@ def parameters_to_command(params):
if "strength" in params and "init_img" in params:
switches.append(f'-f {params["strength"]}')
if "fit" in params and params["fit"] == True:
switches.append(f"--fit")
switches.append("--fit")
if "gfpgan_strength" in params and params["gfpgan_strength"]:
switches.append(f'-G {params["gfpgan_strength"]}')
if "upscale" in params and params["upscale"]:
Expand Down
4 changes: 2 additions & 2 deletions backend/modules/parse_seed_weights.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ def parse_seed_weights(seed_weights):
return False

# Seed must be 0 or above
if not seed >= 0:
if seed < 0:
return False

# Weight must be between 0 and 1
if not (weight >= 0 and weight <= 1):
if weight < 0 or weight > 1:
Comment on lines -36 to +40
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function parse_seed_weights refactored with the following changes:

  • Simplify logical expression using De Morgan identities [×2] (de-morgan)

return False

# This pair is valid
Expand Down
33 changes: 13 additions & 20 deletions backend/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,7 @@
precision = opt.precision
free_gpu_mem = opt.free_gpu_mem
embedding_path = opt.embedding_path
additional_allowed_origins = (
opt.cors if opt.cors else []
) # additional CORS allowed origins
additional_allowed_origins = opt.cors or []
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 55-57 refactored with the following changes:

This removes the following comments ( why? ):

# additional CORS allowed origins

model = "stable-diffusion-1.4"

"""
Expand Down Expand Up @@ -90,8 +88,8 @@ def serve(path):
return send_from_directory(app.static_folder, "index.html")


logger = True if verbose else False
engineio_logger = True if verbose else False
logger = bool(verbose)
engineio_logger = bool(verbose)
Comment on lines -93 to +92
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 93-136 refactored with the following changes:

This removes the following comments ( why? ):

# coreformer.process(self, image, strength, device, seed=None, fidelity=0.75)


# default 1,000,000, needs to be higher for socketio to accept larger images
max_http_buffer_size = 10000000
Expand Down Expand Up @@ -131,9 +129,7 @@ class CanceledException(Exception):
gfpgan, codeformer = restoration.load_face_restore_models()
esrgan = restoration.load_esrgan()

# coreformer.process(self, image, strength, device, seed=None, fidelity=0.75)

except (ModuleNotFoundError, ImportError):
except ImportError:
print(traceback.format_exc(), file=sys.stderr)
print(">> You may need to install the ESRGAN and/or GFPGAN modules")

Expand Down Expand Up @@ -185,7 +181,7 @@ class CanceledException(Exception):

@socketio.on("requestSystemConfig")
def handle_request_capabilities():
print(f">> System config requested")
print(">> System config requested")
Comment on lines -188 to +184
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function handle_request_capabilities refactored with the following changes:

config = get_system_config()
socketio.emit("systemConfig", config)

Expand All @@ -195,7 +191,7 @@ def handle_request_images(page=1, offset=0, last_mtime=None):
chunk_size = 50

if last_mtime:
print(f">> Latest images requested")
print(">> Latest images requested")
Comment on lines -198 to +194
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function handle_request_images refactored with the following changes:

else:
print(
f">> Page {page} of images requested (page size {chunk_size} offset {offset})"
Expand Down Expand Up @@ -231,7 +227,7 @@ def handle_request_images(page=1, offset=0, last_mtime=None):
"images": image_array,
"nextPage": page,
"offset": offset,
"onlyNewImages": True if last_mtime else False,
"onlyNewImages": bool(last_mtime),
},
)

Expand Down Expand Up @@ -389,7 +385,7 @@ def handle_run_gfpgan_event(original_image, gfpgan_parameters):

@socketio.on("cancel")
def handle_cancel():
print(f">> Cancel processing requested")
print(">> Cancel processing requested")
Comment on lines -392 to +388
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function handle_cancel refactored with the following changes:

canceled.set()
socketio.emit("processingCanceled")

Expand Down Expand Up @@ -520,7 +516,7 @@ def parameters_to_generated_image_metadata(parameters):
}
)

rfc_dict["postprocessing"] = postprocessing if len(postprocessing) > 0 else None
rfc_dict["postprocessing"] = postprocessing or None
Comment on lines -523 to +519
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function parameters_to_generated_image_metadata refactored with the following changes:


# semantic drift
rfc_dict["sampler"] = parameters["sampler_name"]
Expand Down Expand Up @@ -582,25 +578,22 @@ def save_image(

seed = "unknown_seed"

if "image" in metadata:
if "seed" in metadata["image"]:
seed = metadata["image"]["seed"]
if "image" in metadata and "seed" in metadata["image"]:
seed = metadata["image"]["seed"]

filename = f"{prefix}.{seed}"

if step_index:
filename += f".{step_index}"
if postprocessing:
filename += f".postprocessed"
filename += ".postprocessed"

filename += ".png"

path = pngwriter.save_image_and_prompt_to_png(
return pngwriter.save_image_and_prompt_to_png(
image=image, dream_prompt=command, metadata=metadata, name=filename
)

return path
Comment on lines -585 to -602
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function save_image refactored with the following changes:



def calculate_real_steps(steps, strength, has_init_image):
return math.floor(strength * steps) if has_init_image else steps
Expand Down
Loading