-
Notifications
You must be signed in to change notification settings - Fork 0
Sourcery refactored main branch #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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() | ||
|
|
||
|
|
||
| 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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
|
|
||
| if __name__ == '__main__': | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| max_http_buffer_size = 10000000 | ||
|
|
||
| socketio_args = { | ||
|
|
@@ -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') | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| config = self.get_system_config() | ||
| socketio.emit('systemConfig', config) | ||
|
|
||
|
|
@@ -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. | ||
|
|
@@ -693,7 +693,6 @@ def image_done(image, seed, first_seed): | |
| raise | ||
| except CanceledException: | ||
| self.socketio.emit('processingCanceled') | ||
| pass | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| except Exception as e: | ||
| print(e) | ||
| self.socketio.emit('error', {'message': (str(e))}) | ||
|
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
| # semantic drift | ||
| rfc_dict['sampler'] = parameters['sampler_name'] | ||
|
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
| filename += '.png' | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,7 +18,7 @@ def parameters_to_command(params): | |
| Converts dict of parameters into a `invoke.py` REPL command. | ||
| """ | ||
|
|
||
| switches = list() | ||
| switches = [] | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
| if "prompt" in params: | ||
| switches.append(f'"{params["prompt"]}"') | ||
|
|
@@ -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: | ||
|
|
@@ -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"]: | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| return False | ||
|
|
||
| # This pair is valid | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 [] | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lines
This removes the following comments ( why? ): |
||
| model = "stable-diffusion-1.4" | ||
|
|
||
| """ | ||
|
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lines
This removes the following comments ( why? ): |
||
|
|
||
| # default 1,000,000, needs to be higher for socketio to accept larger images | ||
| max_http_buffer_size = 10000000 | ||
|
|
@@ -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") | ||
|
|
||
|
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| config = get_system_config() | ||
| socketio.emit("systemConfig", config) | ||
|
|
||
|
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| else: | ||
| print( | ||
| f">> Page {page} of images requested (page size {chunk_size} offset {offset})" | ||
|
|
@@ -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), | ||
| }, | ||
| ) | ||
|
|
||
|
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| canceled.set() | ||
| socketio.emit("processingCanceled") | ||
|
|
||
|
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
| # semantic drift | ||
| rfc_dict["sampler"] = parameters["sampler_name"] | ||
|
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
|
|
||
| def calculate_real_steps(steps, strength, has_init_image): | ||
| return math.floor(strength * steps) if has_init_image else steps | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function
calc_images_mean_L1refactored with the following changes:inline-immediately-returned-variable)