Tophness2022 commited on
Commit
bc7b1c7
·
1 Parent(s): ceb365c

added alternate metadata saving modes and config options

Browse files
Files changed (2) hide show
  1. gradio_server.py +27 -5
  2. requirements.txt +2 -1
gradio_server.py CHANGED
@@ -292,6 +292,7 @@ if not Path(server_config_filename).is_file():
292
  "text_encoder_filename" : text_encoder_choices[1],
293
  "save_path": os.path.join(os.getcwd(), "gradio_outputs"),
294
  "compile" : "",
 
295
  "default_ui": "t2v",
296
  "boost" : 1,
297
  "vae_config": 0,
@@ -325,6 +326,8 @@ if len(args.vae_config) > 0:
325
  vae_config = int(args.vae_config)
326
 
327
  default_ui = server_config.get("default_ui", "t2v")
 
 
328
  use_image2video = default_ui != "t2v"
329
  if args.t2v:
330
  use_image2video = False
@@ -670,6 +673,7 @@ def apply_changes( state,
670
  compile_choice,
671
  profile_choice,
672
  vae_config_choice,
 
673
  default_ui_choice ="t2v",
674
  boost_choice = 1
675
  ):
@@ -687,6 +691,7 @@ def apply_changes( state,
687
  "compile" : compile_choice,
688
  "profile" : profile_choice,
689
  "vae_config" : vae_config_choice,
 
690
  "default_ui" : default_ui_choice,
691
  "boost" : boost_choice,
692
  }
@@ -910,6 +915,7 @@ def generate_video(
910
  slg_start,
911
  slg_end,
912
  state,
 
913
  progress=gr.Progress() #track_tqdm= True
914
 
915
  ):
@@ -1113,7 +1119,6 @@ def generate_video(
1113
  file_list = []
1114
  state["file_list"] = file_list
1115
  global save_path
1116
- save_path = server_config.get("save_path", os.path.join(os.getcwd(), "gradio_outputs"))
1117
  os.makedirs(save_path, exist_ok=True)
1118
  video_no = 0
1119
  total_video = repeat_generation * len(prompts)
@@ -1272,9 +1277,14 @@ def generate_video(
1272
  'num_inference_steps': num_inference_steps,
1273
  }
1274
 
1275
- # Save the configs as json format
1276
- with open(video_path.replace('.mp4', '.json'), 'w') as f:
1277
- json.dump(configs, f, indent=4)
 
 
 
 
 
1278
 
1279
  print(f"New video saved to Path: "+video_path)
1280
  file_list.append(video_path)
@@ -1702,7 +1712,7 @@ def create_demo():
1702
  )
1703
  save_path_choice = gr.Textbox(
1704
  label="Output Folder for Generated Videos",
1705
- value=server_config.get("save_path", os.path.join(os.getcwd(), "gradio_outputs"))
1706
  )
1707
  def check(mode):
1708
  if not mode in attention_modes_supported:
@@ -1777,6 +1787,16 @@ def create_demo():
1777
  # visible= True ############
1778
  )
1779
 
 
 
 
 
 
 
 
 
 
 
1780
  msg = gr.Markdown()
1781
  apply_btn = gr.Button("Apply Changes")
1782
 
@@ -2044,6 +2064,7 @@ def create_demo():
2044
  slg_start_perc,
2045
  slg_end_perc,
2046
  state,
 
2047
  ],
2048
  outputs= [gen_status] #,state
2049
 
@@ -2065,6 +2086,7 @@ def create_demo():
2065
  compile_choice,
2066
  profile_choice,
2067
  vae_config_choice,
 
2068
  default_ui_choice,
2069
  boost_choice,
2070
  ],
 
292
  "text_encoder_filename" : text_encoder_choices[1],
293
  "save_path": os.path.join(os.getcwd(), "gradio_outputs"),
294
  "compile" : "",
295
+ "metadata_type": "metadata",
296
  "default_ui": "t2v",
297
  "boost" : 1,
298
  "vae_config": 0,
 
326
  vae_config = int(args.vae_config)
327
 
328
  default_ui = server_config.get("default_ui", "t2v")
329
+ metadata = server_config.get("metadata_type", "metadata")
330
+ save_path = server_config.get("save_path", os.path.join(os.getcwd(), "gradio_outputs"))
331
  use_image2video = default_ui != "t2v"
332
  if args.t2v:
333
  use_image2video = False
 
673
  compile_choice,
674
  profile_choice,
675
  vae_config_choice,
676
+ metadata_choice,
677
  default_ui_choice ="t2v",
678
  boost_choice = 1
679
  ):
 
691
  "compile" : compile_choice,
692
  "profile" : profile_choice,
693
  "vae_config" : vae_config_choice,
694
+ "metadata_choice": metadata_choice,
695
  "default_ui" : default_ui_choice,
696
  "boost" : boost_choice,
697
  }
 
915
  slg_start,
916
  slg_end,
917
  state,
918
+ metadata_choice,
919
  progress=gr.Progress() #track_tqdm= True
920
 
921
  ):
 
1119
  file_list = []
1120
  state["file_list"] = file_list
1121
  global save_path
 
1122
  os.makedirs(save_path, exist_ok=True)
1123
  video_no = 0
1124
  total_video = repeat_generation * len(prompts)
 
1277
  'num_inference_steps': num_inference_steps,
1278
  }
1279
 
1280
+ if metadata_choice == "json":
1281
+ with open(video_path.replace('.mp4', '.json'), 'w') as f:
1282
+ json.dump(configs, f, indent=4)
1283
+ elif metadata_choice == "metadata":
1284
+ from mutagen.mp4 import MP4
1285
+ file = MP4(video_path)
1286
+ file.tags['©cmt'] = [json.dumps(configs)]
1287
+ file.save()
1288
 
1289
  print(f"New video saved to Path: "+video_path)
1290
  file_list.append(video_path)
 
1712
  )
1713
  save_path_choice = gr.Textbox(
1714
  label="Output Folder for Generated Videos",
1715
+ value=server_config.get("save_path", save_path)
1716
  )
1717
  def check(mode):
1718
  if not mode in attention_modes_supported:
 
1787
  # visible= True ############
1788
  )
1789
 
1790
+ metadata_choice = gr.Dropdown(
1791
+ choices=[
1792
+ ("Export JSON files", "json"),
1793
+ ("Add metadata to video", "metadata"),
1794
+ ("Neither", "none")
1795
+ ],
1796
+ value=metadata,
1797
+ label="Metadata Handling"
1798
+ )
1799
+
1800
  msg = gr.Markdown()
1801
  apply_btn = gr.Button("Apply Changes")
1802
 
 
2064
  slg_start_perc,
2065
  slg_end_perc,
2066
  state,
2067
+ metadata_choice,
2068
  ],
2069
  outputs= [gen_status] #,state
2070
 
 
2086
  compile_choice,
2087
  profile_choice,
2088
  vae_config_choice,
2089
+ metadata_choice,
2090
  default_ui_choice,
2091
  boost_choice,
2092
  ],
requirements.txt CHANGED
@@ -17,4 +17,5 @@ numpy>=1.23.5,<2
17
  einops
18
  moviepy==1.0.3
19
  mmgp==3.2.8
20
- peft==0.14.0
 
 
17
  einops
18
  moviepy==1.0.3
19
  mmgp==3.2.8
20
+ peft==0.14.0
21
+ mutagen