Update app.py
Browse files
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 |
-
|
| 16 |
-
self.
|
| 17 |
-
|
| 18 |
-
def load_dataset(self):
|
| 19 |
-
|
| 20 |
-
|
| 21 |
return dataset
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
|
| 23 |
-
|
| 24 |
-
#
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
def find_nearest_position(self, current_xyz):
|
| 36 |
min_distance = float('inf')
|
| 37 |
nearest_position = None
|
| 38 |
-
|
| 39 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
for item in self.dataset:
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
for record in trajectory_data:
|
| 45 |
-
for position in record['data']:
|
| 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):
|