Update app.py
Browse files
app.py
CHANGED
|
@@ -15,36 +15,55 @@ class SecondLifeNavigator:
|
|
| 15 |
self.dataset = self.load_dataset()
|
| 16 |
|
| 17 |
def load_dataset(self):
|
| 18 |
-
#
|
| 19 |
-
dataset = load_dataset("visionlab/block-towers-10k-3s-trajectory-scale1")
|
| 20 |
return dataset
|
| 21 |
|
| 22 |
-
def
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
else:
|
| 35 |
-
return f"Failed to execute command {command}: HTTP {response.status_code}", None
|
| 36 |
-
except Exception as e:
|
| 37 |
-
return f"Error sending command to Corrade: {e}", None
|
| 38 |
|
| 39 |
def determine_action_sequence(self, current_state):
|
| 40 |
-
#
|
| 41 |
-
#
|
| 42 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
|
| 44 |
def run(self, current_state, corrade_endpoint):
|
| 45 |
action_sequence = self.determine_action_sequence(current_state)
|
| 46 |
return action_sequence
|
| 47 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
def create_interface():
|
| 49 |
def navigate(current_state):
|
| 50 |
dataset_path = os.getenv('DATASET_PATH') # Assuming the dataset path is set in an environment variable
|
|
|
|
| 15 |
self.dataset = self.load_dataset()
|
| 16 |
|
| 17 |
def load_dataset(self):
|
| 18 |
+
# Assuming the dataset contains useful navigation data
|
| 19 |
+
dataset = load_dataset("visionlab/block-towers-10k-3s-trajectory-scale1", split='train')
|
| 20 |
return dataset
|
| 21 |
|
| 22 |
+
def find_nearest_position(self, current_xyz):
|
| 23 |
+
# Placeholder for a function that finds the nearest final position
|
| 24 |
+
# This is a simplistic approach; you might need a more complex logic depending on your dataset structure
|
| 25 |
+
min_distance = float('inf')
|
| 26 |
+
nearest_position = None
|
| 27 |
+
for position in self.dataset['final_positions']:
|
| 28 |
+
x, y, z = position['x'], position['y'], position['z']
|
| 29 |
+
distance = np.sqrt((x - current_xyz[0])**2 + (y - current_xyz[1])**2 + (z - current_xyz[2])**2)
|
| 30 |
+
if distance < min_distance:
|
| 31 |
+
min_distance = distance
|
| 32 |
+
nearest_position = position
|
| 33 |
+
return nearest_position
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
|
| 35 |
def determine_action_sequence(self, current_state):
|
| 36 |
+
# Analyze current_state to extract current XYZ position
|
| 37 |
+
# This is a simplified example; your actual implementation might be different
|
| 38 |
+
current_xyz = [0, 0, 0] # Assuming current_state can be used to derive current XYZ coordinates
|
| 39 |
+
|
| 40 |
+
nearest_position = self.find_nearest_position(current_xyz)
|
| 41 |
+
if nearest_position:
|
| 42 |
+
action_sequence = f"Move to position {nearest_position['x']}, {nearest_position['y']}, {nearest_position['z']}"
|
| 43 |
+
else:
|
| 44 |
+
action_sequence = "No suitable position found."
|
| 45 |
+
return action_sequence
|
| 46 |
|
| 47 |
def run(self, current_state, corrade_endpoint):
|
| 48 |
action_sequence = self.determine_action_sequence(current_state)
|
| 49 |
return action_sequence
|
| 50 |
+
|
| 51 |
+
def send_command_to_corrade(self, corrade_endpoint, command, parameters):
|
| 52 |
+
command_data = {
|
| 53 |
+
"command": command,
|
| 54 |
+
"group": "e269893f-a570-0087-930e-6ba2a0b77f9c",
|
| 55 |
+
"password": "nucleus",
|
| 56 |
+
}
|
| 57 |
+
command_data.update(parameters)
|
| 58 |
+
|
| 59 |
+
try:
|
| 60 |
+
response = requests.post(corrade_endpoint, json=command_data)
|
| 61 |
+
if response.status_code == 200:
|
| 62 |
+
return f"Command {command} executed successfully.", response.json()
|
| 63 |
+
else:
|
| 64 |
+
return f"Failed to execute command {command}: HTTP {response.status_code}", None
|
| 65 |
+
except Exception as e:
|
| 66 |
+
return f"Error sending command to Corrade: {e}", None
|
| 67 |
def create_interface():
|
| 68 |
def navigate(current_state):
|
| 69 |
dataset_path = os.getenv('DATASET_PATH') # Assuming the dataset path is set in an environment variable
|