Spaces:
Sleeping
Sleeping
Georg Claude Sonnet 4.5 commited on
Commit ·
e93c3d3
1
Parent(s): 08948c8
Add @spaces.GPU decorators to Gradio wrapper functions
Browse files- Decorate gradio_initialize() with @spaces.GPU(duration=120)
- Decorate gradio_estimate() with @spaces.GPU(duration=30)
- Remove @spaces.GPU from class methods to avoid double decoration
- ZeroGPU requires decorators on functions directly connected to Gradio
This fixes: 'No @spaces.GPU function detected during startup'
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
app.py
CHANGED
|
@@ -38,7 +38,6 @@ class FoundationPoseInference:
|
|
| 38 |
self.tracked_objects = {}
|
| 39 |
self.use_real_model = USE_REAL_MODEL
|
| 40 |
|
| 41 |
-
@spaces.GPU(duration=120) # Allocate GPU for 120 seconds (includes model loading)
|
| 42 |
def initialize_model(self):
|
| 43 |
"""Initialize the FoundationPose model on GPU."""
|
| 44 |
if self.initialized:
|
|
@@ -112,7 +111,6 @@ class FoundationPoseInference:
|
|
| 112 |
logger.info(f"✓ Object '{object_id}' registered (placeholder mode)")
|
| 113 |
return True
|
| 114 |
|
| 115 |
-
@spaces.GPU(duration=10)
|
| 116 |
def estimate_pose(
|
| 117 |
self,
|
| 118 |
object_id: str,
|
|
@@ -265,6 +263,7 @@ async def api_estimate(request: EstimateRequest):
|
|
| 265 |
|
| 266 |
|
| 267 |
# Gradio wrapper functions
|
|
|
|
| 268 |
def gradio_initialize(object_id: str, reference_files: List, fx: float, fy: float, cx: float, cy: float):
|
| 269 |
"""Gradio wrapper for object initialization."""
|
| 270 |
try:
|
|
@@ -291,7 +290,7 @@ def gradio_initialize(object_id: str, reference_files: List, fx: float, fy: floa
|
|
| 291 |
"cy": cy
|
| 292 |
}
|
| 293 |
|
| 294 |
-
# Register object
|
| 295 |
success = pose_estimator.register_object(
|
| 296 |
object_id=object_id,
|
| 297 |
reference_images=reference_images,
|
|
@@ -308,6 +307,7 @@ def gradio_initialize(object_id: str, reference_files: List, fx: float, fy: floa
|
|
| 308 |
return f"Error: {str(e)}"
|
| 309 |
|
| 310 |
|
|
|
|
| 311 |
def gradio_estimate(object_id: str, query_image: np.ndarray, fx: float, fy: float, cx: float, cy: float):
|
| 312 |
"""Gradio wrapper for pose estimation."""
|
| 313 |
try:
|
|
@@ -322,7 +322,7 @@ def gradio_estimate(object_id: str, query_image: np.ndarray, fx: float, fy: floa
|
|
| 322 |
"cy": cy
|
| 323 |
}
|
| 324 |
|
| 325 |
-
# Estimate pose
|
| 326 |
result = pose_estimator.estimate_pose(
|
| 327 |
object_id=object_id,
|
| 328 |
query_image=query_image,
|
|
|
|
| 38 |
self.tracked_objects = {}
|
| 39 |
self.use_real_model = USE_REAL_MODEL
|
| 40 |
|
|
|
|
| 41 |
def initialize_model(self):
|
| 42 |
"""Initialize the FoundationPose model on GPU."""
|
| 43 |
if self.initialized:
|
|
|
|
| 111 |
logger.info(f"✓ Object '{object_id}' registered (placeholder mode)")
|
| 112 |
return True
|
| 113 |
|
|
|
|
| 114 |
def estimate_pose(
|
| 115 |
self,
|
| 116 |
object_id: str,
|
|
|
|
| 263 |
|
| 264 |
|
| 265 |
# Gradio wrapper functions
|
| 266 |
+
@spaces.GPU(duration=120)
|
| 267 |
def gradio_initialize(object_id: str, reference_files: List, fx: float, fy: float, cx: float, cy: float):
|
| 268 |
"""Gradio wrapper for object initialization."""
|
| 269 |
try:
|
|
|
|
| 290 |
"cy": cy
|
| 291 |
}
|
| 292 |
|
| 293 |
+
# Register object
|
| 294 |
success = pose_estimator.register_object(
|
| 295 |
object_id=object_id,
|
| 296 |
reference_images=reference_images,
|
|
|
|
| 307 |
return f"Error: {str(e)}"
|
| 308 |
|
| 309 |
|
| 310 |
+
@spaces.GPU(duration=30)
|
| 311 |
def gradio_estimate(object_id: str, query_image: np.ndarray, fx: float, fy: float, cx: float, cy: float):
|
| 312 |
"""Gradio wrapper for pose estimation."""
|
| 313 |
try:
|
|
|
|
| 322 |
"cy": cy
|
| 323 |
}
|
| 324 |
|
| 325 |
+
# Estimate pose
|
| 326 |
result = pose_estimator.estimate_pose(
|
| 327 |
object_id=object_id,
|
| 328 |
query_image=query_image,
|