Raffael-Kultyshev commited on
Commit
26c9f29
·
1 Parent(s): b6b74d1

Revert to minimal working version

Browse files
Files changed (1) hide show
  1. app.py +11 -172
app.py CHANGED
@@ -1,177 +1,16 @@
1
- import json
2
- import html
3
- from pathlib import Path
4
- from typing import Dict, List
5
-
6
  import gradio as gr
7
- import plotly.graph_objects as go
8
- import plotly.io as pio
9
-
10
- METRIC_LABELS = {
11
- "x_cm": "X (cm)",
12
- "y_cm": "Y (cm)",
13
- "z_cm": "Z (cm)",
14
- "yaw_deg": "Yaw (°)",
15
- "pitch_deg": "Pitch (°)",
16
- "roll_deg": "Roll (°)",
17
- }
18
-
19
- PLOT_GRID = [
20
- ["x_cm", "y_cm", "z_cm"],
21
- ["yaw_deg", "pitch_deg", "roll_deg"],
22
- ]
23
-
24
- def get_data_dir():
25
- try:
26
- return Path(__file__).parent / "data"
27
- except:
28
- return Path("data")
29
-
30
- def load_data():
31
- data_dir = get_data_dir()
32
- metadata = {}
33
- end_effector = {}
34
- hands_2d = {}
35
-
36
- try:
37
- metadata_path = data_dir / "metadata.json"
38
- if metadata_path.exists():
39
- with open(metadata_path, 'r') as f:
40
- metadata = json.load(f)
41
- except:
42
- pass
43
-
44
- try:
45
- end_effector_path = data_dir / "end_effector.json"
46
- if end_effector_path.exists():
47
- with open(end_effector_path, 'r') as f:
48
- end_effector = json.load(f)
49
- except:
50
- pass
51
-
52
- try:
53
- hands_2d_path = data_dir / "hands_2d.json"
54
- if hands_2d_path.exists():
55
- with open(hands_2d_path, 'r') as f:
56
- hands_2d = json.load(f)
57
- except:
58
- pass
59
-
60
- return metadata, end_effector, hands_2d
61
 
62
- def build_state_dataframe(metadata: dict, end_effector: dict, hand: str = "left"):
63
- fps = metadata.get('fps', 60)
64
- frame_keys = sorted([int(k) for k in end_effector.keys() if str(k).isdigit()])
65
-
66
- timestamps = []
67
- state_data = {
68
- 'wrist_x_cm': [],
69
- 'wrist_y_cm': [],
70
- 'wrist_z_cm': [],
71
- 'wrist_yaw_deg': [],
72
- 'wrist_pitch_deg': [],
73
- 'wrist_roll_deg': [],
74
- }
75
-
76
- for frame_idx in frame_keys:
77
- frame_key = str(frame_idx)
78
- t = frame_idx / fps
79
- timestamps.append(t)
80
-
81
- ee_data = end_effector.get(frame_key, {}) or {}
82
- hand_data = ee_data.get(hand + "_hand")
83
-
84
- if hand_data and isinstance(hand_data, dict):
85
- pose = hand_data.get('pose_6dof')
86
- if pose and len(pose) >= 6:
87
- state_data['wrist_x_cm'].append(pose[0] * 100)
88
- state_data['wrist_y_cm'].append(pose[1] * 100)
89
- state_data['wrist_z_cm'].append(pose[2] * 100)
90
- state_data['wrist_roll_deg'].append(pose[3] * 57.3)
91
- state_data['wrist_pitch_deg'].append(pose[4] * 57.3)
92
- state_data['wrist_yaw_deg'].append(pose[5] * 57.3)
93
- else:
94
- for k in state_data:
95
- state_data[k].append(None)
96
- else:
97
- for k in state_data:
98
- state_data[k].append(None)
99
-
100
- return timestamps, state_data
101
 
102
- def build_plot_html(timestamps: List[float], state_data: Dict, metric: str) -> str:
103
- col_name = f"wrist_{metric}"
104
- if col_name not in state_data or not timestamps:
105
- return "<p>No data</p>"
106
-
107
- fig = go.Figure()
108
- fig.add_trace(go.Scatter(x=timestamps, y=state_data[col_name], mode="lines", name="Wrist"))
109
- fig.update_layout(
110
- margin=dict(l=20, r=20, t=30, b=20),
111
- height=250,
112
- template="plotly_dark",
113
- xaxis_title="Time (s)",
114
- yaxis_title=METRIC_LABELS[metric],
115
- )
116
- return pio.to_html(fig, include_plotlyjs="cdn", full_html=False)
117
 
