mirror of
https://github.com/karl0ss/ai_image_frame_server.git
synced 2025-07-17 10:38:26 +01:00
Compare commits
11 Commits
Author | SHA1 | Date | |
---|---|---|---|
31b373b34a | |||
8665ab431c | |||
1b528a4277 | |||
6210b5de7d | |||
ab32c8032c | |||
43ce8e1b89 | |||
826e91e7e2 | |||
98f7a87005 | |||
bc933c2308 | |||
d5c4d54041 | |||
ba9b4b8bd4 |
@ -1,19 +1,24 @@
|
|||||||
[tool.bumpversion]
|
[tool.bumpversion]
|
||||||
current_version = "0.2.9"
|
current_version = "0.2.14"
|
||||||
parse = "(?P<major>\\d+)\\.(?P<minor>\\d+)\\.(?P<patch>\\d+)"
|
parse = "(?P<major>\\d+)\\.(?P<minor>\\d+)\\.(?P<patch>\\d+)"
|
||||||
serialize = ["{major}.{minor}.{patch}"]
|
serialize = ["{major}.{minor}.{patch}"]
|
||||||
search = "{current_version}"
|
|
||||||
replace = "{new_version}"
|
replace = "{new_version}"
|
||||||
regex = false
|
regex = false
|
||||||
ignore_missing_version = false
|
|
||||||
ignore_missing_files = false
|
|
||||||
tag = true
|
tag = true
|
||||||
sign_tags = false
|
|
||||||
tag_name = "{new_version}"
|
|
||||||
tag_message = "Bump version: {current_version} → {new_version}"
|
|
||||||
allow_dirty = false
|
|
||||||
commit = true
|
commit = true
|
||||||
message = "Bump version: {current_version} → {new_version}"
|
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 = []
|
moveable_tags = []
|
||||||
commit_args = ""
|
commit_args = ""
|
||||||
setup_hooks = []
|
setup_hooks = []
|
||||||
|
@ -3,9 +3,13 @@ FROM python:3.11-slim
|
|||||||
|
|
||||||
# Set the working directory in the container
|
# Set the working directory in the container
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
# Set version label
|
||||||
|
ARG VERSION="0.2.14"
|
||||||
|
LABEL version=$VERSION
|
||||||
|
|
||||||
# Copy project files into the container
|
# Copy project files into the container
|
||||||
COPY . /app
|
COPY . /app
|
||||||
|
|
||||||
|
|
||||||
# Install dependencies
|
# Install dependencies
|
||||||
RUN pip install --no-cache-dir -r requirements.txt
|
RUN pip install --no-cache-dir -r requirements.txt
|
||||||
|
@ -103,7 +103,8 @@ def generate_image(
|
|||||||
# Generate image
|
# Generate image
|
||||||
logging.debug(f"Generating image: {file_name}")
|
logging.debug(f"Generating image: {file_name}")
|
||||||
results = api.queue_and_wait_images(wf, save_node)
|
results = api.queue_and_wait_images(wf, save_node)
|
||||||
|
rename_image()
|
||||||
|
|
||||||
for _, image_data in results.items():
|
for _, image_data in results.items():
|
||||||
output_path = os.path.join(
|
output_path = os.path.join(
|
||||||
user_config["comfyui"]["output_dir"], f"{file_name}.png"
|
user_config["comfyui"]["output_dir"], f"{file_name}.png"
|
||||||
@ -111,7 +112,6 @@ def generate_image(
|
|||||||
with open(output_path, "wb+") as f:
|
with open(output_path, "wb+") as f:
|
||||||
f.write(image_data)
|
f.write(image_data)
|
||||||
generate_thumbnail(output_path)
|
generate_thumbnail(output_path)
|
||||||
rename_image(f"{file_name}.png")
|
|
||||||
|
|
||||||
logging.debug(f"Image generated successfully for UID: {file_name}")
|
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:
|
def create_image(prompt: str | None = None, model: str = "Random") -> None:
|
||||||
"""Generate an image with a chosen workflow (Random, FLUX*, or SDXL*)."""
|
"""Generate an image with a chosen workflow (Random, FLUX*, or SDXL*)."""
|
||||||
from datetime import datetime
|
|
||||||
if prompt is None:
|
if prompt is None:
|
||||||
prompt = create_prompt_on_openwebui(user_config["comfyui"]["prompt"])
|
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)
|
save_prompt(prompt)
|
||||||
selected_workflow, model = select_model(model)
|
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":
|
if selected_workflow == "FLUX":
|
||||||
generate_image(
|
generate_image(
|
||||||
file_name=file_name,
|
file_name="image",
|
||||||
comfy_prompt=prompt,
|
comfy_prompt=prompt,
|
||||||
workflow_path="./workflow_flux.json",
|
workflow_path="./workflow_flux.json",
|
||||||
prompt_node="Positive Prompt T5",
|
prompt_node="Positive Prompt T5",
|
||||||
@ -173,6 +169,6 @@ def create_image(prompt: str | None = None, model: str = "Random") -> None:
|
|||||||
model=model
|
model=model
|
||||||
)
|
)
|
||||||
else: # SDXL
|
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}")
|
logging.info(f"{selected_workflow} generation started with prompt: {prompt}")
|
||||||
|
@ -48,41 +48,33 @@ def load_config() -> configparser.ConfigParser:
|
|||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
def rename_image(new_filename: str) -> str | None:
|
def rename_image() -> str | None:
|
||||||
"""Renames the latest image in the output folder to a timestamped filename."""
|
"""Renames 'image.png' in the output folder to a timestamped filename if it exists."""
|
||||||
output_dir = user_config["comfyui"]["output_dir"]
|
old_path = os.path.join(user_config["comfyui"]["output_dir"], "image.png")
|
||||||
image_png_path = os.path.join(output_dir, "image.png")
|
favourites_file = "./favourites.json"
|
||||||
|
|
||||||
# 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}'")
|
|
||||||
|
|
||||||
# Find the latest generated image (which is the new_filename)
|
if os.path.exists(old_path):
|
||||||
latest_image_path = os.path.join(output_dir, new_filename)
|
new_filename = f"{str(time.time())}.png"
|
||||||
if not os.path.exists(latest_image_path):
|
new_path = os.path.join(user_config["comfyui"]["output_dir"], new_filename)
|
||||||
print(f"Error: Newly generated image '{new_filename}' not found.")
|
|
||||||
|
# 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
|
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):
|
def get_details_from_png(path):
|
||||||
try:
|
try:
|
||||||
@ -132,18 +124,5 @@ def load_topics_from_config():
|
|||||||
sorted_topics = sorted(topics, key=str.lower)
|
sorted_topics = sorted(topics, key=str.lower)
|
||||||
return sorted_topics
|
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()
|
user_config = load_config()
|
||||||
output_folder = user_config["comfyui"]["output_dir"]
|
output_folder = user_config["comfyui"]["output_dir"]
|
@ -4,7 +4,17 @@ import json
|
|||||||
|
|
||||||
bp = Blueprint("gallery_routes", __name__)
|
bp = Blueprint("gallery_routes", __name__)
|
||||||
image_folder = "./output"
|
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"])
|
@bp.route("/images", methods=["GET"])
|
||||||
def gallery():
|
def gallery():
|
||||||
|
Loading…
x
Reference in New Issue
Block a user