Spaces:
Running
on
L40S
Running
on
L40S
Update app.py
Browse files
app.py
CHANGED
@@ -152,19 +152,27 @@ def create_temp_input_json(prompt: str, cond_image_path: str, cond_audio_path_sp
|
|
152 |
|
153 |
def infer(prompt, cond_image_path, cond_audio_path_spk1, cond_audio_path_spk2, sample_steps):
|
154 |
|
|
|
|
|
|
|
|
|
155 |
if is_shared_ui:
|
156 |
-
|
157 |
trimmed_audio_path_spk1 = trim_audio_to_5s_temp(cond_audio_path_spk1)
|
158 |
-
|
159 |
-
|
|
|
|
|
160 |
if cond_audio_path_spk2 is not None:
|
161 |
trimmed_audio_path_spk2 = trim_audio_to_5s_temp(cond_audio_path_spk2)
|
162 |
-
|
163 |
-
|
|
|
|
|
164 |
# Prepare input JSON
|
165 |
input_json_path = create_temp_input_json(prompt, cond_image_path, cond_audio_path_spk1, cond_audio_path_spk2)
|
166 |
-
|
167 |
-
|
|
|
168 |
common_args = [
|
169 |
"--ckpt_dir", "weights/Wan2.1-I2V-14B-480P",
|
170 |
"--wav2vec_dir", "weights/chinese-wav2vec2-base",
|
@@ -172,7 +180,7 @@ def infer(prompt, cond_image_path, cond_audio_path_spk1, cond_audio_path_spk2, s
|
|
172 |
"--sample_steps", str(sample_steps),
|
173 |
"--mode", "streaming",
|
174 |
"--use_teacache",
|
175 |
-
"--save_file",
|
176 |
]
|
177 |
|
178 |
if num_gpus > 1:
|
@@ -210,9 +218,16 @@ def infer(prompt, cond_image_path, cond_audio_path_spk1, cond_audio_path_spk2, s
|
|
210 |
if process.returncode != 0:
|
211 |
raise RuntimeError("Inference failed. Check inference.log for details.")
|
212 |
|
213 |
-
return "
|
214 |
|
215 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
216 |
|
217 |
|
218 |
with gr.Blocks(title="MultiTalk Inference") as demo:
|
|
|
152 |
|
153 |
def infer(prompt, cond_image_path, cond_audio_path_spk1, cond_audio_path_spk2, sample_steps):
|
154 |
|
155 |
+
timestamp = datetime.now().strftime("%Y%m%d%H%M%S%f")
|
156 |
+
result_filename = f"meigen_multitalk_result_{sample_steps}_steps_{timestamp}"
|
157 |
+
temp_files_to_cleanup = []
|
158 |
+
|
159 |
if is_shared_ui:
|
|
|
160 |
trimmed_audio_path_spk1 = trim_audio_to_5s_temp(cond_audio_path_spk1)
|
161 |
+
if trimmed_audio_path_spk1 != cond_audio_path_spk1:
|
162 |
+
cond_audio_path_spk1 = trimmed_audio_path_spk1
|
163 |
+
temp_files_to_cleanup.append(trimmed_audio_path_spk1)
|
164 |
+
|
165 |
if cond_audio_path_spk2 is not None:
|
166 |
trimmed_audio_path_spk2 = trim_audio_to_5s_temp(cond_audio_path_spk2)
|
167 |
+
if trimmed_audio_path_spk2 != cond_audio_path_spk2:
|
168 |
+
cond_audio_path_spk2 = trimmed_audio_path_spk2
|
169 |
+
temp_files_to_cleanup.append(trimmed_audio_path_spk2)
|
170 |
+
|
171 |
# Prepare input JSON
|
172 |
input_json_path = create_temp_input_json(prompt, cond_image_path, cond_audio_path_spk1, cond_audio_path_spk2)
|
173 |
+
temp_files_to_cleanup.append(input_json_path)
|
174 |
+
|
175 |
+
# Base args
|
176 |
common_args = [
|
177 |
"--ckpt_dir", "weights/Wan2.1-I2V-14B-480P",
|
178 |
"--wav2vec_dir", "weights/chinese-wav2vec2-base",
|
|
|
180 |
"--sample_steps", str(sample_steps),
|
181 |
"--mode", "streaming",
|
182 |
"--use_teacache",
|
183 |
+
"--save_file", result_filename
|
184 |
]
|
185 |
|
186 |
if num_gpus > 1:
|
|
|
218 |
if process.returncode != 0:
|
219 |
raise RuntimeError("Inference failed. Check inference.log for details.")
|
220 |
|
221 |
+
return f"{result_filename}.mp4"
|
222 |
|
223 |
+
finally:
|
224 |
+
for f in temp_files_to_cleanup:
|
225 |
+
try:
|
226 |
+
if os.path.exists(f):
|
227 |
+
os.remove(f)
|
228 |
+
print(f"[INFO] Removed temporary file: {f}")
|
229 |
+
except Exception as e:
|
230 |
+
print(f"[WARNING] Could not remove {f}: {e}")
|
231 |
|
232 |
|
233 |
with gr.Blocks(title="MultiTalk Inference") as demo:
|