Breeze1124 commited on
Commit
ca4318a
·
1 Parent(s): f638021
Files changed (2) hide show
  1. app.py +28 -22
  2. requirements.txt +1 -1
app.py CHANGED
@@ -2,64 +2,65 @@ import gradio as gr
2
  import os
3
 
4
  # --- Configuration ---
 
 
5
  SCENES = [
6
  {
7
  "name": "Office 0",
8
- "thumb": "assets/office0.PNG",
9
- "model": "assets_converted/office0_converted.ply",
10
  "tracking_img": "assets/office0_tracking.PNG"
11
  },
12
  {
13
  "name": "Office 2",
14
  "thumb": "assets/office2.PNG",
15
- "model": "assets_converted/office2_converted.ply",
16
  "tracking_img": "assets/office2_tracking.PNG"
17
  },
18
  {
19
  "name": "Room 0",
20
  "thumb": "assets/room0.PNG",
21
- "model": "assets_converted/room0_converted.ply",
22
  "tracking_img": "assets/room0_tracking.PNG"
23
  }
24
  ]
25
 
 
26
  gallery_items = [(item["thumb"], item["name"]) for item in SCENES]
27
 
28
  def load_scene(evt: gr.SelectData):
 
 
 
 
29
  index = evt.index
30
  scene = SCENES[index]
31
 
32
- # 除錯資訊:檢查檔案是否存在
33
  if not os.path.exists(scene["model"]):
34
- print(f"❌ File not found: {scene['model']}")
35
  return (
36
  None,
37
- scene["tracking_img"],
38
- f"**Error: Model file missing on server!**\nPath: `{scene['model']}`"
39
  )
40
 
 
41
  file_size = os.path.getsize(scene["model"]) / (1024 * 1024)
42
- print(f"📂 Loading: {scene['model']} ({file_size:.2f} MB)")
43
 
44
- # 警告:如果檔案還是太大 (>100MB),CPU Basic 載入還是會慢
45
- if file_size > 100:
46
- msg = f"**{scene['name']}** ({file_size:.1f} MB)\n⚠️ File is large, please wait..."
47
- else:
48
- msg = f"**{scene['name']}** ({file_size:.1f} MB) ✓ Loaded"
49
-
50
  return (
51
  scene["model"],
52
  scene["tracking_img"],
53
- msg
54
  )
55
 
56
  # --- UI ---
57
  with gr.Blocks(title="RGS-SLAM Demo") as demo:
58
 
59
  gr.Markdown("# 🚀 RGS-SLAM Gaussian Splatting Viewer")
60
- gr.Markdown("Using CPU-Basic. Models converted to Binary PLY.")
61
 
62
  with gr.Row():
 
63
  with gr.Column(scale=1):
64
  gr.Markdown("### 📂 Select Scene")
65
  scene_gallery = gr.Gallery(
@@ -67,22 +68,27 @@ with gr.Blocks(title="RGS-SLAM Demo") as demo:
67
  label="Available Scenes",
68
  columns=1,
69
  height=400,
70
- object_fit="contain"
 
71
  )
72
 
 
73
  with gr.Column(scale=3):
74
- status = gr.Markdown("**👈 Select a scene to load**")
75
 
76
  with gr.Tab("🎯 3D Reconstruction"):
 
77
  model_viewer = gr.Model3D(
78
- label="3D Model",
79
- clear_color=[0.1, 0.1, 0.1, 1.0],
80
- height=600
 
81
  )
82
 
83
  with gr.Tab("📍 Camera Trajectory"):
84
  trajectory_img = gr.Image(label="Camera Path", height=600)
