Update app.py
Browse files
app.py
CHANGED
|
@@ -33,6 +33,21 @@ logging.basicConfig(
|
|
| 33 |
)
|
| 34 |
logger = logging.getLogger(__name__)
|
| 35 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
# Import application modules
|
| 37 |
try:
|
| 38 |
from main import process_video
|
|
@@ -81,6 +96,7 @@ def validate_video_file(video_path: str) -> Tuple[bool, str]:
|
|
| 81 |
return False, f"Error validating video: {str(e)}"
|
| 82 |
|
| 83 |
|
|
|
|
| 84 |
def estimate_vehicle_speed(
|
| 85 |
video_file: str,
|
| 86 |
model_choice: str,
|
|
@@ -91,6 +107,10 @@ def estimate_vehicle_speed(
|
|
| 91 |
"""
|
| 92 |
Process video and estimate vehicle speeds.
|
| 93 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 94 |
Args:
|
| 95 |
video_file: Path to uploaded video
|
| 96 |
model_choice: YOLO model selection
|
|
|
|
| 33 |
)
|
| 34 |
logger = logging.getLogger(__name__)
|
| 35 |
|
| 36 |
+
# Try to import spaces for ZeroGPU support (with automatic CPU fallback)
|
| 37 |
+
try:
|
| 38 |
+
import spaces
|
| 39 |
+
ZEROGPU_AVAILABLE = True
|
| 40 |
+
logger.info("✅ ZeroGPU support enabled - GPU acceleration available")
|
| 41 |
+
except ImportError:
|
| 42 |
+
ZEROGPU_AVAILABLE = False
|
| 43 |
+
logger.info("ℹ️ ZeroGPU not available - will use CPU (slower but functional)")
|
| 44 |
+
# Create a dummy decorator for compatibility
|
| 45 |
+
class spaces:
|
| 46 |
+
@staticmethod
|
| 47 |
+
def GPU(func):
|
| 48 |
+
"""Dummy decorator when ZeroGPU is not available"""
|
| 49 |
+
return func
|
| 50 |
+
|
| 51 |
# Import application modules
|
| 52 |
try:
|
| 53 |
from main import process_video
|
|
|
|
| 96 |
return False, f"Error validating video: {str(e)}"
|
| 97 |
|
| 98 |
|
| 99 |
+
@spaces.GPU # Enable ZeroGPU acceleration (automatic CPU fallback if unavailable)
|
| 100 |
def estimate_vehicle_speed(
|
| 101 |
video_file: str,
|
| 102 |
model_choice: str,
|
|
|
|
| 107 |
"""
|
| 108 |
Process video and estimate vehicle speeds.
|
| 109 |
|
| 110 |
+
This function is decorated with @spaces.GPU to enable automatic GPU
|
| 111 |
+
acceleration when running on ZeroGPU Spaces. If GPU is not available,
|
| 112 |
+
it automatically falls back to CPU processing.
|
| 113 |
+
|
| 114 |
Args:
|
| 115 |
video_file: Path to uploaded video
|
| 116 |
model_choice: YOLO model selection
|