Spaces:
Running
on
Zero
Running
on
Zero
xiaoyuxi
commited on
Commit
·
5347dd7
1
Parent(s):
da74499
vggt
Browse files
app.py
CHANGED
|
@@ -25,15 +25,15 @@ def initialize_backend():
|
|
| 25 |
print(f"🔧 Backend API object type: {type(backend_api)}")
|
| 26 |
print(f"🔧 Backend API object attributes: {dir(backend_api)}")
|
| 27 |
|
| 28 |
-
#
|
| 29 |
-
|
| 30 |
-
|
| 31 |
BACKEND_AVAILABLE = True
|
| 32 |
print("✅ Backend connection successful!")
|
| 33 |
-
print("✅ Backend API
|
| 34 |
return True
|
| 35 |
else:
|
| 36 |
-
print("❌ Backend API
|
| 37 |
print(f"🔧 Available methods: {[attr for attr in dir(backend_api) if not attr.startswith('_')]}")
|
| 38 |
BACKEND_AVAILABLE = False
|
| 39 |
return False
|
|
@@ -97,19 +97,24 @@ def handle_video_upload(video):
|
|
| 97 |
return None, None, [], 50, 756, 3
|
| 98 |
|
| 99 |
try:
|
| 100 |
-
if BACKEND_AVAILABLE and backend_api:
|
| 101 |
# Try to use backend API
|
| 102 |
try:
|
| 103 |
-
# Use the
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 111 |
else:
|
| 112 |
-
print("
|
| 113 |
# Fallback to local processing
|
| 114 |
pass
|
| 115 |
except Exception as e:
|
|
@@ -228,30 +233,35 @@ def launch_viz(grid_size, vo_points, fps, original_image_state):
|
|
| 228 |
return None, None
|
| 229 |
|
| 230 |
try:
|
| 231 |
-
if BACKEND_AVAILABLE and backend_api:
|
| 232 |
# Try to use backend API
|
| 233 |
try:
|
| 234 |
print(f"🔧 Calling backend API with parameters: grid_size={grid_size}, vo_points={vo_points}, fps={fps}")
|
| 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
|
| 239 |
-
|
| 240 |
-
|
| 241 |
-
|
| 242 |
-
|
| 243 |
-
|
| 244 |
-
|
| 245 |
-
|
| 246 |
-
|
| 247 |
-
|
| 248 |
-
|
| 249 |
-
|
| 250 |
-
|
| 251 |
-
|
| 252 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 253 |
else:
|
| 254 |
-
print("
|
| 255 |
# Fallback to error message
|
| 256 |
pass
|
| 257 |
except Exception as e:
|
|
@@ -279,6 +289,7 @@ def launch_viz(grid_size, vo_points, fps, original_image_state):
|
|
| 279 |
<p style='color: #666; font-size: 12px; margin: 0;'>Backend Available: {BACKEND_AVAILABLE}</p>
|
| 280 |
<p style='color: #666; font-size: 12px; margin: 0;'>Backend API Object: {backend_api is not None}</p>
|
| 281 |
<p style='color: #666; font-size: 12px; margin: 0;'>Backend URL: {BACKEND_SPACE_URL}</p>
|
|
|
|
| 282 |
</div>
|
| 283 |
<p style='color: #2d3436; font-weight: bold; margin-top: 15px;'>
|
| 284 |
Current Status: Backend unavailable - Running in limited mode
|
|
|
|
| 25 |
print(f"🔧 Backend API object type: {type(backend_api)}")
|
| 26 |
print(f"🔧 Backend API object attributes: {dir(backend_api)}")
|
| 27 |
|
| 28 |
+
# Check if it's a Blocks object and has fns
|
| 29 |
+
if hasattr(backend_api, 'fns') and backend_api.fns:
|
| 30 |
+
print(f"🔧 Available functions in fns: {list(backend_api.fns.keys())}")
|
| 31 |
BACKEND_AVAILABLE = True
|
| 32 |
print("✅ Backend connection successful!")
|
| 33 |
+
print("✅ Backend API functions are available")
|
| 34 |
return True
|
| 35 |
else:
|
| 36 |
+
print("❌ Backend API functions 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
|
|
|
|
| 97 |
return None, None, [], 50, 756, 3
|
| 98 |
|
| 99 |
try:
|
| 100 |
+
if BACKEND_AVAILABLE and backend_api and hasattr(backend_api, 'fns'):
|
| 101 |
# Try to use backend API
|
| 102 |
try:
|
| 103 |
+
# Use the Blocks fns to call the function
|
| 104 |
+
if 'process_video_with_points' in backend_api.fns:
|
| 105 |
+
result = backend_api.fns['process_video_with_points'](video, [], 50, 756, 3)
|
| 106 |
+
# Parse the result to extract what we need
|
| 107 |
+
if isinstance(result, dict) and result.get("success"):
|
| 108 |
+
# For now, just extract the first frame locally
|
| 109 |
+
display_image = extract_first_frame(video)
|
| 110 |
+
original_image_state = json.dumps({"video_path": video, "frame": "backend_processing"})
|
| 111 |
+
return original_image_state, display_image, [], 50, 756, 3
|
| 112 |
+
else:
|
| 113 |
+
print("Backend processing failed, using local fallback")
|
| 114 |
+
# Fallback to local processing
|
| 115 |
+
pass
|
| 116 |
else:
|
| 117 |
+
print("process_video_with_points function not found in backend")
|
| 118 |
# Fallback to local processing
|
| 119 |
pass
|
| 120 |
except Exception as e:
|
|
|
|
| 233 |
return None, None
|
| 234 |
|
| 235 |
try:
|
| 236 |
+
if BACKEND_AVAILABLE and backend_api and hasattr(backend_api, 'fns'):
|
| 237 |
# Try to use backend API
|
| 238 |
try:
|
| 239 |
print(f"🔧 Calling backend API with parameters: grid_size={grid_size}, vo_points={vo_points}, fps={fps}")
|
| 240 |
print(f"🔧 Original image state type: {type(original_image_state)}")
|
| 241 |
print(f"🔧 Original image state preview: {str(original_image_state)[:100]}...")
|
| 242 |
|
| 243 |
+
# Use the Blocks fns to call the function
|
| 244 |
+
if 'process_video_with_points' in backend_api.fns:
|
| 245 |
+
# For now, we'll use empty points since we're in local mode
|
| 246 |
+
result = backend_api.fns['process_video_with_points'](
|
| 247 |
+
None, [], grid_size, vo_points, fps
|
| 248 |
+
)
|
| 249 |
+
|
| 250 |
+
print(f"✅ Backend API call successful!")
|
| 251 |
+
print(f"🔧 Result type: {type(result)}")
|
| 252 |
+
print(f"🔧 Result: {result}")
|
| 253 |
+
|
| 254 |
+
# Parse the result
|
| 255 |
+
if isinstance(result, dict) and result.get("success"):
|
| 256 |
+
viz_html = result.get("viz_html_path", "")
|
| 257 |
+
track_video_path = result.get("track_video_path", "")
|
| 258 |
+
return viz_html, track_video_path
|
| 259 |
+
else:
|
| 260 |
+
print("Backend processing failed, showing error message")
|
| 261 |
+
# Fallback to error message
|
| 262 |
+
pass
|
| 263 |
else:
|
| 264 |
+
print("process_video_with_points function not found in backend")
|
| 265 |
# Fallback to error message
|
| 266 |
pass
|
| 267 |
except Exception as e:
|
|
|
|
| 289 |
<p style='color: #666; font-size: 12px; margin: 0;'>Backend Available: {BACKEND_AVAILABLE}</p>
|
| 290 |
<p style='color: #666; font-size: 12px; margin: 0;'>Backend API Object: {backend_api is not None}</p>
|
| 291 |
<p style='color: #666; font-size: 12px; margin: 0;'>Backend URL: {BACKEND_SPACE_URL}</p>
|
| 292 |
+
<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>
|
| 293 |
</div>
|
| 294 |
<p style='color: #2d3436; font-weight: bold; margin-top: 15px;'>
|
| 295 |
Current Status: Backend unavailable - Running in limited mode
|