Spaces:
Running
Running
fix: revert to eager model loading — L4 GPU loads models fast, deferred loading caused inference errors
Browse files
app.py
CHANGED
|
@@ -120,31 +120,15 @@ from musetalk.utils.preprocessing import get_landmark_and_bbox, read_imgs, coord
|
|
| 120 |
from musetalk.utils.blending import get_image
|
| 121 |
from musetalk.utils.utils import load_all_model
|
| 122 |
|
| 123 |
-
|
| 124 |
-
vae =
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
timesteps = None
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
def ensure_models_loaded():
|
| 132 |
-
global audio_processor, vae, unet, pe, device, timesteps
|
| 133 |
-
|
| 134 |
-
if audio_processor is not None:
|
| 135 |
-
return
|
| 136 |
-
|
| 137 |
-
print("Loading models (first inference)...")
|
| 138 |
-
audio_processor, vae, unet, pe = load_all_model()
|
| 139 |
-
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 140 |
-
timesteps = torch.tensor([0], device=device)
|
| 141 |
-
print("Models loaded.")
|
| 142 |
|
| 143 |
|
| 144 |
@torch.no_grad()
|
| 145 |
def inference(audio_path, video_path, bbox_shift, progress=gr.Progress(track_tqdm=True)):
|
| 146 |
-
ensure_models_loaded()
|
| 147 |
-
|
| 148 |
args_dict = {
|
| 149 |
"result_dir": "./results",
|
| 150 |
"fps": 25,
|
|
|
|
| 120 |
from musetalk.utils.blending import get_image
|
| 121 |
from musetalk.utils.utils import load_all_model
|
| 122 |
|
| 123 |
+
print("Loading models...")
|
| 124 |
+
audio_processor, vae, unet, pe = load_all_model()
|
| 125 |
+
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 126 |
+
timesteps = torch.tensor([0], device=device)
|
| 127 |
+
print(f"Models loaded on {device}.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 128 |
|
| 129 |
|
| 130 |
@torch.no_grad()
|
| 131 |
def inference(audio_path, video_path, bbox_shift, progress=gr.Progress(track_tqdm=True)):
|
|
|
|
|
|
|
| 132 |
args_dict = {
|
| 133 |
"result_dir": "./results",
|
| 134 |
"fps": 25,
|