Compare commits

..

11 Commits
0.2.9 ... main

Author SHA1 Message Date
31b373b34a Bump version: 0.2.13 → 0.2.14 2025-07-10 17:12:23 +01:00
8665ab431c rework version 2025-07-10 17:12:14 +01:00
1b528a4277 new version 2025-07-10 17:11:09 +01:00
6210b5de7d updated toml 2025-07-10 17:10:00 +01:00
ab32c8032c add and update version to docker image 2025-07-10 17:08:58 +01:00
43ce8e1b89 Bump version: 0.2.10 → 0.2.11 2025-07-10 16:59:03 +01:00
826e91e7e2 Bump version: 0.2.9 → 0.2.10 2025-07-10 16:58:56 +01:00
98f7a87005 revert to 0.2.9 2025-07-10 16:58:50 +01:00
bc933c2308 Bump version: 0.2.9 → 0.2.10 2025-07-10 16:25:14 +01:00
d5c4d54041 Bump version: 0.2.8 → 0.2.9 2025-07-10 16:25:09 +01:00
ba9b4b8bd4 fix(favorites): preserve favorite status after image rename
Previously, if a user favorited a newly generated image (named 'image.png'), the favorite status would be lost once the image was automatically renamed to its final timestamped filename.

This change modifies the renaming logic to check the `favourites.json` file. If 'image.png' is found, its entry is updated with the new filename, ensuring the favorite status is preserved.
2025-07-10 16:24:57 +01:00
5 changed files with 57 additions and 63 deletions

View File

@ -1,19 +1,24 @@
[tool.bumpversion]
current_version = "0.2.9"
current_version = "0.2.14"
parse = "(?P<major>\\d+)\\.(?P<minor>\\d+)\\.(?P<patch>\\d+)"
serialize = ["{major}.{minor}.{patch}"]
search = "{current_version}"
replace = "{new_version}"
regex = false
ignore_missing_version = false
ignore_missing_files = false
tag = true
sign_tags = false
tag_name = "{new_version}"
tag_message = "Bump version: {current_version} → {new_version}"
allow_dirty = false
commit = true
message = "Bump version: {current_version} → {new_version}"
tag_name = "{new_version}"
tag_message = "Bump version: {current_version} → {new_version}"
[[tool.bumpversion.files]]
filename = ".bumpversion.toml"
search = 'current_version = "{current_version}"'
replace = 'current_version = "{new_version}"'
[[tool.bumpversion.files]]
filename = "Dockerfile"
search = 'ARG VERSION="{current_version}"'
replace = 'ARG VERSION="{new_version}"'
moveable_tags = []
commit_args = ""
setup_hooks = []

View File

@ -3,9 +3,13 @@ FROM python:3.11-slim
# Set the working directory in the container
WORKDIR /app
# Set version label
ARG VERSION="0.2.14"
LABEL version=$VERSION
# Copy project files into the container
COPY . /app
# Install dependencies
RUN pip install --no-cache-dir -r requirements.txt

View File

