Skip to content
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

feat: only generate output image when input was changed #55

Merged
merged 1 commit into from
Feb 23, 2024
Merged
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
13 changes: 12 additions & 1 deletion resources/python/live-painting/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,9 @@ def main(pipe, input_image_path, output_image_path, shutdown_event):
strength = 0.99
guidance_scale = None

# When was the input image last modified
last_modified_time = None

# Queue to hold parameters received from stdin
params_queue = queue.Queue()

Expand All @@ -257,10 +260,18 @@ def main(pipe, input_image_path, output_image_path, shutdown_event):
seed = parameters.get("seed", seed)
strength = parameters.get("strength", strength)
guidance_scale = parameters.get("guidance_scale", guidance_scale)
print(f"Updated parameters {parameters}")
except queue.Empty:
pass # No new parameters, proceed with the existing ones

# Get the current modified time of the input image
current_modified_time = os.path.getmtime(input_image_path)

if current_modified_time != last_modified_time:
last_modified_time = current_modified_time
else:
# Skip this iteration since the input image has not changed
continue

# Only generate an image if the prompt is not empty
if prompt is not None and prompt.strip():
torch.manual_seed(seed)
Expand Down