Spaces:
Running
on
Zero
Running
on
Zero
xiaoyuxi
commited on
Commit
·
416aa34
1
Parent(s):
4d172be
vggt
Browse files
app.py
CHANGED
|
@@ -112,32 +112,27 @@ def handle_video_upload(video):
|
|
| 112 |
return None, None, [], 50, 756, 3
|
| 113 |
|
| 114 |
try:
|
| 115 |
-
if BACKEND_AVAILABLE and backend_api and hasattr(backend_api, '
|
| 116 |
# Try to use backend API
|
| 117 |
try:
|
| 118 |
print("🔧 Calling backend API for video upload...")
|
| 119 |
|
| 120 |
-
#
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
return original_image_state, display_image, [], 50, 756, 3
|
| 135 |
-
else:
|
| 136 |
-
print("Backend processing failed, using local fallback")
|
| 137 |
-
# Fallback to local processing
|
| 138 |
-
pass
|
| 139 |
else:
|
| 140 |
-
print("Backend
|
| 141 |
# Fallback to local processing
|
| 142 |
pass
|
| 143 |
except Exception as e:
|
|
@@ -170,21 +165,27 @@ def select_point(original_img: str, sel_pix: list, point_type: str, evt: gr.Sele
|
|
| 170 |
return None, []
|
| 171 |
|
| 172 |
try:
|
| 173 |
-
if BACKEND_AVAILABLE and backend_api and hasattr(backend_api, '
|
| 174 |
# Try to use backend API
|
| 175 |
try:
|
| 176 |
print(f"🔧 Calling backend select point API: x={evt.index[0]}, y={evt.index[1]}, type={point_type}")
|
| 177 |
|
| 178 |
-
#
|
| 179 |
-
|
| 180 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 181 |
# Create points list with the new point
|
| 182 |
points = [(evt.index[0], evt.index[1], point_type)]
|
| 183 |
-
# Call
|
| 184 |
-
result = backend_api.
|
| 185 |
|
| 186 |
print(f"✅ Backend select point API call successful!")
|
| 187 |
print(f"🔧 Result type: {type(result)}")
|
|
|
|
| 188 |
|
| 189 |
# Parse the result - expect a dict with success status
|
| 190 |
if isinstance(result, dict) and result.get("success"):
|
|
@@ -196,7 +197,7 @@ def select_point(original_img: str, sel_pix: list, point_type: str, evt: gr.Sele
|
|
| 196 |
# Fallback to local processing
|
| 197 |
pass
|
| 198 |
else:
|
| 199 |
-
print("
|
| 200 |
# Fallback to local processing
|
| 201 |
pass
|
| 202 |
except Exception as e:
|
|
@@ -259,19 +260,25 @@ def reset_points(original_img: str, sel_pix):
|
|
| 259 |
return None, []
|
| 260 |
|
| 261 |
try:
|
| 262 |
-
if BACKEND_AVAILABLE and backend_api and hasattr(backend_api, '
|
| 263 |
# Try to use backend API
|
| 264 |
try:
|
| 265 |
print("🔧 Calling backend reset points API")
|
| 266 |
|
| 267 |
-
#
|
| 268 |
-
|
| 269 |
-
|
| 270 |
-
|
| 271 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 272 |
|
| 273 |
print(f"✅ Backend reset points API call successful!")
|
| 274 |
print(f"🔧 Result type: {type(result)}")
|
|
|
|
| 275 |
|
| 276 |
# Parse the result - expect a dict with success status
|
| 277 |
if isinstance(result, dict) and result.get("success"):
|
|
@@ -283,7 +290,7 @@ def reset_points(original_img: str, sel_pix):
|
|
| 283 |
# Fallback to local processing
|
| 284 |
pass
|
| 285 |
else:
|
| 286 |
-
print("
|
| 287 |
# Fallback to local processing
|
| 288 |
pass
|
| 289 |
except Exception as e:
|
|
@@ -318,18 +325,25 @@ def launch_viz(grid_size, vo_points, fps, original_image_state):
|
|
| 318 |
return None, None
|
| 319 |
|
| 320 |
try:
|
| 321 |
-
if BACKEND_AVAILABLE and backend_api and hasattr(backend_api, '
|
| 322 |
# Try to use backend API
|
| 323 |
try:
|
| 324 |
print(f"🔧 Calling backend API with parameters: grid_size={grid_size}, vo_points={vo_points}, fps={fps}")
|
| 325 |
print(f"🔧 Original image state type: {type(original_image_state)}")
|
| 326 |
print(f"🔧 Original image state preview: {str(original_image_state)[:100]}...")
|
| 327 |
|
| 328 |
-
#
|
| 329 |
-
|
| 330 |
-
|
| 331 |
-
|
| 332 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 333 |
|
| 334 |
print(f"✅ Backend API call successful!")
|
| 335 |
print(f"🔧 Result type: {type(result)}")
|
|
@@ -345,7 +359,7 @@ def launch_viz(grid_size, vo_points, fps, original_image_state):
|
|
| 345 |
# Fallback to error message
|
| 346 |
pass
|
| 347 |
else:
|
| 348 |
-
print("
|
| 349 |
# Fallback to error message
|
| 350 |
pass
|
| 351 |
except Exception as e:
|
|
|
|
| 112 |
return None, None, [], 50, 756, 3
|
| 113 |
|
| 114 |
try:
|
| 115 |
+
if BACKEND_AVAILABLE and backend_api and hasattr(backend_api, 'predict'):
|
| 116 |
# Try to use backend API
|
| 117 |
try:
|
| 118 |
print("🔧 Calling backend API for video upload...")
|
| 119 |
|
| 120 |
+
# Call process_video_with_points with empty points to get initial state
|
| 121 |
+
# The function expects: (video_path, points, grid_size, vo_points, fps)
|
| 122 |
+
result = backend_api.predict(video, [], 50, 756, 3)
|
| 123 |
+
|
| 124 |
+
print(f"✅ Backend video upload API call successful!")
|
| 125 |
+
print(f"🔧 Result type: {type(result)}")
|
| 126 |
+
print(f"🔧 Result: {result}")
|
| 127 |
+
|
| 128 |
+
# Parse the result - expect a dict with success status
|
| 129 |
+
if isinstance(result, dict) and result.get("success"):
|
| 130 |
+
# Extract first frame locally for display
|
| 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 |
except Exception as e:
|
|
|
|
| 165 |
return None, []
|
| 166 |
|
| 167 |
try:
|
| 168 |
+
if BACKEND_AVAILABLE and backend_api and hasattr(backend_api, 'predict'):
|
| 169 |
# Try to use backend API
|
| 170 |
try:
|
| 171 |
print(f"🔧 Calling backend select point API: x={evt.index[0]}, y={evt.index[1]}, type={point_type}")
|
| 172 |
|
| 173 |
+
# Parse original image state to get video path
|
| 174 |
+
try:
|
| 175 |
+
state_data = json.loads(original_img)
|
| 176 |
+
video_path = state_data.get("video_path")
|
| 177 |
+
except:
|
| 178 |
+
video_path = None
|
| 179 |
+
|
| 180 |
+
if video_path:
|
| 181 |
# Create points list with the new point
|
| 182 |
points = [(evt.index[0], evt.index[1], point_type)]
|
| 183 |
+
# Call process_video_with_points with the new point
|
| 184 |
+
result = backend_api.predict(video_path, points, 50, 756, 3)
|
| 185 |
|
| 186 |
print(f"✅ Backend select point API call successful!")
|
| 187 |
print(f"🔧 Result type: {type(result)}")
|
| 188 |
+
print(f"🔧 Result: {result}")
|
| 189 |
|
| 190 |
# Parse the result - expect a dict with success status
|
| 191 |
if isinstance(result, dict) and result.get("success"):
|
|
|
|
| 197 |
# Fallback to local processing
|
| 198 |
pass
|
| 199 |
else:
|
| 200 |
+
print("No video path found in state, using local fallback")
|
| 201 |
# Fallback to local processing
|
| 202 |
pass
|
| 203 |
except Exception as e:
|
|
|
|
| 260 |
return None, []
|
| 261 |
|
| 262 |
try:
|
| 263 |
+
if BACKEND_AVAILABLE and backend_api and hasattr(backend_api, 'predict'):
|
| 264 |
# Try to use backend API
|
| 265 |
try:
|
| 266 |
print("🔧 Calling backend reset points API")
|
| 267 |
|
| 268 |
+
# Parse original image state to get video path
|
| 269 |
+
try:
|
| 270 |
+
state_data = json.loads(original_img)
|
| 271 |
+
video_path = state_data.get("video_path")
|
| 272 |
+
except:
|
| 273 |
+
video_path = None
|
| 274 |
+
|
| 275 |
+
if video_path:
|
| 276 |
+
# Call process_video_with_points with empty points to reset
|
| 277 |
+
result = backend_api.predict(video_path, [], 50, 756, 3)
|
| 278 |
|
| 279 |
print(f"✅ Backend reset points API call successful!")
|
| 280 |
print(f"🔧 Result type: {type(result)}")
|
| 281 |
+
print(f"🔧 Result: {result}")
|
| 282 |
|
| 283 |
# Parse the result - expect a dict with success status
|
| 284 |
if isinstance(result, dict) and result.get("success"):
|
|
|
|
| 290 |
# Fallback to local processing
|
| 291 |
pass
|
| 292 |
else:
|
| 293 |
+
print("No video path found in state, using local fallback")
|
| 294 |
# Fallback to local processing
|
| 295 |
pass
|
| 296 |
except Exception as e:
|
|
|
|
| 325 |
return None, None
|
| 326 |
|
| 327 |
try:
|
| 328 |
+
if BACKEND_AVAILABLE and backend_api and hasattr(backend_api, 'predict'):
|
| 329 |
# Try to use backend API
|
| 330 |
try:
|
| 331 |
print(f"🔧 Calling backend API with parameters: grid_size={grid_size}, vo_points={vo_points}, fps={fps}")
|
| 332 |
print(f"🔧 Original image state type: {type(original_image_state)}")
|
| 333 |
print(f"🔧 Original image state preview: {str(original_image_state)[:100]}...")
|
| 334 |
|
| 335 |
+
# Parse original image state to get video path
|
| 336 |
+
try:
|
| 337 |
+
state_data = json.loads(original_image_state)
|
| 338 |
+
video_path = state_data.get("video_path")
|
| 339 |
+
except:
|
| 340 |
+
video_path = None
|
| 341 |
+
|
| 342 |
+
if video_path:
|
| 343 |
+
# Call process_video_with_points with current points and parameters
|
| 344 |
+
# We need to get the current points from the state
|
| 345 |
+
current_points = [] # For now, use empty points
|
| 346 |
+
result = backend_api.predict(video_path, current_points, grid_size, vo_points, fps)
|
| 347 |
|
| 348 |
print(f"✅ Backend API call successful!")
|
| 349 |
print(f"🔧 Result type: {type(result)}")
|
|
|
|
| 359 |
# Fallback to error message
|
| 360 |
pass
|
| 361 |
else:
|
| 362 |
+
print("No video path found in state, showing error message")
|
| 363 |
# Fallback to error message
|
| 364 |
pass
|
| 365 |
except Exception as e:
|