Spaces:
Running
on
Zero
Running
on
Zero
xiaoyuxi
commited on
Commit
·
ab45138
1
Parent(s):
66adae5
backend
Browse files
app.py
CHANGED
|
@@ -216,10 +216,10 @@ def handle_video_upload(video):
|
|
| 216 |
try:
|
| 217 |
print("🔧 Calling backend API for video upload...")
|
| 218 |
|
| 219 |
-
# Call the unified API with upload_video function type
|
| 220 |
result = backend_client.predict(
|
| 221 |
"upload_video", # function_type
|
| 222 |
-
handle_file(video), # video file
|
| 223 |
"", # original_image_state (not used for upload)
|
| 224 |
[], # selected_points (not used for upload)
|
| 225 |
"positive_point", # point_type (not used for upload)
|
|
@@ -242,6 +242,11 @@ def handle_video_upload(video):
|
|
| 242 |
display_image = result.get("display_image", None)
|
| 243 |
selected_points = result.get("selected_points", [])
|
| 244 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 245 |
# Get video settings based on video name
|
| 246 |
video_name = get_video_name(video)
|
| 247 |
grid_size_val, vo_points_val, fps_val = get_video_settings(video_name)
|
|
@@ -337,6 +342,12 @@ def select_point(original_img: str, sel_pix: list, point_type: str, evt: gr.Sele
|
|
| 337 |
if isinstance(result, dict) and result.get("success"):
|
| 338 |
display_image = result.get("display_image", None)
|
| 339 |
new_sel_pix = result.get("selected_points", sel_pix)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 340 |
return display_image, new_sel_pix
|
| 341 |
else:
|
| 342 |
print("Backend processing failed, using local fallback")
|
|
@@ -384,8 +395,8 @@ def select_point(original_img: str, sel_pix: list, point_type: str, evt: gr.Sele
|
|
| 384 |
cv2.circle(display_image, (x, y), 8, color, -1)
|
| 385 |
cv2.circle(display_image, (x, y), 12, (255, 255, 255), 2)
|
| 386 |
|
| 387 |
-
# Add point to selected points list
|
| 388 |
-
new_sel_pix = sel_pix.copy()
|
| 389 |
new_sel_pix.append([x, y, point_type])
|
| 390 |
|
| 391 |
return display_image, new_sel_pix
|
|
@@ -429,6 +440,12 @@ def reset_points(original_img: str, sel_pix):
|
|
| 429 |
if isinstance(result, dict) and result.get("success"):
|
| 430 |
display_image = result.get("display_image", None)
|
| 431 |
new_sel_pix = result.get("selected_points", [])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 432 |
return display_image, new_sel_pix
|
| 433 |
else:
|
| 434 |
print("Backend processing failed, using local fallback")
|
|
|
|
| 216 |
try:
|
| 217 |
print("🔧 Calling backend API for video upload...")
|
| 218 |
|
| 219 |
+
# Call the unified API with upload_video function type - fix: use handle_file wrapper
|
| 220 |
result = backend_client.predict(
|
| 221 |
"upload_video", # function_type
|
| 222 |
+
handle_file(video), # video file - wrapped with handle_file
|
| 223 |
"", # original_image_state (not used for upload)
|
| 224 |
[], # selected_points (not used for upload)
|
| 225 |
"positive_point", # point_type (not used for upload)
|
|
|
|
| 242 |
display_image = result.get("display_image", None)
|
| 243 |
selected_points = result.get("selected_points", [])
|
| 244 |
|
| 245 |
+
# Fix: Convert display_image from list back to numpy array if needed
|
| 246 |
+
if isinstance(display_image, list):
|
| 247 |
+
display_image = np.array(display_image, dtype=np.uint8)
|
| 248 |
+
print(f"🔧 Converted display_image from list to numpy array: {display_image.shape}")
|
| 249 |
+
|
| 250 |
# Get video settings based on video name
|
| 251 |
video_name = get_video_name(video)
|
| 252 |
grid_size_val, vo_points_val, fps_val = get_video_settings(video_name)
|
|
|
|
| 342 |
if isinstance(result, dict) and result.get("success"):
|
| 343 |
display_image = result.get("display_image", None)
|
| 344 |
new_sel_pix = result.get("selected_points", sel_pix)
|
| 345 |
+
|
| 346 |
+
# Fix: Convert display_image from list back to numpy array if needed
|
| 347 |
+
if isinstance(display_image, list):
|
| 348 |
+
display_image = np.array(display_image, dtype=np.uint8)
|
| 349 |
+
print(f"🔧 Converted display_image from list to numpy array: {display_image.shape}")
|
| 350 |
+
|
| 351 |
return display_image, new_sel_pix
|
| 352 |
else:
|
| 353 |
print("Backend processing failed, using local fallback")
|
|
|
|
| 395 |
cv2.circle(display_image, (x, y), 8, color, -1)
|
| 396 |
cv2.circle(display_image, (x, y), 12, (255, 255, 255), 2)
|
| 397 |
|
| 398 |
+
# Add point to selected points list - fix logic to match local version
|
| 399 |
+
new_sel_pix = sel_pix.copy() if sel_pix else []
|
| 400 |
new_sel_pix.append([x, y, point_type])
|
| 401 |
|
| 402 |
return display_image, new_sel_pix
|
|
|
|
| 440 |
if isinstance(result, dict) and result.get("success"):
|
| 441 |
display_image = result.get("display_image", None)
|
| 442 |
new_sel_pix = result.get("selected_points", [])
|
| 443 |
+
|
| 444 |
+
# Fix: Convert display_image from list back to numpy array if needed
|
| 445 |
+
if isinstance(display_image, list):
|
| 446 |
+
display_image = np.array(display_image, dtype=np.uint8)
|
| 447 |
+
print(f"🔧 Converted display_image from list to numpy array: {display_image.shape}")
|
| 448 |
+
|
| 449 |
return display_image, new_sel_pix
|
| 450 |
else:
|
| 451 |
print("Backend processing failed, using local fallback")
|