AEUPH commited on
Commit
cfea439
·
verified ·
1 Parent(s): 0464503

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -27
app.py CHANGED
@@ -9,46 +9,51 @@ import uuid
9
  tokenizer = GPT2Tokenizer.from_pretrained('gpt2')
10
  model = GPT2LMHeadModel.from_pretrained('gpt2')
11
  from datasets import load_dataset
12
- dataset = load_dataset("visionlab/block-towers-10k-3s-trajectory-scale1", split='train')
13
  class SecondLifeNavigator:
14
  def __init__(self):
15
- # Load the dataset, focusing on the 'data' column if that's where the positions are stored.
16
- self.dataset = self.load_dataset()
17
-
18
- def load_dataset(self):
19
- # Load a specific split of the dataset, for example, 'train'.
20
-
21
  return dataset
 
 
 
 
22
 
23
- def determine_action_sequence(self, current_state):
24
- # Assuming current_state can be used to derive current XYZ coordinates
25
- current_xyz = [0, 0, 0] # Example values, replace with actual extraction logic
26
-
27
- nearest_position = self.find_nearest_position(current_xyz)
28
- if nearest_position:
29
- # Construct action sequence based on nearest position
30
- action_sequence = f"Move to position {nearest_position['x']}, {nearest_position['y']}, {nearest_position['z']}"
31
- else:
32
- action_sequence = "No suitable position found."
33
- return action_sequence
34
-
35
- def find_nearest_position(self, current_xyz):
36
  min_distance = float('inf')
37
  nearest_position = None
38
-
39
- # Iterate over items in the dataset. Assuming each item is a dictionary that follows the structure you provided.
 
 
 
 
 
 
40
  for item in self.dataset:
41
- # Directly accessing the 'trajectory' data assuming 'item' is structured as described
42
- trajectory_data = item['data']['trajectory'] # Adjust this if 'data' refers to something else
43
-
44
  for record in trajectory_data:
45
- for position in record['data']: # Now we are in the 'data' list inside 'trajectory'
46
  xyz = position['xyz']
47
  distance = np.sqrt((xyz[0] - current_xyz[0])**2 + (xyz[1] - current_xyz[1])**2 + (xyz[2] - current_xyz[2])**2)
48
  if distance < min_distance:
49
  min_distance = distance
50
  nearest_position = xyz
51
-
52
  return nearest_position
53
 
54
  def send_command_to_corrade(self, corrade_endpoint, command, parameters):
 
9
  tokenizer = GPT2Tokenizer.from_pretrained('gpt2')
10
  model = GPT2LMHeadModel.from_pretrained('gpt2')
11
  from datasets import load_dataset
 
12
  class SecondLifeNavigator:
13
  def __init__(self):
14
+ self.dataset = self.load_dataset("visionlab/block-towers-10k-3s-trajectory-scale1", split='train')
15
+ self.position_lookup = self.preprocess_data()
16
+
17
+ def load_dataset(self, dataset_name, split='train'):
18
+ dataset = load_dataset(dataset_name, split=split)
 
19
  return dataset
20
+
21
+ def preprocess_data(self):
22
+ # Initialize an empty dictionary for the lookup table
23
+ position_lookup = {}
24
 
25
+ # Example: Creating a grid of positions for simplification
26
+ # This grid should be adjusted based on the expected range of xyz values
27
+ for x in np.arange(-100, 100, 1): # Adjust the range and step as needed
28
+ for y in np.arange(-100, 100, 1):
29
+ for z in np.arange(-100, 100, 1):
30
+ nearest_position = self.find_nearest_position([x, y, z], preprocess=True)
31
+ position_lookup[(x, y, z)] = nearest_position
32
+
33
+ return position_lookup
34
+
35
+ def find_nearest_position(self, current_xyz, preprocess=False):
 
 
36
  min_distance = float('inf')
37
  nearest_position = None
38
+
39
+ # Assuming 'trajectory' data contains the relevant positions during preprocessing
40
+ # If not preprocessing, use the lookup
41
+ if not preprocess:
42
+ # Here you access the pre-calculated nearest position from the lookup
43
+ # Adjust rounding or grid matching based on how the preprocess_data was implemented
44
+ return self.position_lookup.get(tuple(map(int, current_xyz)), None)
45
+
46
  for item in self.dataset:
47
+ trajectory_data = item['data']['trajectory'] # Adjust based on the actual structure
48
+
 
49
  for record in trajectory_data:
50
+ for position in record['data']:
51
  xyz = position['xyz']
52
  distance = np.sqrt((xyz[0] - current_xyz[0])**2 + (xyz[1] - current_xyz[1])**2 + (xyz[2] - current_xyz[2])**2)
53
  if distance < min_distance:
54
  min_distance = distance
55
  nearest_position = xyz
56
+
57
  return nearest_position
58
 
59
  def send_command_to_corrade(self, corrade_endpoint, command, parameters):