Spaces:
Running
on
Zero
Running
on
Zero
xiaoyuxi
commited on
Commit
·
f02374d
1
Parent(s):
069b482
vggt
Browse files
app.py
CHANGED
|
@@ -117,29 +117,22 @@ def handle_video_upload(video):
|
|
| 117 |
try:
|
| 118 |
print("🔧 Calling backend API for video upload...")
|
| 119 |
|
| 120 |
-
#
|
| 121 |
if 0 in backend_api.fns:
|
| 122 |
-
print("🔧 Using backend
|
|
|
|
| 123 |
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
# For now, just extract the first frame locally
|
| 134 |
-
display_image = extract_first_frame(video)
|
| 135 |
-
original_image_state = json.dumps({"video_path": video, "frame": "backend_processing"})
|
| 136 |
-
return original_image_state, display_image, [], 50, 756, 3
|
| 137 |
-
else:
|
| 138 |
-
print("Backend processing failed, using local fallback")
|
| 139 |
-
# Fallback to local processing
|
| 140 |
-
pass
|
| 141 |
else:
|
| 142 |
-
print("
|
| 143 |
# Fallback to local processing
|
| 144 |
pass
|
| 145 |
else:
|
|
@@ -181,10 +174,10 @@ def select_point(original_img: str, sel_pix: list, point_type: str, evt: gr.Sele
|
|
| 181 |
try:
|
| 182 |
print(f"🔧 Calling backend select point API: x={evt.index[0]}, y={evt.index[1]}, type={point_type}")
|
| 183 |
|
| 184 |
-
#
|
| 185 |
if 1 in backend_api.fns:
|
| 186 |
-
print("🔧 Using backend
|
| 187 |
-
result = backend_api.
|
| 188 |
|
| 189 |
print(f"✅ Backend select point API call successful!")
|
| 190 |
print(f"🔧 Result type: {type(result)}")
|
|
@@ -267,10 +260,10 @@ def reset_points(original_img: str, sel_pix):
|
|
| 267 |
try:
|
| 268 |
print("🔧 Calling backend reset points API")
|
| 269 |
|
| 270 |
-
#
|
| 271 |
if 2 in backend_api.fns:
|
| 272 |
-
print("🔧 Using backend
|
| 273 |
-
result = backend_api.
|
| 274 |
|
| 275 |
print(f"✅ Backend reset points API call successful!")
|
| 276 |
print(f"🔧 Result type: {type(result)}")
|
|
@@ -327,43 +320,25 @@ def launch_viz(grid_size, vo_points, fps, original_image_state):
|
|
| 327 |
print(f"🔧 Original image state type: {type(original_image_state)}")
|
| 328 |
print(f"🔧 Original image state preview: {str(original_image_state)[:100]}...")
|
| 329 |
|
| 330 |
-
#
|
| 331 |
-
print(f"🔧 Backend API predict type: {type(backend_api.predict)}")
|
| 332 |
-
print(f"🔧 Backend API predict: {backend_api.predict}")
|
| 333 |
-
|
| 334 |
-
# For gr.Blocks, we use predict method
|
| 335 |
if 0 in backend_api.fns:
|
| 336 |
-
print("🔧 Using backend
|
| 337 |
-
#
|
| 338 |
-
|
| 339 |
-
|
| 340 |
-
|
| 341 |
-
|
| 342 |
-
|
| 343 |
-
|
| 344 |
-
|
| 345 |
-
|
| 346 |
-
|
| 347 |
-
|
| 348 |
-
|
| 349 |
-
track_video_path = result.get("track_video_path", "")
|
| 350 |
-
return viz_html, track_video_path
|
| 351 |
-
else:
|
| 352 |
-
print("Backend processing failed, showing error message")
|
| 353 |
-
# Fallback to error message
|
| 354 |
-
pass
|
| 355 |
else:
|
| 356 |
-
print("
|
| 357 |
-
|
| 358 |
-
|
| 359 |
-
if hasattr(backend_api, 'call_function'):
|
| 360 |
-
print("🔧 Trying call_function method")
|
| 361 |
-
result = backend_api.call_function(0, [None, [], grid_size, vo_points, fps])
|
| 362 |
-
# Handle result...
|
| 363 |
-
else:
|
| 364 |
-
print("❌ No callable method found")
|
| 365 |
-
# Fallback to error message
|
| 366 |
-
pass
|
| 367 |
else:
|
| 368 |
print("Backend function 0 not found")
|
| 369 |
# Fallback to error message
|
|
@@ -395,7 +370,6 @@ def launch_viz(grid_size, vo_points, fps, original_image_state):
|
|
| 395 |
<p style='color: #666; font-size: 12px; margin: 0;'>Backend URL: {BACKEND_SPACE_URL}</p>
|
| 396 |
<p style='color: #666; font-size: 12px; margin: 0;'>Backend Type: {type(backend_api) if backend_api else 'None'}</p>
|
| 397 |
<p style='color: #666; font-size: 12px; margin: 0;'>Available Functions: {list(backend_api.fns.keys()) if backend_api and hasattr(backend_api, 'fns') else 'None'}</p>
|
| 398 |
-
<p style='color: #666; font-size: 12px; margin: 0;'>Predict Type: {type(backend_api.predict) if backend_api and hasattr(backend_api, 'predict') else 'None'}</p>
|
| 399 |
</div>
|
| 400 |
<p style='color: #2d3436; font-weight: bold; margin-top: 15px;'>
|
| 401 |
Current Status: Backend unavailable - Running in limited mode
|
|
|
|
| 117 |
try:
|
| 118 |
print("🔧 Calling backend API for video upload...")
|
| 119 |
|
| 120 |
+
# Use call_function method
|
| 121 |
if 0 in backend_api.fns:
|
| 122 |
+
print("🔧 Using backend call_function method")
|
| 123 |
+
result = backend_api.call_function(0, [video, [], 50, 756, 3])
|
| 124 |
|
| 125 |
+
print(f"✅ Backend video upload API call successful!")
|
| 126 |
+
print(f"🔧 Result type: {type(result)}")
|
| 127 |
+
|
| 128 |
+
# Parse the result - expect a dict with success status
|
| 129 |
+
if isinstance(result, dict) and result.get("success"):
|
| 130 |
+
# For now, just extract the first frame locally
|
| 131 |
+
display_image = extract_first_frame(video)
|
| 132 |
+
original_image_state = json.dumps({"video_path": video, "frame": "backend_processing"})
|
| 133 |
+
return original_image_state, display_image, [], 50, 756, 3
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 134 |
else:
|
| 135 |
+
print("Backend processing failed, using local fallback")
|
| 136 |
# Fallback to local processing
|
| 137 |
pass
|
| 138 |
else:
|
|
|
|
| 174 |
try:
|
| 175 |
print(f"🔧 Calling backend select point API: x={evt.index[0]}, y={evt.index[1]}, type={point_type}")
|
| 176 |
|
| 177 |
+
# Use call_function method
|
| 178 |
if 1 in backend_api.fns:
|
| 179 |
+
print("🔧 Using backend call_function method for point selection")
|
| 180 |
+
result = backend_api.call_function(1, [original_img, sel_pix, point_type, evt.index[0], evt.index[1]])
|
| 181 |
|
| 182 |
print(f"✅ Backend select point API call successful!")
|
| 183 |
print(f"🔧 Result type: {type(result)}")
|
|
|
|
| 260 |
try:
|
| 261 |
print("🔧 Calling backend reset points API")
|
| 262 |
|
| 263 |
+
# Use call_function method
|
| 264 |
if 2 in backend_api.fns:
|
| 265 |
+
print("🔧 Using backend call_function method for reset")
|
| 266 |
+
result = backend_api.call_function(2, [original_img, sel_pix])
|
| 267 |
|
| 268 |
print(f"✅ Backend reset points API call successful!")
|
| 269 |
print(f"🔧 Result type: {type(result)}")
|
|
|
|
| 320 |
print(f"🔧 Original image state type: {type(original_image_state)}")
|
| 321 |
print(f"🔧 Original image state preview: {str(original_image_state)[:100]}...")
|
| 322 |
|
| 323 |
+
# Use call_function method
|
|
|
|
|
|
|
|
|
|
|
|
|
| 324 |
if 0 in backend_api.fns:
|
| 325 |
+
print("🔧 Using backend call_function method")
|
| 326 |
+
# For now, we'll use empty points since we're in local mode
|
| 327 |
+
result = backend_api.call_function(0, [None, [], grid_size, vo_points, fps])
|
| 328 |
+
|
| 329 |
+
print(f"✅ Backend API call successful!")
|
| 330 |
+
print(f"🔧 Result type: {type(result)}")
|
| 331 |
+
print(f"🔧 Result: {result}")
|
| 332 |
+
|
| 333 |
+
# Parse the result
|
| 334 |
+
if isinstance(result, dict) and result.get("success"):
|
| 335 |
+
viz_html = result.get("viz_html_path", "")
|
| 336 |
+
track_video_path = result.get("track_video_path", "")
|
| 337 |
+
return viz_html, track_video_path
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 338 |
else:
|
| 339 |
+
print("Backend processing failed, showing error message")
|
| 340 |
+
# Fallback to error message
|
| 341 |
+
pass
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 342 |
else:
|
| 343 |
print("Backend function 0 not found")
|
| 344 |
# Fallback to error message
|
|
|
|
| 370 |
<p style='color: #666; font-size: 12px; margin: 0;'>Backend URL: {BACKEND_SPACE_URL}</p>
|
| 371 |
<p style='color: #666; font-size: 12px; margin: 0;'>Backend Type: {type(backend_api) if backend_api else 'None'}</p>
|
| 372 |
<p style='color: #666; font-size: 12px; margin: 0;'>Available Functions: {list(backend_api.fns.keys()) if backend_api and hasattr(backend_api, 'fns') else 'None'}</p>
|
|
|
|
| 373 |
</div>
|
| 374 |
<p style='color: #2d3436; font-weight: bold; margin-top: 15px;'>
|
| 375 |
Current Status: Backend unavailable - Running in limited mode
|