mirror of
https://github.com/vladmandic/automatic
synced 2026-09-20 01:31:13 +02:00
networks info details include preview image metadata
Signed-off-by: Vladimir Mandic <mandic00@live.com>
This commit is contained in:
@@ -22,6 +22,7 @@
|
||||
- change `vlm` beams to 1 by default for faster response
|
||||
- update diffusers
|
||||
- **controlnet** allow processor to keep aspect-ratio for override images based on i2i or t2i resolution
|
||||
- **networks** info details now displays image metadata from preview image
|
||||
- **Fixes**
|
||||
- `qwen` improve lora compatibility
|
||||
- `chrono` transformers handling
|
||||
|
||||
@@ -314,6 +314,12 @@ def parse_novelai_metadata(data: dict):
|
||||
def read_info_from_image(image: Image, watermark: bool = False):
|
||||
if image is None:
|
||||
return '', {}
|
||||
if isinstance(image, str):
|
||||
try:
|
||||
image = Image.open(image)
|
||||
image.load()
|
||||
except Exception:
|
||||
return '', {}
|
||||
items = image.info or {}
|
||||
geninfo = items.pop('parameters', None) or items.pop('UserComment', None) or ''
|
||||
if geninfo is not None and len(geninfo) > 0:
|
||||
|
||||
@@ -702,6 +702,9 @@ def create_ui(container, button_parent, tabname, skip_indexing = False):
|
||||
with gr.Tab('Embedded metadata', elem_classes=['extra-details-tabs']):
|
||||
meta = gr.JSON({}, show_label=False)
|
||||
ui.details_components.append(meta)
|
||||
with gr.Tab('Preview metadata', elem_classes=['extra-details-tabs']):
|
||||
thumb = gr.JSON({}, show_label=False)
|
||||
ui.details_components.append(thumb)
|
||||
with gr.Group(elem_id=f"{tabname}_extra_details_text", elem_classes=["extra-details-text"], visible=False) as ui.details_text:
|
||||
description = gr.Textbox(label='Description', lines=1, placeholder="Style description...")
|
||||
prompt = gr.Textbox(label='Network prompt', lines=2, placeholder="Prompt...")
|
||||
@@ -849,7 +852,8 @@ def create_ui(container, button_parent, tabname, skip_indexing = False):
|
||||
btn_save_style.click(fn=fn_save_style, _js='closeDetailsEN', inputs=[info, description, prompt, negative, extra, wildcards], outputs=[info])
|
||||
btn_delete_style.click(fn=fn_delete_style, _js='closeDetailsEN', inputs=[info], outputs=[info])
|
||||
|
||||
def show_details(text, img, desc, info, meta, description, prompt, negative, parameters, wildcards, params, _dummy1=None, _dummy2=None):
|
||||
def show_details(text, img, desc, info, meta, thumb, description, prompt, negative, parameters, wildcards, params, _dummy1=None, _dummy2=None):
|
||||
from modules import images
|
||||
page, item = get_item(state, params)
|
||||
is_style = (page is not None) and (page.title == 'Style')
|
||||
is_valid = (item is not None) and hasattr(item, 'name') and hasattr(item, 'filename')
|
||||
@@ -877,12 +881,14 @@ def create_ui(container, button_parent, tabname, skip_indexing = False):
|
||||
item.description = description
|
||||
if wildcards is not None and len(wildcards) > 0:
|
||||
item.wildcards = wildcards
|
||||
|
||||
meta = page.metadata.get(item.name, {}) or {}
|
||||
if type(meta) is str:
|
||||
try:
|
||||
meta = json.loads(meta)
|
||||
except Exception:
|
||||
meta = {}
|
||||
|
||||
if ui.last_item.preview.startswith('data:'):
|
||||
b64str = ui.last_item.preview.split(',',1)[1]
|
||||
img = Image.open(io.BytesIO(base64.b64decode(b64str)))
|
||||
@@ -890,6 +896,9 @@ def create_ui(container, button_parent, tabname, skip_indexing = False):
|
||||
img = item.local_preview
|
||||
else:
|
||||
img = page.find_preview_file(item.filename)
|
||||
|
||||
_geninfo, thumb = images.read_info_from_image(img)
|
||||
|
||||
lora = ''
|
||||
model = ''
|
||||
style = ''
|
||||
@@ -965,6 +974,7 @@ def create_ui(container, button_parent, tabname, skip_indexing = False):
|
||||
desc, # gr.textbox
|
||||
info, # gr.json
|
||||
meta, # gr.json
|
||||
thumb, # gr.json
|
||||
description, # gr.textbox
|
||||
gr.update(value=prompt, visible=is_style), # gr.textbox
|
||||
gr.update(value=negative, visible=is_style), # gr.textbox
|
||||
@@ -1022,7 +1032,7 @@ def create_ui(container, button_parent, tabname, skip_indexing = False):
|
||||
params = infotext.parse(text)
|
||||
prompt = params.get('Original prompt', None) or params.get('Prompt', '')
|
||||
negative = params.get('Original negative', None) or params.get('Negative prompt', '')
|
||||
res = show_details(text=None, img=None, desc=None, info=None, meta=None, parameters=None, description=None, prompt=prompt, negative=negative, wildcards=None, params=params)
|
||||
res = show_details(text=None, img=None, desc=None, info=None, meta=None, thumb=None, parameters=None, description=None, prompt=prompt, negative=negative, wildcards=None, params=params)
|
||||
return res
|
||||
|
||||
def ui_quicksave_click(name):
|
||||
|
||||
Reference in New Issue
Block a user