Commit
·
5aea41f
1
Parent(s):
3403b3b
EXACT reference structure: plots-wrap Column + Row loop + plot-html elem_classes
Browse files
app.py
CHANGED
|
@@ -7,7 +7,20 @@ import plotly.io as pio
|
|
| 7 |
DATA_DIR = Path(__file__).parent / "data"
|
| 8 |
video_path = DATA_DIR / "video.mp4"
|
| 9 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
CUSTOM_CSS = """
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
.plot-html {
|
| 12 |
background: #111a2c;
|
| 13 |
border-radius: 12px;
|
|
@@ -28,13 +41,13 @@ def load_data():
|
|
| 28 |
try:
|
| 29 |
with open(DATA_DIR / "metadata.json", 'r') as f:
|
| 30 |
metadata = json.load(f)
|
| 31 |
-
except
|
| 32 |
-
|
| 33 |
try:
|
| 34 |
with open(DATA_DIR / "end_effector.json", 'r') as f:
|
| 35 |
end_effector = json.load(f)
|
| 36 |
-
except
|
| 37 |
-
|
| 38 |
return metadata, end_effector
|
| 39 |
|
| 40 |
def build_plot_html(metadata, end_effector, hand, metric):
|
|
@@ -103,33 +116,11 @@ metadata, end_effector = load_data()
|
|
| 103 |
total_frames = len(metadata.get('poses', []))
|
| 104 |
fps = metadata.get('fps', 60)
|
| 105 |
|
| 106 |
-
# Build plots
|
| 107 |
-
left_figs = {
|
| 108 |
-
|
| 109 |
-
"y_cm": build_plot_html(metadata, end_effector, "left", "y_cm"),
|
| 110 |
-
"z_cm": build_plot_html(metadata, end_effector, "left", "z_cm"),
|
| 111 |
-
"roll_deg": build_plot_html(metadata, end_effector, "left", "roll_deg"),
|
| 112 |
-
"pitch_deg": build_plot_html(metadata, end_effector, "left", "pitch_deg"),
|
| 113 |
-
"yaw_deg": build_plot_html(metadata, end_effector, "left", "yaw_deg"),
|
| 114 |
-
}
|
| 115 |
-
|
| 116 |
-
right_figs = {
|
| 117 |
-
"x_cm": build_plot_html(metadata, end_effector, "right", "x_cm"),
|
| 118 |
-
"y_cm": build_plot_html(metadata, end_effector, "right", "y_cm"),
|
| 119 |
-
"z_cm": build_plot_html(metadata, end_effector, "right", "z_cm"),
|
| 120 |
-
"roll_deg": build_plot_html(metadata, end_effector, "right", "roll_deg"),
|
| 121 |
-
"pitch_deg": build_plot_html(metadata, end_effector, "right", "pitch_deg"),
|
| 122 |
-
"yaw_deg": build_plot_html(metadata, end_effector, "right", "yaw_deg"),
|
| 123 |
-
}
|
| 124 |
|
| 125 |
-
theme = gr.themes.Soft(
|
| 126 |
-
primary_hue="cyan", secondary_hue="blue", neutral_hue="slate"
|
| 127 |
-
).set(
|
| 128 |
-
body_background_fill="#0c1424",
|
| 129 |
-
body_text_color="#f8fafc",
|
| 130 |
-
block_background_fill="#111a2c",
|
| 131 |
-
border_color_primary="#1f2b47",
|
| 132 |
-
)
|
| 133 |
|
| 134 |
with gr.Blocks(theme=theme, css=CUSTOM_CSS) as demo:
|
| 135 |
gr.Markdown("# 🤖 Dynamic Intelligence - Human Demo Visualizer")
|
|
@@ -137,27 +128,21 @@ with gr.Blocks(theme=theme, css=CUSTOM_CSS) as demo:
|
|
| 137 |
|
| 138 |
gr.Video(value=str(video_path) if video_path.exists() else None, height=360)
|
| 139 |
|
|
|
|
| 140 |
gr.Markdown("### Left Hand Trajectories")
|
| 141 |
-
with gr.Column():
|
| 142 |
-
|
| 143 |
-
gr.
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
with gr.Row():
|
| 147 |
-
gr.HTML(value=left_figs["roll_deg"], elem_classes=["plot-html"])
|
| 148 |
-
gr.HTML(value=left_figs["pitch_deg"], elem_classes=["plot-html"])
|
| 149 |
-
gr.HTML(value=left_figs["yaw_deg"], elem_classes=["plot-html"])
|
| 150 |
|
|
|
|
| 151 |
gr.Markdown("### Right Hand Trajectories")
|
| 152 |
-
with gr.Column():
|
| 153 |
-
|
| 154 |
-
gr.
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
with gr.Row():
|
| 158 |
-
gr.HTML(value=right_figs["roll_deg"], elem_classes=["plot-html"])
|
| 159 |
-
gr.HTML(value=right_figs["pitch_deg"], elem_classes=["plot-html"])
|
| 160 |
-
gr.HTML(value=right_figs["yaw_deg"], elem_classes=["plot-html"])
|
| 161 |
|
| 162 |
if __name__ == "__main__":
|
| 163 |
demo.launch()
|
|
|
|
| 7 |
DATA_DIR = Path(__file__).parent / "data"
|
| 8 |
video_path = DATA_DIR / "video.mp4"
|
| 9 |
|
| 10 |
+
PLOT_GRID = [
|
| 11 |
+
["x_cm", "y_cm", "z_cm"],
|
| 12 |
+
["yaw_deg", "pitch_deg", "roll_deg"],
|
| 13 |
+
]
|
| 14 |
+
|
| 15 |
+
PLOT_ORDER = [metric for row in PLOT_GRID for metric in row]
|
| 16 |
+
|
| 17 |
CUSTOM_CSS = """
|
| 18 |
+
.plots-wrap {
|
| 19 |
+
margin-top: 18px;
|
| 20 |
+
}
|
| 21 |
+
.plots-wrap .gr-row {
|
| 22 |
+
gap: 16px;
|
| 23 |
+
}
|
| 24 |
.plot-html {
|
| 25 |
background: #111a2c;
|
| 26 |
border-radius: 12px;
|
|
|
|
| 41 |
try:
|
| 42 |
with open(DATA_DIR / "metadata.json", 'r') as f:
|
| 43 |
metadata = json.load(f)
|
| 44 |
+
except:
|
| 45 |
+
pass
|
| 46 |
try:
|
| 47 |
with open(DATA_DIR / "end_effector.json", 'r') as f:
|
| 48 |
end_effector = json.load(f)
|
| 49 |
+
except:
|
| 50 |
+
pass
|
| 51 |
return metadata, end_effector
|
| 52 |
|
| 53 |
def build_plot_html(metadata, end_effector, hand, metric):
|
|
|
|
| 116 |
total_frames = len(metadata.get('poses', []))
|
| 117 |
fps = metadata.get('fps', 60)
|
| 118 |
|
| 119 |
+
# Build plots - EXACTLY like reference app
|
| 120 |
+
left_figs = {metric: build_plot_html(metadata, end_effector, "left", metric) for metric in PLOT_ORDER}
|
| 121 |
+
right_figs = {metric: build_plot_html(metadata, end_effector, "right", metric) for metric in PLOT_ORDER}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 122 |
|
| 123 |
+
theme = gr.themes.Soft(primary_hue="cyan", secondary_hue="blue", neutral_hue="slate")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 124 |
|
| 125 |
with gr.Blocks(theme=theme, css=CUSTOM_CSS) as demo:
|
| 126 |
gr.Markdown("# 🤖 Dynamic Intelligence - Human Demo Visualizer")
|
|
|
|
| 128 |
|
| 129 |
gr.Video(value=str(video_path) if video_path.exists() else None, height=360)
|
| 130 |
|
| 131 |
+
# Left hand - EXACT structure from reference
|
| 132 |
gr.Markdown("### Left Hand Trajectories")
|
| 133 |
+
with gr.Column(elem_classes=["plots-wrap"]):
|
| 134 |
+
for row in PLOT_GRID:
|
| 135 |
+
with gr.Row():
|
| 136 |
+
for metric in row:
|
| 137 |
+
gr.HTML(value=left_figs[metric], elem_classes=["plot-html"])
|
|
|
|
|
|
|
|
|
|
|
|
|
| 138 |
|
| 139 |
+
# Right hand - EXACT structure from reference
|
| 140 |
gr.Markdown("### Right Hand Trajectories")
|
| 141 |
+
with gr.Column(elem_classes=["plots-wrap"]):
|
| 142 |
+
for row in PLOT_GRID:
|
| 143 |
+
with gr.Row():
|
| 144 |
+
for metric in row:
|
| 145 |
+
gr.HTML(value=right_figs[metric], elem_classes=["plot-html"])
|
|
|
|
|
|
|
|
|
|
|
|
|
| 146 |
|
| 147 |
if __name__ == "__main__":
|
| 148 |
demo.launch()
|