Spaces:
Sleeping
Sleeping
YoungjaeDev
Claude
commited on
Commit
·
3008fd1
1
Parent(s):
8133f1d
fix: HF Spaces daemon 프로세스 호환 - ProcessPool을 ThreadPool로 변경
Browse filesHF Spaces에서 Gradio가 daemon 프로세스로 실행되어
ProcessPoolExecutor가 자식 프로세스를 생성할 수 없는 문제 해결:
- ProcessPoolExecutor -> ThreadPoolExecutor로 변경
- 워커 함수 내부 import를 파일 상단으로 이동
- 시각화 작업은 I/O bound가 아니지만 ThreadPool로도 충분한 성능
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
app.py
CHANGED
|
@@ -22,7 +22,7 @@ import os
|
|
| 22 |
import subprocess
|
| 23 |
import sys
|
| 24 |
import tempfile
|
| 25 |
-
from concurrent.futures import
|
| 26 |
from pathlib import Path
|
| 27 |
from typing import Iterable, Optional, Tuple
|
| 28 |
|
|
@@ -34,6 +34,7 @@ import torch
|
|
| 34 |
from gradio.themes import Soft
|
| 35 |
from gradio.themes.utils import colors, fonts, sizes
|
| 36 |
from huggingface_hub import hf_hub_download
|
|
|
|
| 37 |
|
| 38 |
# HF Spaces 배포용: 프로젝트 루트 설정 불필요 (self-contained)
|
| 39 |
|
|
@@ -342,7 +343,7 @@ def create_windows_and_predict(
|
|
| 342 |
|
| 343 |
|
| 344 |
# -----------------------------------------------------------------------------
|
| 345 |
-
# 시각화 워커 함수 (
|
| 346 |
# -----------------------------------------------------------------------------
|
| 347 |
# FALL DETECTED 텍스트 표시 지속 시간 (초)
|
| 348 |
FALL_DISPLAY_DURATION = 2.0
|
|
@@ -353,9 +354,6 @@ def _visualize_single_frame(args: tuple) -> Tuple[int, np.ndarray]:
|
|
| 353 |
(frame_idx, frame, keypoints, show_fall_text,
|
| 354 |
viz_keypoints, viz_scale) = args
|
| 355 |
|
| 356 |
-
# HF Spaces 배포용 상대 import (워커 프로세스에서)
|
| 357 |
-
from visualization import visualize_fall_simple
|
| 358 |
-
|
| 359 |
vis_frame = visualize_fall_simple(
|
| 360 |
frame=frame,
|
| 361 |
keypoints=keypoints if keypoints is not None and keypoints.sum() > 0 else None,
|
|
@@ -428,8 +426,8 @@ def visualize_clip_parallel(
|
|
| 428 |
)
|
| 429 |
viz_args.append(args)
|
| 430 |
|
| 431 |
-
# 병렬 시각화
|
| 432 |
-
with
|
| 433 |
results = list(executor.map(_visualize_single_frame, viz_args))
|
| 434 |
|
| 435 |
# 순서대로 정렬
|
|
|
|
| 22 |
import subprocess
|
| 23 |
import sys
|
| 24 |
import tempfile
|
| 25 |
+
from concurrent.futures import ThreadPoolExecutor
|
| 26 |
from pathlib import Path
|
| 27 |
from typing import Iterable, Optional, Tuple
|
| 28 |
|
|
|
|
| 34 |
from gradio.themes import Soft
|
| 35 |
from gradio.themes.utils import colors, fonts, sizes
|
| 36 |
from huggingface_hub import hf_hub_download
|
| 37 |
+
from visualization import visualize_fall_simple
|
| 38 |
|
| 39 |
# HF Spaces 배포용: 프로젝트 루트 설정 불필요 (self-contained)
|
| 40 |
|
|
|
|
| 343 |
|
| 344 |
|
| 345 |
# -----------------------------------------------------------------------------
|
| 346 |
+
# 시각화 워커 함수 (ThreadPoolExecutor용 - HF Spaces daemon 프로세스 호환)
|
| 347 |
# -----------------------------------------------------------------------------
|
| 348 |
# FALL DETECTED 텍스트 표시 지속 시간 (초)
|
| 349 |
FALL_DISPLAY_DURATION = 2.0
|
|
|
|
| 354 |
(frame_idx, frame, keypoints, show_fall_text,
|
| 355 |
viz_keypoints, viz_scale) = args
|
| 356 |
|
|
|
|
|
|
|
|
|
|
| 357 |
vis_frame = visualize_fall_simple(
|
| 358 |
frame=frame,
|
| 359 |
keypoints=keypoints if keypoints is not None and keypoints.sum() > 0 else None,
|
|
|
|
| 426 |
)
|
| 427 |
viz_args.append(args)
|
| 428 |
|
| 429 |
+
# 병렬 시각화 (ThreadPoolExecutor 사용 - HF Spaces daemon 프로세스 호환)
|
| 430 |
+
with ThreadPoolExecutor(max_workers=num_workers) as executor:
|
| 431 |
results = list(executor.map(_visualize_single_frame, viz_args))
|
| 432 |
|
| 433 |
# 순서대로 정렬
|