mirror of
https://github.com/Wan-Video/Wan2.1.git
synced 2025-12-16 12:13:27 +00:00
commit
4a38beca5b
39
wgp.py
39
wgp.py
@ -4826,11 +4826,15 @@ def generate_video(
|
|||||||
if metadata_choice == "json":
|
if metadata_choice == "json":
|
||||||
with open(path.replace(f'.{extension}', '.json'), 'w') as f:
|
with open(path.replace(f'.{extension}', '.json'), 'w') as f:
|
||||||
json.dump(configs, f, indent=4)
|
json.dump(configs, f, indent=4)
|
||||||
elif metadata_choice == "metadata" and not is_image:
|
elif metadata_choice == "metadata":
|
||||||
from mutagen.mp4 import MP4
|
if is_image:
|
||||||
file = MP4(path)
|
with Image.open(path) as img:
|
||||||
file.tags['©cmt'] = [json.dumps(configs)]
|
img.save(path, comment=json.dumps(configs))
|
||||||
file.save()
|
else:
|
||||||
|
from mutagen.mp4 import MP4
|
||||||
|
file = MP4(path)
|
||||||
|
file.tags['©cmt'] = [json.dumps(configs)]
|
||||||
|
file.save()
|
||||||
if is_image:
|
if is_image:
|
||||||
print(f"New image saved to Path: "+ path)
|
print(f"New image saved to Path: "+ path)
|
||||||
else:
|
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()
|
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
|
||||||
@ -6001,8 +6005,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
|
||||||
|
|
||||||
@ -6037,7 +6047,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
|
||||||
@ -6045,9 +6055,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]}'")
|
||||||
|
|
||||||
@ -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)
|
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 = "")
|
||||||
|
|
||||||
@ -7810,7 +7821,7 @@ def generate_configuration_tab(state, blocks, header, model_choice, resolution,
|
|||||||
metadata_choice = gr.Dropdown(
|
metadata_choice = gr.Dropdown(
|
||||||
choices=[
|
choices=[
|
||||||
("Export JSON files", "json"),
|
("Export JSON files", "json"),
|
||||||
("Add metadata to video", "metadata"),
|
("Embed metadata (Exif tag)", "metadata"),
|
||||||
("Neither", "none")
|
("Neither", "none")
|
||||||
],
|
],
|
||||||
value=server_config.get("metadata_type", "metadata"),
|
value=server_config.get("metadata_type", "metadata"),
|
||||||
@ -8612,4 +8623,4 @@ if __name__ == "__main__":
|
|||||||
url = "http://" + server_name
|
url = "http://" + server_name
|
||||||
webbrowser.open(url + ":" + str(server_port), new = 0, autoraise = True)
|
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])
|
demo.launch(server_name=server_name, server_port=server_port, share=args.share, allowed_paths=[save_path])
|
||||||
# Lucky me !!!
|
# Lucky me !!!
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user