load metadata from images

This commit is contained in:
pixxy 2025-07-18 00:57:19 +01:00
parent d174f71c59
commit 3785636918

21
wgp.py
View File

@ -5452,7 +5452,7 @@ def apply_lset(state, wizard_prompt_activated, lset_name, loras_choices, loras_m
return wizard_prompt_activated, loras_choices, loras_mult_choices, prompt, get_unique_id(), gr.update(), gr.update() return wizard_prompt_activated, loras_choices, loras_mult_choices, prompt, get_unique_id(), gr.update(), gr.update()
else: else:
configs, any_video_file = get_settings_from_file(state, os.path.join(get_lora_dir(current_model_type), lset_name), True, True, True) configs, _ = get_settings_from_file(state, os.path.join(get_lora_dir(current_model_type), lset_name), True, True, True)
if configs == None: if configs == None:
gr.Info("File not supported") gr.Info("File not supported")
return [gr.update()] * 7 return [gr.update()] * 7
@ -5906,8 +5906,14 @@ def get_settings_from_file(state, file_path, allow_json, merge_with_defaults, sw
tags = file.tags['©cmt'][0] tags = file.tags['©cmt'][0]
except: except:
pass pass
if tags != None: elif file_path.endswith(".jpg"):
configs = json.loads(tags) try:
with Image.open(file_path) as img:
tags = img.info["comment"]
except:
pass
if tags is not None:
configs = json.loads(tags)
if configs == None: if configs == None:
return None, False return None, False
@ -5942,7 +5948,7 @@ def load_settings_from_file(state, file_path):
if file_path==None: if file_path==None:
return gr.update(), gr.update(), None return gr.update(), gr.update(), None
configs, any_video_file = get_settings_from_file(state, file_path, True, True, True) configs, any_video_or_image_file = get_settings_from_file(state, file_path, True, True, True)
if configs == None: if configs == None:
gr.Info("File not supported") gr.Info("File not supported")
return gr.update(), gr.update(), None return gr.update(), gr.update(), None
@ -5950,9 +5956,10 @@ def load_settings_from_file(state, file_path):
current_model_type = state["model_type"] current_model_type = state["model_type"]
model_type = configs["model_type"] model_type = configs["model_type"]
prompt = configs.get("prompt", "") prompt = configs.get("prompt", "")
is_image = configs.get("is_image", False)
if any_video_file: if any_video_or_image_file:
gr.Info(f"Settings Loaded from Video generated with prompt '{prompt[:100]}'") gr.Info(f"Settings Loaded from {'Image' if is_image else 'Video'} generated with prompt '{prompt[:100]}'")
else: else:
gr.Info(f"Settings Loaded from Settings file with prompt '{prompt[:100]}'") gr.Info(f"Settings Loaded from Settings file with prompt '{prompt[:100]}'")
@ -7140,7 +7147,7 @@ def generate_video_tab(update_form = False, state_dict = None, ui_defaults = Non
save_settings_btn = gr.Button("Set Settings as Default", visible = not args.lock_config) save_settings_btn = gr.Button("Set Settings as Default", visible = not args.lock_config)
export_settings_from_file_btn = gr.Button("Export Settings to File") export_settings_from_file_btn = gr.Button("Export Settings to File")
with gr.Row(): with gr.Row():
settings_file = gr.File(height=41,label="Load Settings From Video / Json") settings_file = gr.File(height=41,label="Load Settings From Video / Image / JSON")
settings_base64_output = gr.Text(interactive= False, visible=False, value = "") settings_base64_output = gr.Text(interactive= False, visible=False, value = "")
settings_filename = gr.Text(interactive= False, visible=False, value = "") settings_filename = gr.Text(interactive= False, visible=False, value = "")