85
 
 
86
  scene_gallery.select(
87
  fn=load_scene,
88
  outputs=[model_viewer, trajectory_img, status]
 
2
  import os
3
 
4
  # --- Configuration ---
5
+ # 假設你的 .splat 檔案已經放在 "assets_converted" 資料夾中
6
+ # 建議將檔案命名為 office0.splat, office2.splat, room0.splat 以保持簡潔
7
  SCENES = [
8
  {
9
  "name": "Office 0",
10
+ "thumb": "assets/office0.PNG",
11
+ "model": "assets/office0.splat", # <--- 修改處:改成 .splat 檔案
12
  "tracking_img": "assets/office0_tracking.PNG"
13
  },
14
  {
15
  "name": "Office 2",
16
  "thumb": "assets/office2.PNG",
17
+ "model": "assets/office2.splat", # <--- 修改處
18
  "tracking_img": "assets/office2_tracking.PNG"
19
  },
20
  {
21
  "name": "Room 0",
22
  "thumb": "assets/room0.PNG",
23
+ "model": "assets/room0.splat", # <--- 修改處
24
  "tracking_img": "assets/room0_tracking.PNG"
25
  }
26
  ]
27
 
28
+ # 建立 Gallery 用清單
29
  gallery_items = [(item["thumb"], item["name"]) for item in SCENES]
30
 
31
  def load_scene(evt: gr.SelectData):
32
+ """
33
+ 載入選定的場景。
34
+ Gradio 的 Model3D 元件會根據副檔名 (.splat) 自動切換渲染模式。
35
+ """
36
  index = evt.index
37
  scene = SCENES[index]
38
 
39
+ # 檢查檔案是否存在,避免報錯讓使用者困惑
40
  if not os.path.exists(scene["model"]):
 
41
  return (
42
  None,
43
+ scene["tracking_img"] if os.path.exists(scene["tracking_img"]) else None,
44
+ f"**⚠️ Error: File not found: {scene['model']}**\n請確認 .splat 檔案已上傳至正確路徑。"
45
  )
46
 
47
+ # 計算檔案大小供顯示
48
  file_size = os.path.getsize(scene["model"]) / (1024 * 1024)
 
49
 
 
 
 
 
 
 
50
  return (
51
  scene["model"],
52
  scene["tracking_img"],
53
+ f"**{scene['name']}** ({file_size:.1f} MB) ✓ Loaded (.splat)"
54
  )
55
 
56
  # --- UI ---
57
  with gr.Blocks(title="RGS-SLAM Demo") as demo:
58
 
59
  gr.Markdown("# 🚀 RGS-SLAM Gaussian Splatting Viewer")
60
+ gr.Markdown("此檢視器使用 `.splat` 格式,載入速度更快且相容性更高。")
61
 
62
  with gr.Row():
63
+ # 左側選單
64
  with gr.Column(scale=1):
65
  gr.Markdown("### 📂 Select Scene")
66
  scene_gallery = gr.Gallery(
 
68
  label="Available Scenes",
69
  columns=1,
70
  height=400,
71
+ object_fit="contain",
72
+ allow_preview=False # 關閉點擊預覽圖片,強制觸發選擇事件
73
  )
74
 
75
+ # 右側顯示區
76
  with gr.Column(scale=3):
77
+ status = gr.Markdown("**👈 Select a scene from the left to load**")
78
 
79
  with gr.Tab("🎯 3D Reconstruction"):
80
+ # Model3D 支援 .splat, .ply, .glb 等格式
81
  model_viewer = gr.Model3D(
82
+ label="3D Gaussian Splat",
83
+ clear_color=[0.0, 0.0, 0.0, 1.0], # 建議 splat 使用黑色背景
84
+ height=600,
85
+ interactive=True
86
  )
87
 
88
  with gr.Tab("📍 Camera Trajectory"):
89
  trajectory_img = gr.Image(label="Camera Path", height=600)
90
 
91
+ # 事件綁定
92
  scene_gallery.select(
93
  fn=load_scene,
94
  outputs=[model_viewer, trajectory_img, status]
requirements.txt CHANGED
@@ -1,4 +1,4 @@
1
- gradio>=4.0.0
2
  trimesh
3
  plotly
4
  numpy
 
1
+ gradio>=4.16.0
2
  trimesh
3
  plotly
4
  numpy