Spaces:
Running
on
Zero
Running
on
Zero
xiaoyuxi
commited on
Commit
·
da74499
1
Parent(s):
b08da78
vggt
Browse files
app.py
CHANGED
|
@@ -22,13 +22,19 @@ def initialize_backend():
|
|
| 22 |
backend_api = gr.load(f"spaces/{BACKEND_SPACE_URL}", token=hf_token)
|
| 23 |
|
| 24 |
# Test if the API object has the expected methods
|
| 25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
BACKEND_AVAILABLE = True
|
| 27 |
print("✅ Backend connection successful!")
|
| 28 |
print("✅ Backend API methods are available")
|
| 29 |
return True
|
| 30 |
else:
|
| 31 |
print("❌ Backend API methods not found")
|
|
|
|
| 32 |
BACKEND_AVAILABLE = False
|
| 33 |
return False
|
| 34 |
|
|
@@ -94,9 +100,18 @@ def handle_video_upload(video):
|
|
| 94 |
if BACKEND_AVAILABLE and backend_api:
|
| 95 |
# Try to use backend API
|
| 96 |
try:
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 100 |
except Exception as e:
|
| 101 |
print(f"Backend API call failed: {e}")
|
| 102 |
# Fallback to local processing
|
|
@@ -220,15 +235,25 @@ def launch_viz(grid_size, vo_points, fps, original_image_state):
|
|
| 220 |
print(f"🔧 Original image state type: {type(original_image_state)}")
|
| 221 |
print(f"🔧 Original image state preview: {str(original_image_state)[:100]}...")
|
| 222 |
|
| 223 |
-
|
| 224 |
-
|
|
|
|
|
|
|
| 225 |
)
|
| 226 |
|
| 227 |
print(f"✅ Backend API call successful!")
|
| 228 |
-
print(f"🔧
|
| 229 |
-
print(f"🔧
|
| 230 |
|
| 231 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 232 |
except Exception as e:
|
| 233 |
print(f"❌ Backend API call failed: {e}")
|
| 234 |
print(f"🔧 Error type: {type(e)}")
|
|
|
|
| 22 |
backend_api = gr.load(f"spaces/{BACKEND_SPACE_URL}", token=hf_token)
|
| 23 |
|
| 24 |
# Test if the API object has the expected methods
|
| 25 |
+
print(f"🔧 Backend API object type: {type(backend_api)}")
|
| 26 |
+
print(f"🔧 Backend API object attributes: {dir(backend_api)}")
|
| 27 |
+
|
| 28 |
+
# gr.load() typically exposes the Interface's fn function directly
|
| 29 |
+
# So we should look for the main function name, not the wrapper names
|
| 30 |
+
if hasattr(backend_api, 'process_video_with_points'):
|
| 31 |
BACKEND_AVAILABLE = True
|
| 32 |
print("✅ Backend connection successful!")
|
| 33 |
print("✅ Backend API methods are available")
|
| 34 |
return True
|
| 35 |
else:
|
| 36 |
print("❌ Backend API methods not found")
|
| 37 |
+
print(f"🔧 Available methods: {[attr for attr in dir(backend_api) if not attr.startswith('_')]}")
|
| 38 |
BACKEND_AVAILABLE = False
|
| 39 |
return False
|
| 40 |
|
|
|
|
| 100 |
if BACKEND_AVAILABLE and backend_api:
|
| 101 |
# Try to use backend API
|
| 102 |
try:
|
| 103 |
+
# Use the main function directly since gr.load() exposes the Interface's fn
|
| 104 |
+
result = backend_api.process_video_with_points(video, [], 50, 756, 3)
|
| 105 |
+
# Parse the result to extract what we need
|
| 106 |
+
if isinstance(result, dict) and result.get("success"):
|
| 107 |
+
# For now, just extract the first frame locally
|
| 108 |
+
display_image = extract_first_frame(video)
|
| 109 |
+
original_image_state = json.dumps({"video_path": video, "frame": "backend_processing"})
|
| 110 |
+
return original_image_state, display_image, [], 50, 756, 3
|
| 111 |
+
else:
|
| 112 |
+
print("Backend processing failed, using local fallback")
|
| 113 |
+
# Fallback to local processing
|
| 114 |
+
pass
|
| 115 |
except Exception as e:
|
| 116 |
print(f"Backend API call failed: {e}")
|
| 117 |
# Fallback to local processing
|
|
|
|
| 235 |
print(f"🔧 Original image state type: {type(original_image_state)}")
|
| 236 |
print(f"🔧 Original image state preview: {str(original_image_state)[:100]}...")
|
| 237 |
|
| 238 |
+
# Use the main function with points from the state
|
| 239 |
+
# For now, we'll use empty points since we're in local mode
|
| 240 |
+
result = backend_api.process_video_with_points(
|
| 241 |
+
None, [], grid_size, vo_points, fps
|
| 242 |
)
|
| 243 |
|
| 244 |
print(f"✅ Backend API call successful!")
|
| 245 |
+
print(f"🔧 Result type: {type(result)}")
|
| 246 |
+
print(f"🔧 Result: {result}")
|
| 247 |
|
| 248 |
+
# Parse the result
|
| 249 |
+
if isinstance(result, dict) and result.get("success"):
|
| 250 |
+
viz_html = result.get("viz_html_path", "")
|
| 251 |
+
track_video_path = result.get("track_video_path", "")
|
| 252 |
+
return viz_html, track_video_path
|
| 253 |
+
else:
|
| 254 |
+
print("Backend processing failed, showing error message")
|
| 255 |
+
# Fallback to error message
|
| 256 |
+
pass
|
| 257 |
except Exception as e:
|
| 258 |
print(f"❌ Backend API call failed: {e}")
|
| 259 |
print(f"🔧 Error type: {type(e)}")
|