Spaces:
Running
on
Zero
Running
on
Zero
File size: 1,167 Bytes
ffbf761 44a5fb8 ffbf761 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
import tempfile
import os
import spaces
from typing import Optional
from data.loader import load_simulation_data
from visualization.logger import SimulationLogger
import rerun as rr
@spaces.GPU
def visualize_simulation(file, simulation_index: int) -> Optional[str]:
if file is None:
return None
try:
simulations, _ = load_simulation_data(file)
if simulations is None or simulation_index >= len(simulations):
return None
# Create temporary file for RRD
temp_dir = tempfile.mkdtemp()
rrd_path = os.path.join(temp_dir, "simulation.rrd")
# Log selected simulation
simulation = simulations[simulation_index]
logger = SimulationLogger()
logger.log_metadata(simulation['instructions'])
logger.log_subjects(
simulation['subjects'], simulation.get('selectedSubject'))
logger.log_camera_trajectory(simulation['cameraFrames'])
logger.log_camera_frames(simulation['cameraFrames'])
rr.save(rrd_path)
return rrd_path
except Exception as e:
print(f"Error processing simulation: {str(e)}")
return None
|