diff --git a/ai_frame_image_server.py b/ai_frame_image_server.py index 732de54..083d11c 100644 --- a/ai_frame_image_server.py +++ b/ai_frame_image_server.py @@ -9,7 +9,7 @@ import os import time import threading from apscheduler.schedulers.background import BackgroundScheduler -from lib import create_image, load_config, create_prompt_on_openwebui, cancel_current_job +from lib import create_image, load_config, create_prompt_on_openwebui, cancel_current_job, get_prompt_from_png user_config = load_config() app = Flask(__name__) @@ -35,13 +35,17 @@ def index() -> str: def gallery() -> str: """ Renders the gallery HTML template. - Args: - None Returns: str: The rendered HTML template. """ - images = [f for f in os.listdir(image_folder) if f.lower().endswith(('png', 'jpg', 'jpeg', 'gif'))] - images = sorted(images, reverse=True) + images = [] + for f in os.listdir(image_folder): + if f.lower().endswith(('png', 'jpg', 'jpeg', 'gif')): + path = os.path.join(image_folder, f) + prompt = get_prompt_from_png(path) # You’d define this function to read metadata + images.append({'filename': f, 'prompt': prompt}) + + return render_template("gallery.html", images=images) diff --git a/lib.py b/lib.py index 76279d5..8364cbe 100644 --- a/lib.py +++ b/lib.py @@ -6,6 +6,7 @@ import litellm import time import os import requests +from PIL import Image from typing import Optional from comfy_api_simplified import ComfyApiWrapper, ComfyWorkflowWrapper from tenacity import ( @@ -270,5 +271,15 @@ def create_image(prompt: str | None = None) -> None: logging.error("No prompt generated.") +def get_prompt_from_png(path): + try: + with Image.open(path) as img: + meta = img.info.get("parameters").split("Negative")[0] # ComfyUI usually stores it here + return meta or "" + except Exception as e: + print(f"Error reading metadata from {path}: {e}") + return "" + user_config = load_config() output_folder = user_config["comfyui"]["output_dir"] + diff --git a/requirements.txt b/requirements.txt index b6e1c71..f6e25ce 100644 Binary files a/requirements.txt and b/requirements.txt differ diff --git a/templates/gallery.html b/templates/gallery.html index e87804c..cc65b42 100644 --- a/templates/gallery.html +++ b/templates/gallery.html @@ -57,13 +57,25 @@ .arrow.right { right: 20px; } + + #lightbox-prompt { + color: #ccc; + font-family: monospace; + white-space: pre-wrap; + background: rgba(0, 0, 0, 0.6); + padding: 10px 20px; + border-radius: 10px; + max-width: 80%; + text-align: left; + margin-top: 20px; + }

Image Archive

@@ -72,36 +84,44 @@ × + +