Spaces:
Running
on
Zero
Running
on
Zero
xiaoyuxi
commited on
Commit
·
351d58b
1
Parent(s):
cf6e100
backend
Browse files
app.py
CHANGED
|
@@ -533,8 +533,8 @@ def launch_viz(grid_size, vo_points, fps, original_image_state):
|
|
| 533 |
track_video_content = result.get("track_video_content", None)
|
| 534 |
track_video_filename = result.get("track_video_filename", "tracked_video.mp4")
|
| 535 |
|
| 536 |
-
# ✅
|
| 537 |
-
#
|
| 538 |
print(f"✅ Received HTML content from backend (length: {len(viz_html)})")
|
| 539 |
|
| 540 |
# 🔧 Debug: 检查HTML内容是否包含关键元素
|
|
@@ -552,10 +552,40 @@ def launch_viz(grid_size, vo_points, fps, original_image_state):
|
|
| 552 |
print("⚠️ Warning: HTML doesn't contain embedded base64 data!")
|
| 553 |
if not has_canvas:
|
| 554 |
print("⚠️ Warning: HTML doesn't contain canvas element!")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 555 |
else:
|
| 556 |
print("❌ Warning: Empty HTML content received from backend!")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 557 |
|
| 558 |
# If we have base64 encoded video content, save it as a temporary file
|
|
|
|
| 559 |
if track_video_content:
|
| 560 |
try:
|
| 561 |
# Create a temporary file for the video
|
|
@@ -574,17 +604,14 @@ def launch_viz(grid_size, vo_points, fps, original_image_state):
|
|
| 574 |
print(f"✅ Successfully saved tracking video to: {local_video_path}")
|
| 575 |
print(f"🔧 Video file size: {len(video_bytes)} bytes")
|
| 576 |
|
| 577 |
-
# Use the local video path for display
|
| 578 |
-
return viz_html, local_video_path
|
| 579 |
-
|
| 580 |
except Exception as e:
|
| 581 |
print(f"❌ Failed to process tracking video: {e}")
|
| 582 |
-
|
| 583 |
-
return viz_html, None
|
| 584 |
else:
|
| 585 |
-
# No video content, return HTML only
|
| 586 |
print("⚠️ No tracking video content received from backend")
|
| 587 |
-
|
|
|
|
|
|
|
| 588 |
else:
|
| 589 |
error_msg = result.get("error", "Unknown error") if isinstance(result, dict) else "Backend processing failed"
|
| 590 |
print(f"❌ Backend processing failed: {error_msg}")
|
|
|
|
| 533 |
track_video_content = result.get("track_video_content", None)
|
| 534 |
track_video_filename = result.get("track_video_filename", "tracked_video.mp4")
|
| 535 |
|
| 536 |
+
# ✅ 关键修复:Backend返回的是完整HTML页面,需要保存为文件并用iframe显示
|
| 537 |
+
# 不能直接返回HTML内容,否则会覆盖整个Frontend页面
|
| 538 |
print(f"✅ Received HTML content from backend (length: {len(viz_html)})")
|
| 539 |
|
| 540 |
# 🔧 Debug: 检查HTML内容是否包含关键元素
|
|
|
|
| 552 |
print("⚠️ Warning: HTML doesn't contain embedded base64 data!")
|
| 553 |
if not has_canvas:
|
| 554 |
print("⚠️ Warning: HTML doesn't contain canvas element!")
|
| 555 |
+
|
| 556 |
+
# 💾 保存HTML到临时文件
|
| 557 |
+
temp_viz_dir = "temp_frontend_viz"
|
| 558 |
+
os.makedirs(temp_viz_dir, exist_ok=True)
|
| 559 |
+
|
| 560 |
+
# 生成唯一文件名
|
| 561 |
+
timestamp = str(int(time.time() * 1000))
|
| 562 |
+
html_filename = f"viz_{timestamp}.html"
|
| 563 |
+
html_path = os.path.join(temp_viz_dir, html_filename)
|
| 564 |
+
|
| 565 |
+
# 保存HTML文件
|
| 566 |
+
with open(html_path, 'w', encoding='utf-8') as f:
|
| 567 |
+
f.write(viz_html)
|
| 568 |
+
|
| 569 |
+
print(f"✅ Saved HTML visualization to: {html_path}")
|
| 570 |
+
|
| 571 |
+
# 🖼️ 创建iframe HTML来显示保存的文件
|
| 572 |
+
iframe_html = f"""
|
| 573 |
+
<div style='border: 3px solid #667eea; border-radius: 10px; overflow: hidden; box-shadow: 0 8px 32px rgba(102, 126, 234, 0.3);'>
|
| 574 |
+
<iframe id="viz_iframe" src="/gradio_api/file={html_path}" width="100%" height="950px" style="border:none;"></iframe>
|
| 575 |
+
</div>
|
| 576 |
+
"""
|
| 577 |
+
|
| 578 |
else:
|
| 579 |
print("❌ Warning: Empty HTML content received from backend!")
|
| 580 |
+
iframe_html = """
|
| 581 |
+
<div style='border: 3px solid #ff6b6b; border-radius: 10px; padding: 20px; background-color: #fff5f5; text-align: center;'>
|
| 582 |
+
<h3 style='color: #d63031;'>❌ Empty Visualization Data</h3>
|
| 583 |
+
<p style='color: #2d3436;'>Backend returned empty HTML content.</p>
|
| 584 |
+
</div>
|
| 585 |
+
"""
|
| 586 |
|
| 587 |
# If we have base64 encoded video content, save it as a temporary file
|
| 588 |
+
local_video_path = None
|
| 589 |
if track_video_content:
|
| 590 |
try:
|
| 591 |
# Create a temporary file for the video
|
|
|
|
| 604 |
print(f"✅ Successfully saved tracking video to: {local_video_path}")
|
| 605 |
print(f"🔧 Video file size: {len(video_bytes)} bytes")
|
| 606 |
|
|
|
|
|
|
|
|
|
|
| 607 |
except Exception as e:
|
| 608 |
print(f"❌ Failed to process tracking video: {e}")
|
| 609 |
+
local_video_path = None
|
|
|
|
| 610 |
else:
|
|
|
|
| 611 |
print("⚠️ No tracking video content received from backend")
|
| 612 |
+
|
| 613 |
+
# 返回iframe HTML和视频路径
|
| 614 |
+
return iframe_html, local_video_path
|
| 615 |
else:
|
| 616 |
error_msg = result.get("error", "Unknown error") if isinstance(result, dict) else "Backend processing failed"
|
| 617 |
print(f"❌ Backend processing failed: {error_msg}")
|