mirror of
https://github.com/karl0ss/ai_image_frame_server.git
synced 2025-04-28 19:23:41 +01:00
fix sorting and sdxl workflow prompt text
This commit is contained in:
parent
81140d720b
commit
9aea4e63fc
@ -41,11 +41,11 @@ def gallery() -> str:
|
|||||||
images = []
|
images = []
|
||||||
for f in os.listdir(image_folder):
|
for f in os.listdir(image_folder):
|
||||||
if f.lower().endswith(('png', 'jpg', 'jpeg', 'gif')):
|
if f.lower().endswith(('png', 'jpg', 'jpeg', 'gif')):
|
||||||
path = os.path.join(image_folder, f)
|
path = os.path.join(image_folder, f) # Full path to the image
|
||||||
prompt = get_prompt_from_png(path) # You’d define this function to read metadata
|
prompt = get_prompt_from_png(path) # Your method to extract the prompt
|
||||||
images.append({'filename': f, 'prompt': prompt})
|
images.append({'filename': f, 'prompt': prompt, 'path': path}) # Add 'path' to the dictionary
|
||||||
|
|
||||||
|
|
||||||
|
images = sorted(images, key=lambda x: os.path.getmtime(x['path']), reverse=True)
|
||||||
return render_template("gallery.html", images=images)
|
return render_template("gallery.html", images=images)
|
||||||
|
|
||||||
|
|
||||||
|
7
lib.py
7
lib.py
@ -274,7 +274,12 @@ def create_image(prompt: str | None = None) -> None:
|
|||||||
def get_prompt_from_png(path):
|
def get_prompt_from_png(path):
|
||||||
try:
|
try:
|
||||||
with Image.open(path) as img:
|
with Image.open(path) as img:
|
||||||
meta = img.info.get("parameters").split("Negative")[0] # ComfyUI usually stores it here
|
try:
|
||||||
|
# Flux workflow
|
||||||
|
meta = img.info.get("parameters").split("Negative")[0]
|
||||||
|
except AttributeError:
|
||||||
|
# SDXL workflow
|
||||||
|
meta = json.loads(img.info["prompt"])['6']['inputs']['text']
|
||||||
return meta or ""
|
return meta or ""
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Error reading metadata from {path}: {e}")
|
print(f"Error reading metadata from {path}: {e}")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user