J Z commited on
Update app.py
Browse files
app.py
CHANGED
|
@@ -77,26 +77,63 @@ async def init_float():
|
|
| 77 |
)
|
| 78 |
logger.info("[STARTUP] Emotion model downloaded")
|
| 79 |
|
| 80 |
-
# Check for float.pth
|
| 81 |
float_ckpt = checkpoints_dir / "float.pth"
|
| 82 |
-
if not float_ckpt.exists():
|
| 83 |
-
logger.
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 89 |
assets_dir = Path("/app/assets")
|
| 90 |
assets_dir.mkdir(parents=True, exist_ok=True)
|
| 91 |
ref_image = assets_dir / "ref.png"
|
| 92 |
-
if not ref_image.exists():
|
| 93 |
-
logger.
|
| 94 |
-
|
| 95 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 96 |
|
| 97 |
# Initialize FLOAT
|
| 98 |
lipsync = get_lipsync()
|
| 99 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 100 |
logger.info("[STARTUP] ✓ FLOAT lipsync system ready!")
|
| 101 |
|
| 102 |
except Exception as e:
|
|
|
|
| 77 |
)
|
| 78 |
logger.info("[STARTUP] Emotion model downloaded")
|
| 79 |
|
| 80 |
+
# Check for float.pth - download from repo if not present (xet storage)
|
| 81 |
float_ckpt = checkpoints_dir / "float.pth"
|
| 82 |
+
if not float_ckpt.exists() or float_ckpt.stat().st_size < 1024:
|
| 83 |
+
logger.info("[STARTUP] Downloading float.pth from repo...")
|
| 84 |
+
try:
|
| 85 |
+
downloaded = hf_hub_download(
|
| 86 |
+
repo_id=REPO_ID, repo_type="space",
|
| 87 |
+
filename="app/checkpoints/float.pth",
|
| 88 |
+
local_dir="/tmp/hf_download",
|
| 89 |
+
)
|
| 90 |
+
shutil.copy2(downloaded, float_ckpt)
|
| 91 |
+
logger.info(f"[STARTUP] float.pth downloaded: {float_ckpt.stat().st_size / 1e6:.1f} MB")
|
| 92 |
+
except Exception as e:
|
| 93 |
+
logger.warning(f"[STARTUP] Could not download float.pth: {e}")
|
| 94 |
+
logger.warning("[STARTUP] Upload it to your Space repo under app/checkpoints/float.pth")
|
| 95 |
+
logger.warning("[STARTUP] FLOAT lipsync will be disabled until checkpoint is available")
|
| 96 |
+
return
|
| 97 |
+
|
| 98 |
+
# Check for reference image - download from repo if needed
|
| 99 |
assets_dir = Path("/app/assets")
|
| 100 |
assets_dir.mkdir(parents=True, exist_ok=True)
|
| 101 |
ref_image = assets_dir / "ref.png"
|
| 102 |
+
if not ref_image.exists() or ref_image.stat().st_size < 1024:
|
| 103 |
+
logger.info("[STARTUP] Looking for reference image in repo...")
|
| 104 |
+
try:
|
| 105 |
+
# Try common image extensions
|
| 106 |
+
for ext in ["ref.png", "ref.jpg", "ref.jpeg", "main2.png"]:
|
| 107 |
+
try:
|
| 108 |
+
downloaded = hf_hub_download(
|
| 109 |
+
repo_id=REPO_ID, repo_type="space",
|
| 110 |
+
filename=f"app/assets/{ext}",
|
| 111 |
+
local_dir="/tmp/hf_download",
|
| 112 |
+
)
|
| 113 |
+
dest = assets_dir / ext
|
| 114 |
+
shutil.copy2(downloaded, dest)
|
| 115 |
+
ref_image = dest
|
| 116 |
+
logger.info(f"[STARTUP] Reference image downloaded: {ext}")
|
| 117 |
+
break
|
| 118 |
+
except Exception:
|
| 119 |
+
continue
|
| 120 |
+
else:
|
| 121 |
+
logger.warning("[STARTUP] No reference image found in app/assets/")
|
| 122 |
+
logger.warning("[STARTUP] Upload a face image as app/assets/ref.png")
|
| 123 |
+
return
|
| 124 |
+
except Exception as e:
|
| 125 |
+
logger.warning(f"[STARTUP] Could not download reference image: {e}")
|
| 126 |
+
return
|
| 127 |
|
| 128 |
# Initialize FLOAT
|
| 129 |
lipsync = get_lipsync()
|
| 130 |
+
config = {
|
| 131 |
+
"ref_path": str(ref_image),
|
| 132 |
+
"ckpt_path": str(float_ckpt),
|
| 133 |
+
"wav2vec_model_path": str(w2v_dir),
|
| 134 |
+
"audio2emotion_path": str(emo_dir),
|
| 135 |
+
}
|
| 136 |
+
lipsync.initialize(config)
|
| 137 |
logger.info("[STARTUP] ✓ FLOAT lipsync system ready!")
|
| 138 |
|
| 139 |
except Exception as e:
|