118
- def build_interface():
119
- metadata, end_effector, hands_2d = load_data()
120
-
121
- total_frames = len(metadata.get('poses', []))
122
- fps = metadata.get('fps', 60)
123
- hand_detection_rate = len(hands_2d) / max(1, total_frames) * 100 if total_frames > 0 else 0
124
- left_poses = sum(1 for f in end_effector.values() if f and isinstance(f, dict) and f.get('left_hand'))
125
- right_poses = sum(1 for f in end_effector.values() if f and isinstance(f, dict) and f.get('right_hand'))
126
-
127
- video_path = get_data_dir() / "video.mp4"
128
-
129
- left_timestamps, left_state = build_state_dataframe(metadata, end_effector, "left")
130
- right_timestamps, right_state = build_state_dataframe(metadata, end_effector, "right")
131
-
132
- left_figs = {metric: build_plot_html(left_timestamps, left_state, metric) for metric in METRIC_LABELS.keys()}
133
- right_figs = {metric: build_plot_html(right_timestamps, right_state, metric) for metric in METRIC_LABELS.keys()}
134
-
135
- stats_html = f"""
136
- <div style="background: #0f172a; padding: 20px; border-radius: 18px;">
137
- <ul style="list-style: none; padding: 0;">
138
- <li><span style="color: #7dd3fc;">Frames:</span> {total_frames:,}</li>
139
- <li><span style="color: #7dd3fc;">Detection rate:</span> {hand_detection_rate:.1f}%</li>
140
- <li><span style="color: #7dd3fc;">Left poses:</span> {left_poses}</li>
141
- <li><span style="color: #7dd3fc;">Right poses:</span> {right_poses}</li>
142
- <li><span style="color: #7dd3fc;">FPS:</span> {fps:.1f}</li>
143
- </ul>
144
- </div>
145
- """
146
-
147
- theme = gr.themes.Soft(primary_hue="cyan", secondary_hue="blue", neutral_hue="slate")
148
-
149
- with gr.Blocks(theme=theme) as demo:
150
- gr.Markdown("# 🤖 Dynamic Intelligence - Human Demo Visualizer")
151
- gr.Markdown("Egocentric hand tracking dataset for humanoid robot training.")
152
-
153
- with gr.Row():
154
- with gr.Column(scale=1):
155
- gr.HTML(stats_html)
156
- with gr.Column(scale=2):
157
- video = gr.Video(value=str(video_path) if video_path.exists() else None, height=360)
158
-
159
- gr.Markdown("### Left Hand Trajectories")
160
- with gr.Row():
161
- for metric in ["x_cm", "y_cm", "z_cm"]:
162
- gr.HTML(value=left_figs[metric])
163
- with gr.Row():
164
- for metric in ["yaw_deg", "pitch_deg", "roll_deg"]:
165
- gr.HTML(value=left_figs[metric])
166
-
167
- gr.Markdown("### Right Hand Trajectories")
168
- with gr.Row():
169
- for metric in ["x_cm", "y_cm", "z_cm"]:
170
- gr.HTML(value=right_figs[metric])
171
- with gr.Row():
172
- for metric in ["yaw_deg", "pitch_deg", "roll_deg"]:
173
- gr.HTML(value=right_figs[metric])
174
-
175
- return demo
176
 
177
- demo = build_interface()
 
1
+ """
2
+ Minimal test version
3
+ """
 
 
4
  import gradio as gr
5
+ from pathlib import Path
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
 
7
+ DATA_DIR = Path(__file__).parent / "data"
8
+ video_path = DATA_DIR / "video.mp4"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
 
10
+ with gr.Blocks() as demo:
11
+ gr.Markdown("# Test")
12
+ gr.Video(value=str(video_path) if video_path.exists() else None)
 
 
 
 
 
 
 
 
 
 
 
 
13
 
14
+ if __name__ == "__main__":
15
+ demo.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16