diff --git a/wgp.py b/wgp.py index 3a2f89b..b0ea395 100644 --- a/wgp.py +++ b/wgp.py @@ -4826,11 +4826,15 @@ def generate_video( if metadata_choice == "json": with open(path.replace(f'.{extension}', '.json'), 'w') as f: json.dump(configs, f, indent=4) - elif metadata_choice == "metadata" and not is_image: - from mutagen.mp4 import MP4 - file = MP4(path) - file.tags['©cmt'] = [json.dumps(configs)] - file.save() + elif metadata_choice == "metadata": + if is_image: + with Image.open(path) as img: + img.save(path, comment=json.dumps(configs)) + else: + from mutagen.mp4 import MP4 + file = MP4(path) + file.tags['©cmt'] = [json.dumps(configs)] + file.save() if is_image: print(f"New image saved to Path: "+ path) else: @@ -5536,7 +5540,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() 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: gr.Info("File not supported") return [gr.update()] * 7 @@ -6001,8 +6005,14 @@ def get_settings_from_file(state, file_path, allow_json, merge_with_defaults, sw tags = file.tags['©cmt'][0] except: pass - if tags != None: - configs = json.loads(tags) + elif file_path.endswith(".jpg"): + 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: return None, False @@ -6037,7 +6047,7 @@ def load_settings_from_file(state, file_path): if file_path==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: gr.Info("File not supported") return gr.update(), gr.update(), None @@ -6045,9 +6055,10 @@ def load_settings_from_file(state, file_path): current_model_type = state["model_type"] model_type = configs["model_type"] prompt = configs.get("prompt", "") + is_image = configs.get("is_image", False) - if any_video_file: - gr.Info(f"Settings Loaded from Video generated with prompt '{prompt[:100]}'") + if any_video_or_image_file: + gr.Info(f"Settings Loaded from {'Image' if is_image else 'Video'} generated with prompt '{prompt[:100]}'") else: gr.Info(f"Settings Loaded from Settings file with prompt '{prompt[:100]}'") @@ -7321,7 +7332,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) export_settings_from_file_btn = gr.Button("Export Settings to File") 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_filename = gr.Text(interactive= False, visible=False, value = "") @@ -7810,7 +7821,7 @@ def generate_configuration_tab(state, blocks, header, model_choice, resolution, metadata_choice = gr.Dropdown( choices=[ ("Export JSON files", "json"), - ("Add metadata to video", "metadata"), + ("Embed metadata (Exif tag)", "metadata"), ("Neither", "none") ], value=server_config.get("metadata_type", "metadata"), @@ -8612,4 +8623,4 @@ if __name__ == "__main__": url = "http://" + server_name webbrowser.open(url + ":" + str(server_port), new = 0, autoraise = True) demo.launch(server_name=server_name, server_port=server_port, share=args.share, allowed_paths=[save_path]) -# Lucky me !!! \ No newline at end of file +# Lucky me !!!