xiaoyuxi commited on
Commit
dc6fad3
·
1 Parent(s): 3c8b47e
Files changed (1) hide show
  1. app.py +53 -15
app.py CHANGED
@@ -445,11 +445,28 @@ def launch_viz(grid_size, vo_points, fps, original_image_state):
445
  print(f"🔧 Original image state type: {type(original_image_state)}")
446
  print(f"🔧 Original image state preview: {str(original_image_state)[:100]}...")
447
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
448
  # Call the unified API with run_tracker function type
449
  result = backend_client.predict(
450
  "run_tracker", # function_type
451
  None, # video file (not used for run_tracker)
452
- original_image_state, # original_image_state
453
  [], # selected_points (not used for run_tracker)
454
  "positive_point", # point_type (not used for run_tracker)
455
  0, # point_x (not used for run_tracker)
@@ -470,8 +487,9 @@ def launch_viz(grid_size, vo_points, fps, original_image_state):
470
  track_video_path = result.get("track_video_path", "")
471
  return viz_html, track_video_path
472
  else:
473
- print("Backend processing failed, showing error message")
474
- # Fallback to error message
 
475
  pass
476
  except Exception as e:
477
  print(f"❌ Backend API call failed: {e}")
@@ -488,36 +506,56 @@ def launch_viz(grid_size, vo_points, fps, original_image_state):
488
  print("🔧 Frontend and backend may be using incompatible Gradio versions")
489
  elif "timeout" in str(e).lower():
490
  print("🔧 Backend request timed out - Space might be overloaded")
 
 
 
 
491
  else:
492
  print(f"🔧 Unexpected error type: {type(e).__name__}")
493
 
494
  print("🔄 Showing error message instead of visualization...")
495
- # Fallback to local processing
496
  pass
497
 
 
 
 
 
 
 
 
 
 
 
 
498
  # Fallback: show message that backend is required
499
  error_message = f"""
500
  <div style='border: 3px solid #ff6b6b; border-radius: 10px; padding: 20px; background-color: #fff5f5;'>
501
- <h3 style='color: #d63031; margin-bottom: 15px;'>⚠️ Backend Connection Required</h3>
502
  <p style='color: #2d3436; line-height: 1.6;'>
503
- The tracking and visualization features require a connection to the backend Space.
504
- Please ensure:
505
  </p>
 
506
  <ul style='color: #2d3436; line-height: 1.6;'>
507
- <li>The backend Space is deployed and running</li>
508
- <li>The BACKEND_SPACE_URL is correctly configured</li>
509
- <li>You have proper access permissions to the backend Space</li>
 
510
  </ul>
511
- <div style='background-color: #f8f9fa; border-radius: 5px; padding: 10px; margin-top: 10px;'>
512
  <p style='color: #2d3436; font-weight: bold; margin: 0 0 5px 0;'>Debug Information:</p>
513
  <p style='color: #666; font-size: 12px; margin: 0;'>Backend Available: {BACKEND_AVAILABLE}</p>
514
  <p style='color: #666; font-size: 12px; margin: 0;'>Backend Client: {backend_client is not None}</p>
515
  <p style='color: #666; font-size: 12px; margin: 0;'>Backend URL: {BACKEND_SPACE_URL}</p>
516
- <p style='color: #666; font-size: 12px; margin: 0;'>Client Type: {type(backend_client) if backend_client else 'None'}</p>
 
 
 
 
 
 
 
517
  </div>
518
- <p style='color: #2d3436; font-weight: bold; margin-top: 15px;'>
519
- Current Status: Backend unavailable - Running in limited mode
520
- </p>
521
  </div>
522
  """
523
  return error_message, None
 
445
  print(f"🔧 Original image state type: {type(original_image_state)}")
446
  print(f"🔧 Original image state preview: {str(original_image_state)[:100]}...")
447
 
448
+ # Validate and potentially fix the original_image_state format
449
+ state_to_send = original_image_state
450
+
451
+ # Check if this is a local processing state that needs to be converted
452
+ try:
453
+ if isinstance(original_image_state, str):
454
+ parsed_state = json.loads(original_image_state)
455
+ if "video_path" in parsed_state and "frame" in parsed_state:
456
+ # This is a local processing state, we need to handle differently
457
+ print("🔧 Detected local processing state, cannot use backend for tracking")
458
+ print("🔧 Backend requires proper video upload state from backend API")
459
+ # Fall through to local processing
460
+ raise ValueError("Local state cannot be processed by backend")
461
+ except json.JSONDecodeError:
462
+ print("🔧 Invalid JSON state, cannot send to backend")
463
+ raise ValueError("Invalid state format")
464
+
465
  # Call the unified API with run_tracker function type
466
  result = backend_client.predict(
467
  "run_tracker", # function_type
468
  None, # video file (not used for run_tracker)
469
+ state_to_send, # original_image_state
470
  [], # selected_points (not used for run_tracker)
471
  "positive_point", # point_type (not used for run_tracker)
472
  0, # point_x (not used for run_tracker)
 
487
  track_video_path = result.get("track_video_path", "")
488
  return viz_html, track_video_path
489
  else:
490
+ error_msg = result.get("error", "Unknown error") if isinstance(result, dict) else "Backend processing failed"
491
+ print(f"❌ Backend processing failed: {error_msg}")
492
+ # Fall through to error message
493
  pass
494
  except Exception as e:
495
  print(f"❌ Backend API call failed: {e}")
 
506
  print("🔧 Frontend and backend may be using incompatible Gradio versions")
507
  elif "timeout" in str(e).lower():
508
  print("🔧 Backend request timed out - Space might be overloaded")
509
+ elif "Expecting value" in str(e):
510
+ print("🔧 JSON parsing error in backend - state format mismatch")
511
+ print("🔧 This happens when using local processing state with backend API")
512
+ print("🔧 Please upload video again to use backend processing")
513
  else:
514
  print(f"🔧 Unexpected error type: {type(e).__name__}")
515
 
516
  print("🔄 Showing error message instead of visualization...")
517
+ # Fall through to error message
518
  pass
519
 
520
+ # Create an informative error message based on the state
521
+ state_info = ""
522
+ try:
523
+ if isinstance(original_image_state, str):
524
+ parsed_state = json.loads(original_image_state)
525
+ if "video_path" in parsed_state:
526
+ video_name = os.path.basename(parsed_state["video_path"])
527
+ state_info = f"Video: {video_name}"
528
+ except:
529
+ state_info = "State format unknown"
530
+
531
  # Fallback: show message that backend is required
532
  error_message = f"""
533
  <div style='border: 3px solid #ff6b6b; border-radius: 10px; padding: 20px; background-color: #fff5f5;'>
534
+ <h3 style='color: #d63031; margin-bottom: 15px;'>⚠️ Backend Processing Required</h3>
535
  <p style='color: #2d3436; line-height: 1.6;'>
536
+ The tracking and visualization features require backend processing. The current setup is using local processing which is incompatible with the backend API.
 
537
  </p>
538
+ <h4 style='color: #d63031; margin: 15px 0 10px 0;'>Solutions:</h4>
539
  <ul style='color: #2d3436; line-height: 1.6;'>
540
+ <li><strong>Upload video again:</strong> This will properly initialize the backend state</li>
541
+ <li><strong>Select points on the frame:</strong> Ensure you've clicked on the object to track</li>
542
+ <li><strong>Check backend connection:</strong> Ensure the backend Space is running</li>
543
+ <li><strong>Use compatible state:</strong> Avoid local processing mode</li>
544
  </ul>
545
+ <div style='background-color: #f8f9fa; border-radius: 5px; padding: 10px; margin-top: 15px;'>
546
  <p style='color: #2d3436; font-weight: bold; margin: 0 0 5px 0;'>Debug Information:</p>
547
  <p style='color: #666; font-size: 12px; margin: 0;'>Backend Available: {BACKEND_AVAILABLE}</p>
548
  <p style='color: #666; font-size: 12px; margin: 0;'>Backend Client: {backend_client is not None}</p>
549
  <p style='color: #666; font-size: 12px; margin: 0;'>Backend URL: {BACKEND_SPACE_URL}</p>
550
+ <p style='color: #666; font-size: 12px; margin: 0;'>State Info: {state_info}</p>
551
+ <p style='color: #666; font-size: 12px; margin: 0;'>Processing Mode: {"Backend" if BACKEND_AVAILABLE else "Local (Limited)"}</p>
552
+ </div>
553
+ <div style='background-color: #e3f2fd; border-radius: 5px; padding: 10px; margin-top: 10px; border-left: 4px solid #2196f3;'>
554
+ <p style='color: #1976d2; font-weight: bold; margin: 0 0 5px 0;'>💡 Quick Fix:</p>
555
+ <p style='color: #1976d2; font-size: 13px; margin: 0;'>
556
+ Try uploading your video again - this should properly initialize the backend state for tracking.
557
+ </p>
558
  </div>
 
 
 
559
  </div>
560
  """
561
  return error_message, None