AEUPH commited on
Commit
ed1dc29
·
verified ·
1 Parent(s): 3b807aa

Rename app.py to app.py.bak4

Browse files
Files changed (1) hide show
  1. app.py → app.py.bak4 +16 -3
app.py → app.py.bak4 RENAMED
@@ -13,24 +13,36 @@ print("Initializing GPT-2 Tokenizer and Model...")
13
  tokenizer = GPT2Tokenizer.from_pretrained('gpt2')
14
  model = GPT2LMHeadModel.from_pretrained('gpt2')
15
 
16
- # Global dataset loading
 
 
 
17
  print("Loading dataset...")
18
  dataset = load_dataset("visionlab/block-towers-10k-3s-trajectory-scale1", split='train')
19
  print("Dataset loaded successfully.")
20
 
21
  from scipy.spatial import KDTree
22
 
23
- # Assuming final_positions is a list of dicts with 'x', 'y', 'z'
 
 
24
  final_positions = [position for item in dataset for position in item['data']['final_positions']]
25
  positions_array = np.array([[p['x'], p['y'], p['z']] for p in final_positions])
26
 
27
  # Build a KD-tree
28
  tree = KDTree(positions_array)
29
 
30
- # Now, given a current_xyz as a list [x, y, z], you can find the nearest position quickly
 
 
 
 
 
31
  distance, index = tree.query(current_xyz)
32
  nearest_position = final_positions[index]
33
 
 
 
34
  def safe_convert_single_to_double_quotes(s):
35
  try:
36
  temp_placeholder = "<TEMP_ESCAPED_SINGLE_QUOTE>"
@@ -47,6 +59,7 @@ class SecondLifeNavigator:
47
  self.dataset = dataset
48
  print("SecondLifeNavigator initialized with the dataset.")
49
 
 
50
  def determine_action_sequence(self, current_xyz):
51
  print(f"Determining action sequence for position: {current_xyz}")
52
  min_distance = float('inf')
 
13
  tokenizer = GPT2Tokenizer.from_pretrained('gpt2')
14
  model = GPT2LMHeadModel.from_pretrained('gpt2')
15
 
16
+ from scipy.spatial import KDTree
17
+
18
+
19
+ # Load your dataset
20
  print("Loading dataset...")
21
  dataset = load_dataset("visionlab/block-towers-10k-3s-trajectory-scale1", split='train')
22
  print("Dataset loaded successfully.")
23
 
24
  from scipy.spatial import KDTree
25
 
26
+ print("Extracting positions and building KD-tree...")
27
+
28
+ # Assuming final_positions is structured as shown
29
  final_positions = [position for item in dataset for position in item['data']['final_positions']]
30
  positions_array = np.array([[p['x'], p['y'], p['z']] for p in final_positions])
31
 
32
  # Build a KD-tree
33
  tree = KDTree(positions_array)
34
 
35
+ print("KD-tree constructed successfully.")
36
+
37
+ # Example current_xyz coordinate
38
+ current_xyz = [1, 2, 3] # Replace with actual values as needed
39
+
40
+ print("Querying KD-tree for the nearest position...")
41
  distance, index = tree.query(current_xyz)
42
  nearest_position = final_positions[index]
43
 
44
+ print(f"Nearest position found: {nearest_position} at distance {distance}")
45
+
46
  def safe_convert_single_to_double_quotes(s):
47
  try:
48
  temp_placeholder = "<TEMP_ESCAPED_SINGLE_QUOTE>"
 
59
  self.dataset = dataset
60
  print("SecondLifeNavigator initialized with the dataset.")
61
 
62
+
63
  def determine_action_sequence(self, current_xyz):
64
  print(f"Determining action sequence for position: {current_xyz}")
65
  min_distance = float('inf')