Spaces:
Sleeping
Sleeping
YoungjaeDev
Claude
commited on
Commit
·
169758c
1
Parent(s):
7ea83d4
fix: Private HF repo 모델 다운로드 에러 처리 강화
Browse files- HF_TOKEN 환경변수 누락 시 명확한 에러 메시지 추가
- hf_hub_download 실패 시 RuntimeError로 감싸서 디버깅 정보 포함
- 다운로드된 파일 존재 여부 검증 추가
- 파일 크기 검증 추가 (1MB 미만이면 손상 파일로 간주)
Resolves CodeRabbit review feedback
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
app.py
CHANGED
|
@@ -155,6 +155,9 @@ def download_models() -> tuple[str, str]:
|
|
| 155 |
|
| 156 |
Returns:
|
| 157 |
tuple: (pose_model_path, stgcn_checkpoint_path)
|
|
|
|
|
|
|
|
|
|
| 158 |
"""
|
| 159 |
# 로컬 경로 우선 확인 (개발 환경)
|
| 160 |
local_pose = Path("yolo11m-pose.pt")
|
|
@@ -166,17 +169,49 @@ def download_models() -> tuple[str, str]:
|
|
| 166 |
# HuggingFace Hub에서 다운로드 (Private repo는 HF_TOKEN 환경변수 필요)
|
| 167 |
token = os.environ.get("HF_TOKEN")
|
| 168 |
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
|
|
|
|
|
|
| 174 |
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 180 |
|
| 181 |
return pose_model_path, stgcn_checkpoint
|
| 182 |
|
|
@@ -441,7 +476,7 @@ def process_video(
|
|
| 441 |
def create_demo() -> gr.Blocks:
|
| 442 |
"""Gradio 데모 생성"""
|
| 443 |
|
| 444 |
-
with gr.Blocks() as demo:
|
| 445 |
gr.Markdown(
|
| 446 |
"""
|
| 447 |
# Fall Detection Demo
|
|
@@ -549,8 +584,6 @@ if __name__ == "__main__":
|
|
| 549 |
demo.queue(max_size=10).launch(
|
| 550 |
server_name="0.0.0.0",
|
| 551 |
server_port=7860,
|
| 552 |
-
share=
|
| 553 |
show_error=True,
|
| 554 |
-
theme=custom_theme,
|
| 555 |
-
css=css,
|
| 556 |
)
|
|
|
|
| 155 |
|
| 156 |
Returns:
|
| 157 |
tuple: (pose_model_path, stgcn_checkpoint_path)
|
| 158 |
+
|
| 159 |
+
Raises:
|
| 160 |
+
RuntimeError: 모델 다운로드 또는 검증 실패 시
|
| 161 |
"""
|
| 162 |
# 로컬 경로 우선 확인 (개발 환경)
|
| 163 |
local_pose = Path("yolo11m-pose.pt")
|
|
|
|
| 169 |
# HuggingFace Hub에서 다운로드 (Private repo는 HF_TOKEN 환경변수 필요)
|
| 170 |
token = os.environ.get("HF_TOKEN")
|
| 171 |
|
| 172 |
+
# Private 저장소 접근을 위한 토큰 확인
|
| 173 |
+
if token is None:
|
| 174 |
+
raise RuntimeError(
|
| 175 |
+
"HF_TOKEN 환경변수가 설정되지 않았습니다. "
|
| 176 |
+
"Private 모델 저장소 접근을 위해 HF_TOKEN이 필요합니다. "
|
| 177 |
+
"HF Spaces의 경우 Settings > Secrets에서 설정하세요."
|
| 178 |
+
)
|
| 179 |
|
| 180 |
+
try:
|
| 181 |
+
pose_model_path = hf_hub_download(
|
| 182 |
+
repo_id=HF_MODEL_REPO,
|
| 183 |
+
filename="yolo11m-pose.pt",
|
| 184 |
+
token=token
|
| 185 |
+
)
|
| 186 |
+
|
| 187 |
+
stgcn_checkpoint = hf_hub_download(
|
| 188 |
+
repo_id=HF_MODEL_REPO,
|
| 189 |
+
filename="best_acc.pth",
|
| 190 |
+
token=token
|
| 191 |
+
)
|
| 192 |
+
except Exception as e:
|
| 193 |
+
raise RuntimeError(
|
| 194 |
+
f"모델 다운로드 실패: {e}\n"
|
| 195 |
+
f"저장소: {HF_MODEL_REPO}\n"
|
| 196 |
+
f"HF_TOKEN이 올바르게 설정되었는지 확인하세요."
|
| 197 |
+
) from e
|
| 198 |
+
|
| 199 |
+
# 다운로드된 파일 검증
|
| 200 |
+
pose_path = Path(pose_model_path)
|
| 201 |
+
stgcn_path = Path(stgcn_checkpoint)
|
| 202 |
+
|
| 203 |
+
if not pose_path.exists():
|
| 204 |
+
raise RuntimeError(f"Pose 모델 파일이 존재하지 않습니다: {pose_model_path}")
|
| 205 |
+
if not stgcn_path.exists():
|
| 206 |
+
raise RuntimeError(f"ST-GCN 체크포인트 파일이 존재하지 않습니다: {stgcn_checkpoint}")
|
| 207 |
+
|
| 208 |
+
# 파일 크기 검증 (너무 작으면 손상된 파일일 가능성)
|
| 209 |
+
pose_size = pose_path.stat().st_size
|
| 210 |
+
stgcn_size = stgcn_path.stat().st_size
|
| 211 |
+
if pose_size < 1_000_000: # 1MB 미만
|
| 212 |
+
raise RuntimeError(f"Pose 모델 파일이 너무 작습니다: {pose_size} bytes")
|
| 213 |
+
if stgcn_size < 1_000_000: # 1MB 미만
|
| 214 |
+
raise RuntimeError(f"ST-GCN 체크포인트 파일이 너무 작습니다: {stgcn_size} bytes")
|
| 215 |
|
| 216 |
return pose_model_path, stgcn_checkpoint
|
| 217 |
|
|
|
|
| 476 |
def create_demo() -> gr.Blocks:
|
| 477 |
"""Gradio 데모 생성"""
|
| 478 |
|
| 479 |
+
with gr.Blocks(theme=custom_theme, css=css) as demo:
|
| 480 |
gr.Markdown(
|
| 481 |
"""
|
| 482 |
# Fall Detection Demo
|
|
|
|
| 584 |
demo.queue(max_size=10).launch(
|
| 585 |
server_name="0.0.0.0",
|
| 586 |
server_port=7860,
|
| 587 |
+
share=True,
|
| 588 |
show_error=True,
|
|
|
|
|
|
|
| 589 |
)
|