fffiloni commited on
Commit
b9d8cdd
·
verified ·
1 Parent(s): 581674d

load models only if duplicated and gou associated spaces

Browse files
Files changed (1) hide show
  1. app.py +55 -52
app.py CHANGED
@@ -33,58 +33,61 @@ def trim_audio_to_5s_temp(audio_path, sample_rate=16000):
33
  sf.write(temp_path, audio, samplerate=sample_rate)
34
  return temp_path
35
 
36
- num_gpus = torch.cuda.device_count()
37
- print(f"GPU AVAILABLE: {num_gpus}")
38
-
39
- # Download All Required Models using `snapshot_download`
40
-
41
- # Download Wan2.1-I2V-14B-480P model
42
- wan_model_path = snapshot_download(
43
- repo_id="Wan-AI/Wan2.1-I2V-14B-480P",
44
- local_dir="./weights/Wan2.1-I2V-14B-480P",
45
- #local_dir_use_symlinks=False
46
- )
47
-
48
- # Download Chinese wav2vec2 model
49
- wav2vec_path = snapshot_download(
50
- repo_id="TencentGameMate/chinese-wav2vec2-base",
51
- local_dir="./weights/chinese-wav2vec2-base",
52
- #local_dir_use_symlinks=False
53
- )
54
-
55
- # Download MeiGen MultiTalk weights
56
- multitalk_path = snapshot_download(
57
- repo_id="MeiGen-AI/MeiGen-MultiTalk",
58
- local_dir="./weights/MeiGen-MultiTalk",
59
- #local_dir_use_symlinks=False
60
- )
61
-
62
- # Define paths
63
- base_model_dir = "./weights/Wan2.1-I2V-14B-480P"
64
- multitalk_dir = "./weights/MeiGen-MultiTalk"
65
-
66
- # File to rename
67
- original_index = os.path.join(base_model_dir, "diffusion_pytorch_model.safetensors.index.json")
68
- backup_index = os.path.join(base_model_dir, "diffusion_pytorch_model.safetensors.index.json_old")
69
-
70
- # Rename the original index file
71
- if os.path.exists(original_index):
72
- os.rename(original_index, backup_index)
73
- print("Renamed original index file to .json_old")
74
-
75
- # Copy updated index file from MultiTalk
76
- shutil.copy2(
77
- os.path.join(multitalk_dir, "diffusion_pytorch_model.safetensors.index.json"),
78
- base_model_dir
79
- )
80
-
81
- # Copy MultiTalk model weights
82
- shutil.copy2(
83
- os.path.join(multitalk_dir, "multitalk.safetensors"),
84
- base_model_dir
85
- )
86
-
87
- print("Copied MultiTalk files into base model directory.")
 
 
 
88
 
89
  if not is_shared_ui:
90
 
 
33
  sf.write(temp_path, audio, samplerate=sample_rate)
34
  return temp_path
35
 
36
+ if is_gpu_associated:
37
+ num_gpus = torch.cuda.device_count()
38
+ print(f"GPU AVAILABLE: {num_gpus}")
39
+
40
+
41
+ if not is_shared_ui and is_gpu_associated:
42
+ # Download All Required Models using `snapshot_download`
43
+
44
+ # Download Wan2.1-I2V-14B-480P model
45
+ wan_model_path = snapshot_download(
46
+ repo_id="Wan-AI/Wan2.1-I2V-14B-480P",
47
+ local_dir="./weights/Wan2.1-I2V-14B-480P",
48
+ #local_dir_use_symlinks=False
49
+ )
50
+
51
+ # Download Chinese wav2vec2 model
52
+ wav2vec_path = snapshot_download(
53
+ repo_id="TencentGameMate/chinese-wav2vec2-base",
54
+ local_dir="./weights/chinese-wav2vec2-base",
55
+ #local_dir_use_symlinks=False
56
+ )
57
+
58
+ # Download MeiGen MultiTalk weights
59
+ multitalk_path = snapshot_download(
60
+ repo_id="MeiGen-AI/MeiGen-MultiTalk",
61
+ local_dir="./weights/MeiGen-MultiTalk",
62
+ #local_dir_use_symlinks=False
63
+ )
64
+
65
+ # Define paths
66
+ base_model_dir = "./weights/Wan2.1-I2V-14B-480P"
67
+ multitalk_dir = "./weights/MeiGen-MultiTalk"
68
+
69
+ # File to rename
70
+ original_index = os.path.join(base_model_dir, "diffusion_pytorch_model.safetensors.index.json")
71
+ backup_index = os.path.join(base_model_dir, "diffusion_pytorch_model.safetensors.index.json_old")
72
+
73
+ # Rename the original index file
74
+ if os.path.exists(original_index):
75
+ os.rename(original_index, backup_index)
76
+ print("Renamed original index file to .json_old")
77
+
78
+ # Copy updated index file from MultiTalk
79
+ shutil.copy2(
80
+ os.path.join(multitalk_dir, "diffusion_pytorch_model.safetensors.index.json"),
81
+ base_model_dir
82
+ )
83
+
84
+ # Copy MultiTalk model weights
85
+ shutil.copy2(
86
+ os.path.join(multitalk_dir, "multitalk.safetensors"),
87
+ base_model_dir
88
+ )
89
+
90
+ print("Copied MultiTalk files into base model directory.")
91
 
92
  if not is_shared_ui:
93