Spaces:
Sleeping
Sleeping
Commit
·
811e580
1
Parent(s):
574e252
Add first version of demo
Browse files- .gitattributes +1 -0
- app.py +37 -18
- colored_sphere.obj +3 -0
- pc_to_mesh.py +61 -0
- scene0435_00_vh_clean_2.ply → scene0435_00.pth +2 -2
.gitattributes
CHANGED
|
@@ -34,3 +34,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
*.ply filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
*.ply filter=lfs diff=lfs merge=lfs -text
|
| 37 |
+
*.obj filter=lfs diff=lfs merge=lfs -text
|
app.py
CHANGED
|
@@ -1,26 +1,45 @@
|
|
| 1 |
import gradio as gr
|
|
|
|
| 2 |
|
| 3 |
-
|
| 4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
-
|
| 7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
|
|
|
|
|
|
|
|
|
|
| 9 |
with gr.Row():
|
| 10 |
-
#
|
| 11 |
-
with gr.Column(
|
| 12 |
-
gr.
|
| 13 |
-
|
| 14 |
-
output = gr.Textbox(label="Greeting")
|
| 15 |
-
greet_btn = gr.Button("Greet")
|
| 16 |
-
greet_btn.click(fn=greet, inputs=name, outputs=output)
|
| 17 |
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
)
|
| 25 |
|
| 26 |
-
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from gradio_litmodel3d import LitModel3D
|
| 3 |
|
| 4 |
+
# Predefined questions
|
| 5 |
+
questions_list = [
|
| 6 |
+
"How many curtains are there over the windows in a room?",
|
| 7 |
+
"What is front of the window and behind the mini fridge?",
|
| 8 |
+
"Name the type of room described by the list of object.",
|
| 9 |
+
"Can I make dinner in this room?"
|
| 10 |
+
]
|
| 11 |
|
| 12 |
+
# Function to generate answer based on selected question
|
| 13 |
+
def get_answer(question):
|
| 14 |
+
answers = {
|
| 15 |
+
"How many curtains are there over the windows in a room?": "2.",
|
| 16 |
+
"What is front of the window and behind the mini fridge?": "Curtains.",
|
| 17 |
+
"Name the type of room described by the list of object.": "Hotel room.",
|
| 18 |
+
"Can I make dinner in this room?": "No."
|
| 19 |
+
}
|
| 20 |
+
return answers.get(question, "")
|
| 21 |
|
| 22 |
+
with gr.Blocks(title="3DGraphLLM Q&A Demo") as demo:
|
| 23 |
+
gr.Markdown("# 3DGraphLLM Q&A Demo") # H1 heading
|
| 24 |
+
gr.Markdown("Select a question to see the corresponding answer.") # Optional subtitle/description
|
| 25 |
with gr.Row():
|
| 26 |
+
# Left block: Questions and Answers
|
| 27 |
+
with gr.Column():
|
| 28 |
+
question_dropdown = gr.Dropdown(label="Questions", choices=questions_list)
|
| 29 |
+
answer_box = gr.Textbox(label="Answer", interactive=False)
|
|
|
|
|
|
|
|
|
|
| 30 |
|
| 31 |
+
# Update answer when question is selected
|
| 32 |
+
question_dropdown.change(fn=get_answer, inputs=question_dropdown, outputs=answer_box)
|
| 33 |
+
|
| 34 |
+
# Right block: 3D model viewer
|
| 35 |
+
with gr.Column():
|
| 36 |
+
model3d = LitModel3D(
|
| 37 |
+
value="colored_sphere.obj",
|
| 38 |
+
interactive=False,
|
| 39 |
+
exposure=4.0,
|
| 40 |
+
contrast=1,
|
| 41 |
+
camera_position=(90, 90, 7)
|
| 42 |
)
|
| 43 |
|
| 44 |
+
if __name__ == "__main__":
|
| 45 |
+
demo.launch()
|
colored_sphere.obj
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:af0623db05615dfdab7a8b430a9a9d280cb04494851279f776570e4648e81d2c
|
| 3 |
+
size 124159899
|
pc_to_mesh.py
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import open3d as o3d
|
| 2 |
+
import torch
|
| 3 |
+
import numpy as np
|
| 4 |
+
|
| 5 |
+
pc_points, pc_colors, _, _ = torch.load("scene0435_00.pth", weights_only=False)
|
| 6 |
+
|
| 7 |
+
# Convert points to NumPy array
|
| 8 |
+
points = np.asarray(pc_points)
|
| 9 |
+
|
| 10 |
+
# Define Z range to keep (e.g., remove points with z > 1.0)
|
| 11 |
+
z_min, z_max = -np.inf, 2.1
|
| 12 |
+
mask = (points[:, 2] >= z_min) & (points[:, 2] <= z_max)
|
| 13 |
+
|
| 14 |
+
pcd = o3d.geometry.PointCloud()
|
| 15 |
+
pcd.points = o3d.utility.Vector3dVector(pc_points[mask])
|
| 16 |
+
pcd.colors = o3d.utility.Vector3dVector(pc_colors[mask] / 255)
|
| 17 |
+
|
| 18 |
+
# Angle in radians
|
| 19 |
+
theta = np.pi / 2
|
| 20 |
+
|
| 21 |
+
# Rotation matrix around Z-axis
|
| 22 |
+
R = np.array([
|
| 23 |
+
[np.cos(theta), -np.sin(theta), 0],
|
| 24 |
+
[np.sin(theta), np.cos(theta), 0],
|
| 25 |
+
[0, 0, 1]
|
| 26 |
+
])
|
| 27 |
+
|
| 28 |
+
pcd.rotate(R, center=(0, 0, 0))
|
| 29 |
+
|
| 30 |
+
# --- Create a sample mesh ---
|
| 31 |
+
# Estimate normals (required)
|
| 32 |
+
pcd.estimate_normals(search_param=o3d.geometry.KDTreeSearchParamHybrid(
|
| 33 |
+
radius=0.01, max_nn=2
|
| 34 |
+
))
|
| 35 |
+
|
| 36 |
+
# Poisson reconstruction
|
| 37 |
+
mesh, densities = o3d.geometry.TriangleMesh.create_from_point_cloud_poisson(
|
| 38 |
+
pcd, depth=10
|
| 39 |
+
)
|
| 40 |
+
|
| 41 |
+
# Optional: crop mesh to original bounds
|
| 42 |
+
bbox = pcd.get_axis_aligned_bounding_box()
|
| 43 |
+
|
| 44 |
+
mesh = mesh.crop(bbox)
|
| 45 |
+
|
| 46 |
+
# colors = np.asarray(mesh.vertex_colors) # Nx3 array, values in [0,1]
|
| 47 |
+
# factor = 2 # >1 to lighten, <1 to darken
|
| 48 |
+
# colors = np.clip(colors * factor, 0, 1) # keep in [0,1]
|
| 49 |
+
|
| 50 |
+
# # Stretch each channel to [0,1]
|
| 51 |
+
# min_val = colors.min(axis=0)
|
| 52 |
+
# max_val = np.quantile(colors, q=0.95, axis=0)
|
| 53 |
+
# print(min_val, max_val)
|
| 54 |
+
# colors = (colors - min_val) / (max_val - min_val + 1e-8)
|
| 55 |
+
# mesh.vertex_colors = o3d.utility.Vector3dVector(colors)
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
# --- Save mesh as .obj with per-vertex colors ---
|
| 59 |
+
o3d.io.write_triangle_mesh("colored_sphere.obj", mesh, write_vertex_colors=True)
|
| 60 |
+
|
| 61 |
+
print("Saved colored OBJ: colored_sphere.obj")
|
scene0435_00_vh_clean_2.ply → scene0435_00.pth
RENAMED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:75ec2bd156032cf2e79525a6cd619421193c955d52a95e372406adf95485a2b4
|
| 3 |
+
size 8757881
|