@ -103,7 +103,8 @@ def generate_image(
# Generate image
logging.debug(f"Generating image: {file_name}")
results = api.queue_and_wait_images(wf, save_node)
rename_image()
for _, image_data in results.items():
output_path = os.path.join(
user_config["comfyui"]["output_dir"], f"{file_name}.png"
@ -111,7 +112,6 @@ def generate_image(
with open(output_path, "wb+") as f:
f.write(image_data)
generate_thumbnail(output_path)
rename_image(f"{file_name}.png")
logging.debug(f"Image generated successfully for UID: {file_name}")
@ -143,7 +143,7 @@ def select_model(model: str) -> tuple[str, str]:
def create_image(prompt: str | None = None, model: str = "Random") -> None:
"""Generate an image with a chosen workflow (Random, FLUX*, or SDXL*)."""
from datetime import datetime
if prompt is None:
prompt = create_prompt_on_openwebui(user_config["comfyui"]["prompt"])
@ -153,14 +153,10 @@ def create_image(prompt: str | None = None, model: str = "Random") -> None:
save_prompt(prompt)
selected_workflow, model = select_model(model)
# Generate a unique filename using a timestamp
timestamp = datetime.now().strftime("%Y%m%d-%H%M%S")
file_name = f"{timestamp}_{random.getrandbits(32)}"
if selected_workflow == "FLUX":
generate_image(
file_name=file_name,
file_name="image",
comfy_prompt=prompt,
workflow_path="./workflow_flux.json",
prompt_node="Positive Prompt T5",
@ -173,6 +169,6 @@ def create_image(prompt: str | None = None, model: str = "Random") -> None:
model=model
)
else: # SDXL
generate_image(file_name, comfy_prompt=prompt, model=model)
generate_image("image", comfy_prompt=prompt, model=model)
logging.info(f"{selected_workflow} generation started with prompt: {prompt}")

View File

@ -48,41 +48,33 @@ def load_config() -> configparser.ConfigParser:
sys.exit(1)
def rename_image(new_filename: str) -> str | None:
"""Renames the latest image in the output folder to a timestamped filename."""
output_dir = user_config["comfyui"]["output_dir"]
image_png_path = os.path.join(output_dir, "image.png")
# Check if image.png exists and is a favourite
if os.path.exists(image_png_path):
favourites = get_favourites()
if "image.png" in favourites:
# It's a favourite, so rename it to preserve it
timestamped_filename = f"{datetime.now().strftime('%Y%m%d-%H%M%S')}.png"
timestamped_path = os.path.join(output_dir, timestamped_filename)
os.rename(image_png_path, timestamped_path)
# Update favourites list
favourites.remove("image.png")
favourites.append(timestamped_filename)
save_favourites(favourites)
print(f"Preserved favourite 'image.png' as '{timestamped_filename}'")
def rename_image() -> str | None:
"""Renames 'image.png' in the output folder to a timestamped filename if it exists."""
old_path = os.path.join(user_config["comfyui"]["output_dir"], "image.png")
favourites_file = "./favourites.json"
# Find the latest generated image (which is the new_filename)
latest_image_path = os.path.join(output_dir, new_filename)
if not os.path.exists(latest_image_path):
print(f"Error: Newly generated image '{new_filename}' not found.")
if os.path.exists(old_path):
new_filename = f"{str(time.time())}.png"
new_path = os.path.join(user_config["comfyui"]["output_dir"], new_filename)
# Check if image.png is a favourite
if os.path.exists(favourites_file):
with open(favourites_file, 'r') as f:
favourites = json.load(f)
if "image.png" in favourites:
favourites.remove("image.png")
favourites.append(new_filename)
with open(favourites_file, 'w') as f:
json.dump(favourites, f)
os.rename(old_path, new_path)
generate_thumbnail(new_path)
print(f"Renamed 'image.png' to '{new_filename}'")
return new_filename
else:
print("No image.png found.")
return None
# Rename the latest image to "image.png"
if os.path.exists(image_png_path):
os.remove(image_png_path) # remove if it wasn't a favourite
os.rename(latest_image_path, image_png_path)
generate_thumbnail(image_png_path)
print(f"Renamed '{new_filename}' to 'image.png'")
return "image.png"
def get_details_from_png(path):
try:
@ -132,18 +124,5 @@ def load_topics_from_config():
sorted_topics = sorted(topics, key=str.lower)
return sorted_topics
favourites_file = "./favourites.json"
def get_favourites():
if not os.path.exists(favourites_file):
return []
with open(favourites_file, 'r') as f:
return json.load(f)
def save_favourites(favourites):
with open(favourites_file, 'w') as f:
json.dump(favourites, f)
user_config = load_config()
output_folder = user_config["comfyui"]["output_dir"]

View File

@ -4,7 +4,17 @@ import json
bp = Blueprint("gallery_routes", __name__)
image_folder = "./output"
from libs.generic import get_favourites, save_favourites
favourites_file = "./favourites.json"
def get_favourites():
if not os.path.exists(favourites_file):
return []
with open(favourites_file, 'r') as f:
return json.load(f)
def save_favourites(favourites):
with open(favourites_file, 'w') as f:
json.dump(favourites, f)
@bp.route("/images", methods=["GET"])
def gallery():