Spaces:
Running
Running
load models only if duplicated and gou associated spaces
Browse files
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 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
#
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
#
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
#
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
|
|
|
|
|
|
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 |
|