Spaces:
Running
on
Zero
Running
on
Zero
show instruction in simulation dropdown
Browse files- app.py +10 -3
- data/loader.py +24 -4
- visualization/logger.py +4 -10
app.py
CHANGED
@@ -5,8 +5,13 @@ from visualization.visualizer import visualize_simulation
|
|
5 |
|
6 |
|
7 |
def update_simulation_dropdown(file):
|
8 |
-
|
9 |
-
return gr.Dropdown(
|
|
|
|
|
|
|
|
|
|
|
10 |
|
11 |
|
12 |
def create_app():
|
@@ -24,7 +29,9 @@ def create_app():
|
|
24 |
simulation_dropdown = gr.Dropdown(
|
25 |
label="Select Simulation",
|
26 |
choices=[],
|
27 |
-
type="index"
|
|
|
|
|
28 |
)
|
29 |
|
30 |
with gr.Row():
|
|
|
5 |
|
6 |
|
7 |
def update_simulation_dropdown(file):
|
8 |
+
simulations, descriptions = load_simulation_data(file)
|
9 |
+
return gr.Dropdown(
|
10 |
+
choices=descriptions if descriptions else [],
|
11 |
+
value=None,
|
12 |
+
allow_custom_value=False,
|
13 |
+
multiline=True
|
14 |
+
)
|
15 |
|
16 |
|
17 |
def create_app():
|
|
|
29 |
simulation_dropdown = gr.Dropdown(
|
30 |
label="Select Simulation",
|
31 |
choices=[],
|
32 |
+
type="index",
|
33 |
+
multiline=True,
|
34 |
+
scale=2
|
35 |
)
|
36 |
|
37 |
with gr.Row():
|
data/loader.py
CHANGED
@@ -2,6 +2,15 @@ import json
|
|
2 |
from typing import Optional, Dict, Any, List, Tuple
|
3 |
|
4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
def load_simulation_data(file) -> Tuple[Optional[List[Dict[str, Any]]], Optional[List[str]]]:
|
6 |
if file is None:
|
7 |
return None, None
|
@@ -10,10 +19,21 @@ def load_simulation_data(file) -> Tuple[Optional[List[Dict[str, Any]]], Optional
|
|
10 |
json_data = json.load(open(file.name))
|
11 |
simulations = json_data['simulations']
|
12 |
|
13 |
-
descriptions = [
|
14 |
-
|
15 |
-
|
16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
|
18 |
return simulations, descriptions
|
19 |
except Exception as e:
|
|
|
2 |
from typing import Optional, Dict, Any, List, Tuple
|
3 |
|
4 |
|
5 |
+
def create_instruction_description(instruction: Dict[str, Any]) -> str:
|
6 |
+
movement = instruction.get('cameraMovement', 'N/A')
|
7 |
+
shot_type = instruction.get('initialShotType', 'N/A')
|
8 |
+
frames = instruction.get('frameCount', 'N/A')
|
9 |
+
subject_idx = instruction.get('subjectIndex', 'N/A')
|
10 |
+
|
11 |
+
return f"{movement} {shot_type} of subject {subject_idx} ({frames} frames)"
|
12 |
+
|
13 |
+
|
14 |
def load_simulation_data(file) -> Tuple[Optional[List[Dict[str, Any]]], Optional[List[str]]]:
|
15 |
if file is None:
|
16 |
return None, None
|
|
|
19 |
json_data = json.load(open(file.name))
|
20 |
simulations = json_data['simulations']
|
21 |
|
22 |
+
descriptions = []
|
23 |
+
for i, sim in enumerate(simulations):
|
24 |
+
header = f"Simulation {i + 1}"
|
25 |
+
|
26 |
+
instruction_texts = []
|
27 |
+
for j, instruction in enumerate(sim['instructions']):
|
28 |
+
inst_desc = create_instruction_description(instruction)
|
29 |
+
instruction_texts.append(f" {j + 1}. {inst_desc}")
|
30 |
+
|
31 |
+
full_description = f"{header}\n" + "\n".join(instruction_texts)
|
32 |
+
|
33 |
+
subject_count = len(sim['subjects'])
|
34 |
+
full_description = f"{full_description}\n ({subject_count} subjects)"
|
35 |
+
|
36 |
+
descriptions.append(full_description)
|
37 |
|
38 |
return simulations, descriptions
|
39 |
except Exception as e:
|
visualization/logger.py
CHANGED
@@ -10,7 +10,7 @@ def create_subject_box(subject: Dict) -> Dict[str, np.ndarray]:
|
|
10 |
|
11 |
return {
|
12 |
'center': position,
|
13 |
-
'half_size': size / 2
|
14 |
}
|
15 |
|
16 |
|
@@ -40,7 +40,6 @@ class SimulationLogger:
|
|
40 |
if not subjects:
|
41 |
return
|
42 |
|
43 |
-
# Prepare batch data for all subjects
|
44 |
centers = []
|
45 |
half_sizes = []
|
46 |
colors = []
|
@@ -51,13 +50,13 @@ class SimulationLogger:
|
|
51 |
box_params = create_subject_box(subject)
|
52 |
centers.append(box_params['center'])
|
53 |
half_sizes.append(box_params['half_size'])
|
54 |
-
colors.append([0.8, 0.2, 0.2, 1.0])
|
55 |
labels.append(subject.get('objectClass', 'Unknown'))
|
56 |
except Exception as e:
|
57 |
print(f"Error creating box parameters: {str(e)}")
|
58 |
continue
|
59 |
|
60 |
-
if centers:
|
61 |
rr.log(
|
62 |
"world/subjects",
|
63 |
rr.Boxes3D(
|
@@ -65,7 +64,7 @@ class SimulationLogger:
|
|
65 |
half_sizes=np.array(half_sizes),
|
66 |
colors=np.array(colors),
|
67 |
labels=labels,
|
68 |
-
fill_mode="solid"
|
69 |
),
|
70 |
timeless=True
|
71 |
)
|
@@ -118,10 +117,5 @@ class SimulationLogger:
|
|
118 |
)
|
119 |
)
|
120 |
|
121 |
-
rr.log(
|
122 |
-
"metadata/current_frame",
|
123 |
-
rr.TextDocument(
|
124 |
-
f"Frame: {frame_idx + 1}/{len(camera_frames)}"),
|
125 |
-
)
|
126 |
except Exception as e:
|
127 |
print(f"Error logging camera frame {frame_idx}: {str(e)}")
|
|
|
10 |
|
11 |
return {
|
12 |
'center': position,
|
13 |
+
'half_size': size / 2
|
14 |
}
|
15 |
|
16 |
|
|
|
40 |
if not subjects:
|
41 |
return
|
42 |
|
|
|
43 |
centers = []
|
44 |
half_sizes = []
|
45 |
colors = []
|
|
|
50 |
box_params = create_subject_box(subject)
|
51 |
centers.append(box_params['center'])
|
52 |
half_sizes.append(box_params['half_size'])
|
53 |
+
colors.append([0.8, 0.2, 0.2, 1.0])
|
54 |
labels.append(subject.get('objectClass', 'Unknown'))
|
55 |
except Exception as e:
|
56 |
print(f"Error creating box parameters: {str(e)}")
|
57 |
continue
|
58 |
|
59 |
+
if centers:
|
60 |
rr.log(
|
61 |
"world/subjects",
|
62 |
rr.Boxes3D(
|
|
|
64 |
half_sizes=np.array(half_sizes),
|
65 |
colors=np.array(colors),
|
66 |
labels=labels,
|
67 |
+
fill_mode="solid"
|
68 |
),
|
69 |
timeless=True
|
70 |
)
|
|
|
117 |
)
|
118 |
)
|
119 |
|
|
|
|
|
|
|
|
|
|
|
120 |
except Exception as e:
|
121 |
print(f"Error logging camera frame {frame_idx}: {str(e)}")
|