Last active
November 18, 2025 15:21
-
-
Save aadith-warrier/032d4488c80a9bc27425242a9d08ed4b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| """ | |
| Generic template for building a Rerun + Gradio visualization pipeline. | |
| """ | |
| import gradio as gr | |
| import numpy as np | |
| import uuid | |
| import rerun as rr | |
| from gradio_rerun import Rerun | |
| from rerun.blueprint import Vertical, Horizontal, Spatial2DView, Spatial3DView, Blueprint | |
| def log_sample(recording_id: str, sample_index: int): | |
| item = dataset[sample_index] | |
| rec = rr.RecordingStream(application_id="demo_app", recording_id=recording_id) | |
| stream = rec.binary_stream() | |
| T = num_frames(item) | |
| for t in range(T): | |
| rr.set_time("frame_idx", sequence=t, recording=rec) | |
| sample = extract_frame_data(item, t) | |
| # -- Image --------------------------------------------------------- | |
| if "image" in sample and sample["image"] is not None: | |
| rec.log("image/main", rr.Image(sample["image"])) | |
| # -- Point Cloud --------------------------------------------------- | |
| if "points" in sample: | |
| positions = sample["points"] | |
| colors = sample.get("colors", None) | |
| rec.log( | |
| "points/main", | |
| rr.Points3D( | |
| positions=positions, | |
| colors=colors, | |
| radii=0.1 | |
| ) | |
| ) | |
| # Optional: bounding boxes, segmentation masks, trajectories, etc. | |
| # --------------------------------------------------------------------- | |
| # Viewer Layout | |
| # --------------------------------------------------------------------- | |
| rec.send_blueprint( | |
| Blueprint( | |
| Horizontal( | |
| Vertical( | |
| Spatial2DView(origin="image"), | |
| ), | |
| Spatial3DView(origin="points"), | |
| ), | |
| collapse_panels=True | |
| ) | |
| ) | |
| yield stream.read() | |
| # ------------------------------------------------------------------------- | |
| # Gradio UI | |
| # ------------------------------------------------------------------------- | |
| dataset = load_dataset() | |
| with gr.Blocks() as demo: | |
| recording_id = gr.State(str(uuid.uuid4())) | |
| sample_index = gr.Slider( | |
| 0, | |
| len(dataset) - 1, | |
| step=1, | |
| value=0, | |
| label="Sample Index" | |
| ) | |
| viewer = Rerun(streaming=True, height=800) | |
| sample_index.change( | |
| fn=log_sample, | |
| inputs=[recording_id, sample_index], | |
| outputs=[viewer], | |
| ) | |
| demo.launch() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment