Spaces:
Build error
Build error
Fix: auto-detect device for GPU/CPU fallback
Browse filesUse torch.cuda.is_available() to auto-detect device.
Falls back to CPU when GPU is not available.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
app.py
CHANGED
|
@@ -29,10 +29,13 @@ def detect(image, face_score_threshold, landmark_score_threshold):
|
|
| 29 |
"""Detect anime faces and landmarks in the image."""
|
| 30 |
global detector
|
| 31 |
|
| 32 |
-
# Lazy initialization
|
| 33 |
if detector is None:
|
| 34 |
from anime_face_detector import create_detector
|
| 35 |
-
|
|
|
|
|
|
|
|
|
|
| 36 |
|
| 37 |
# Convert RGB to BGR for OpenCV
|
| 38 |
image_bgr = cv2.cvtColor(image, cv2.COLOR_RGB2BGR)
|
|
|
|
| 29 |
"""Detect anime faces and landmarks in the image."""
|
| 30 |
global detector
|
| 31 |
|
| 32 |
+
# Lazy initialization with auto device detection
|
| 33 |
if detector is None:
|
| 34 |
from anime_face_detector import create_detector
|
| 35 |
+
# Auto-detect device: use GPU if available, otherwise CPU
|
| 36 |
+
device = 'cuda:0' if torch.cuda.is_available() else 'cpu'
|
| 37 |
+
print(f'Using device: {device}')
|
| 38 |
+
detector = create_detector('yolov3', device=device)
|
| 39 |
|
| 40 |
# Convert RGB to BGR for OpenCV
|
| 41 |
image_bgr = cv2.cvtColor(image, cv2.COLOR_RGB2BGR)
|