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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -6
app.py CHANGED
@@ -9,14 +9,39 @@ import uuid
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
 
9
  tokenizer = GPT2Tokenizer.from_pretrained('gpt2')
10
  model = GPT2LMHeadModel.from_pretrained('gpt2')
11
  from datasets import load_dataset
12
+ # Global dataset loading
13
+ dataset = load_dataset("visionlab/block-towers-10k-3s-trajectory-scale1", split='train')
14
+
15
+ # Preprocess dataset to build a lookup table for fast access
16
+ # Simplified example: computing average positions (assuming a 2D grid for simplicity)
17
+ lookup_table = {}
18
+ grid_size = 1.0 # Adjust based on your dataset's scale and distribution
19
+ for item in dataset:
20
+ for record in item['data']['trajectory']:
21
+ for position in record['data']:
22
+ xyz = position['xyz']
23
+ grid_key = (round(xyz[0]/grid_size), round(xyz[1]/grid_size), round(xyz[2]/grid_size))
24
+ if grid_key not in lookup_table:
25
+ lookup_table[grid_key] = xyz
26
+ else:
27
+ # Update this to handle multiple positions per grid cell if needed
28
+ pass
29
+
30
  class SecondLifeNavigator:
31
  def __init__(self):
32
+ # Assume the dataset and lookup_table are ready to use
33
+ self.lookup_table = lookup_table
34
+
35
+ def determine_action_sequence(self, current_xyz):
36
+ # Simplified nearest position lookup using the grid
37
+ grid_key = (round(current_xyz[0]/grid_size), round(current_xyz[1]/grid_size), round(current_xyz[2]/grid_size))
38
+ nearest_position = self.lookup_table.get(grid_key)
39
+
40
+ if nearest_position:
41
+ action_sequence = f"Move to position {nearest_position[0]}, {nearest_position[1]}, {nearest_position[2]}"
42
+ else:
43
+ action_sequence = "No suitable position found."
44
+ return action_sequence
45
 
46
  def preprocess_data(self):
47
  # Initialize an empty dictionary for the lookup table