Spaces:
Build error
Build error
update gradio
Browse files- app.py +8 -1
- cliport/cfg/data.yaml +2 -2
- cliport/environments/environment.py +129 -69
- gensim/sim_runner.py +19 -66
- temp/BuildWheel_error.txt +3 -3
app.py
CHANGED
|
@@ -94,8 +94,15 @@ class DemoRunner:
|
|
| 94 |
self.simulation_runner._md_logger = ''
|
| 95 |
# progress(0.2)
|
| 96 |
yield "Task Generating ==>", None, None
|
|
|
|
|
|
|
| 97 |
yield from self.simulation_runner.example_task_creation()
|
| 98 |
yield from self.simulation_runner.simulate_task()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 99 |
|
| 100 |
|
| 101 |
def setup(api_key, option_choice, target_task_name):
|
|
@@ -159,7 +166,7 @@ if __name__ == '__main__':
|
|
| 159 |
generated_task = gr.Markdown(label='Generated Task')
|
| 160 |
generated_asset = gr.Markdown(label='Generated Asset')
|
| 161 |
generated_code = gr.Code(label='Generated Code', language="python", interactive=True)
|
| 162 |
-
video_run = gr.Video(label='Video of Last Instruction')
|
| 163 |
btn_setup.click(
|
| 164 |
setup,
|
| 165 |
inputs=[inp_api_key, option_choice, inp_instruction],
|
|
|
|
| 94 |
self.simulation_runner._md_logger = ''
|
| 95 |
# progress(0.2)
|
| 96 |
yield "Task Generating ==>", None, None
|
| 97 |
+
|
| 98 |
+
t1 = time.time()
|
| 99 |
yield from self.simulation_runner.example_task_creation()
|
| 100 |
yield from self.simulation_runner.simulate_task()
|
| 101 |
+
# self.simulation_runner.example_task_creation()
|
| 102 |
+
# self.simulation_runner.simulate_task()
|
| 103 |
+
|
| 104 |
+
t2 = time.time()
|
| 105 |
+
print("run example cost = ", t2 - t1, " s")
|
| 106 |
|
| 107 |
|
| 108 |
def setup(api_key, option_choice, target_task_name):
|
|
|
|
| 166 |
generated_task = gr.Markdown(label='Generated Task')
|
| 167 |
generated_asset = gr.Markdown(label='Generated Asset')
|
| 168 |
generated_code = gr.Code(label='Generated Code', language="python", interactive=True)
|
| 169 |
+
video_run = gr.Video(label='Video of Last Instruction', autoplay=True)
|
| 170 |
btn_setup.click(
|
| 171 |
setup,
|
| 172 |
inputs=[inp_api_key, option_choice, inp_instruction],
|
cliport/cfg/data.yaml
CHANGED
|
@@ -30,5 +30,5 @@ record:
|
|
| 30 |
add_text: False
|
| 31 |
add_task_text: True
|
| 32 |
fps: 20
|
| 33 |
-
video_height:
|
| 34 |
-
video_width:
|
|
|
|
| 30 |
add_text: False
|
| 31 |
add_task_text: True
|
| 32 |
fps: 20
|
| 33 |
+
video_height: 320
|
| 34 |
+
video_width: 360
|
cliport/environments/environment.py
CHANGED
|
@@ -307,6 +307,7 @@ class Environment(gym.Env):
|
|
| 307 |
color, depth, _ = self.render_camera(config)
|
| 308 |
obs['color'] += (color,)
|
| 309 |
obs['depth'] += (depth,)
|
|
|
|
| 310 |
return obs, 0.0, True, self.info
|
| 311 |
|
| 312 |
start_time = time.time()
|
|
@@ -325,30 +326,33 @@ class Environment(gym.Env):
|
|
| 325 |
|
| 326 |
obs = self._get_obs()
|
| 327 |
|
| 328 |
-
if not os.path.exists(self.record_cfg['save_video_path']):
|
| 329 |
-
|
| 330 |
-
self.video_path = os.path.join(self.record_cfg['save_video_path'], "123.mp4")
|
| 331 |
-
video_writer = imageio.get_writer(self.video_path,
|
| 332 |
-
|
| 333 |
-
|
| 334 |
-
|
| 335 |
-
print(f"has {len(self.curr_video)} frames to save")
|
| 336 |
-
for color in self.curr_video:
|
| 337 |
-
|
| 338 |
-
|
| 339 |
-
|
|
|
|
|
|
|
|
|
|
| 340 |
self.cur_obs = obs
|
| 341 |
self.cur_reward = reward
|
| 342 |
self.cur_done = done
|
| 343 |
self.cur_info = info
|
| 344 |
-
yield "Task Generated ==> Asset Generated ==> API Reviewed ==> Error Reviewed ==> Code Generated ==> Running Simulation", self.generated_code, self.video_path
|
| 345 |
|
| 346 |
|
| 347 |
def step_simulation(self):
|
| 348 |
p.stepSimulation()
|
| 349 |
self.step_counter += 1
|
| 350 |
|
| 351 |
-
if self.save_video and self.step_counter %
|
| 352 |
self.add_video_frame()
|
| 353 |
|
| 354 |
def render(self, mode='rgb_array'):
|
|
@@ -360,6 +364,62 @@ class Environment(gym.Env):
|
|
| 360 |
|
| 361 |
return color
|
| 362 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 363 |
def render_camera(self, config, image_size=None, shadow=1):
|
| 364 |
"""Render RGB-D image with specified camera configuration."""
|
| 365 |
if not image_size:
|
|
@@ -513,67 +573,67 @@ class Environment(gym.Env):
|
|
| 513 |
# Render frame.
|
| 514 |
config = self.agent_cams[0]
|
| 515 |
image_size = (self.record_cfg['video_height'], self.record_cfg['video_width'])
|
| 516 |
-
color,
|
| 517 |
color = np.array(color)
|
| 518 |
|
| 519 |
-
if hasattr(self.record_cfg, 'blender_render') and self.record_cfg['blender_render']:
|
| 520 |
-
|
| 521 |
-
self.blender_recorder.add_keyframe()
|
| 522 |
|
| 523 |
# Add language instruction to video.
|
| 524 |
-
if self.record_cfg['add_text']:
|
| 525 |
-
|
| 526 |
-
|
| 527 |
-
|
| 528 |
-
|
| 529 |
-
|
| 530 |
-
|
| 531 |
-
|
| 532 |
-
|
| 533 |
-
|
| 534 |
-
|
| 535 |
-
|
| 536 |
-
|
| 537 |
-
|
| 538 |
-
|
| 539 |
-
|
| 540 |
-
|
| 541 |
-
|
| 542 |
-
|
| 543 |
-
|
| 544 |
-
|
| 545 |
-
|
| 546 |
-
|
| 547 |
-
|
| 548 |
-
|
| 549 |
-
|
| 550 |
-
|
| 551 |
-
|
| 552 |
-
|
| 553 |
-
|
| 554 |
-
|
| 555 |
-
if 'add_task_text' in self.record_cfg and self.record_cfg['add_task_text']:
|
| 556 |
-
|
| 557 |
-
|
| 558 |
-
|
| 559 |
-
|
| 560 |
-
|
| 561 |
-
|
| 562 |
-
|
| 563 |
-
|
| 564 |
-
|
| 565 |
-
|
| 566 |
-
|
| 567 |
-
|
| 568 |
-
|
| 569 |
-
|
| 570 |
-
|
| 571 |
-
|
| 572 |
-
|
| 573 |
-
|
| 574 |
|
| 575 |
self.curr_video.append(color)
|
| 576 |
-
self.video_writer.append_data(color)
|
| 577 |
|
| 578 |
def movep(self, pose, speed=0.01):
|
| 579 |
"""Move UR5 to target end effector pose."""
|
|
|
|
| 307 |
color, depth, _ = self.render_camera(config)
|
| 308 |
obs['color'] += (color,)
|
| 309 |
obs['depth'] += (depth,)
|
| 310 |
+
|
| 311 |
return obs, 0.0, True, self.info
|
| 312 |
|
| 313 |
start_time = time.time()
|
|
|
|
| 326 |
|
| 327 |
obs = self._get_obs()
|
| 328 |
|
| 329 |
+
# if not os.path.exists(self.record_cfg['save_video_path']):
|
| 330 |
+
# os.mkdir(self.record_cfg['save_video_path'])
|
| 331 |
+
# self.video_path = os.path.join(self.record_cfg['save_video_path'], "123.mp4")
|
| 332 |
+
# video_writer = imageio.get_writer(self.video_path,
|
| 333 |
+
# fps=self.record_cfg['fps'],
|
| 334 |
+
# format='FFMPEG',
|
| 335 |
+
# codec='h264', )
|
| 336 |
+
# print(f"has {len(self.curr_video)} frames to save")
|
| 337 |
+
# for color in self.curr_video:
|
| 338 |
+
# video_writer.append_data(color)
|
| 339 |
+
# video_writer.close()
|
| 340 |
+
# print("save video to ", self.video_path)
|
| 341 |
+
# self.video_path = None
|
| 342 |
+
|
| 343 |
+
|
| 344 |
self.cur_obs = obs
|
| 345 |
self.cur_reward = reward
|
| 346 |
self.cur_done = done
|
| 347 |
self.cur_info = info
|
| 348 |
+
# yield "Task Generated ==> Asset Generated ==> API Reviewed ==> Error Reviewed ==> Code Generated ==> Running Simulation", self.generated_code, self.video_path
|
| 349 |
|
| 350 |
|
| 351 |
def step_simulation(self):
|
| 352 |
p.stepSimulation()
|
| 353 |
self.step_counter += 1
|
| 354 |
|
| 355 |
+
if self.save_video and self.step_counter % 60 == 0:
|
| 356 |
self.add_video_frame()
|
| 357 |
|
| 358 |
def render(self, mode='rgb_array'):
|
|
|
|
| 364 |
|
| 365 |
return color
|
| 366 |
|
| 367 |
+
def render_camera_without_seg(self, config, image_size=None, shadow=1):
|
| 368 |
+
"""Render RGB-D image with specified camera configuration."""
|
| 369 |
+
if not image_size:
|
| 370 |
+
image_size = config['image_size']
|
| 371 |
+
|
| 372 |
+
# OpenGL camera settings.
|
| 373 |
+
lookdir = np.float32([0, 0, 1]).reshape(3, 1)
|
| 374 |
+
updir = np.float32([0, -1, 0]).reshape(3, 1)
|
| 375 |
+
rotation = p.getMatrixFromQuaternion(config['rotation'])
|
| 376 |
+
rotm = np.float32(rotation).reshape(3, 3)
|
| 377 |
+
lookdir = (rotm @ lookdir).reshape(-1)
|
| 378 |
+
updir = (rotm @ updir).reshape(-1)
|
| 379 |
+
lookat = config['position'] + lookdir
|
| 380 |
+
focal_len = config['intrinsics'][0]
|
| 381 |
+
znear, zfar = config['zrange']
|
| 382 |
+
viewm = p.computeViewMatrix(config['position'], lookat, updir)
|
| 383 |
+
fovh = (image_size[0] / 2) / focal_len
|
| 384 |
+
fovh = (640 / 2) / focal_len
|
| 385 |
+
fovh = 180 * np.arctan(fovh) * 2 / np.pi
|
| 386 |
+
|
| 387 |
+
# Notes: 1) FOV is vertical FOV 2) aspect must be float
|
| 388 |
+
aspect_ratio = image_size[1] / image_size[0]
|
| 389 |
+
projm = p.computeProjectionMatrixFOV(fovh, aspect_ratio, znear, zfar)
|
| 390 |
+
|
| 391 |
+
# Render with OpenGL camera settings.
|
| 392 |
+
_, _, color, depth, segm = p.getCameraImage(
|
| 393 |
+
width=image_size[1],
|
| 394 |
+
height=image_size[0],
|
| 395 |
+
viewMatrix=viewm,
|
| 396 |
+
projectionMatrix=projm,
|
| 397 |
+
shadow=shadow,
|
| 398 |
+
flags=p.ER_SEGMENTATION_MASK_OBJECT_AND_LINKINDEX,
|
| 399 |
+
renderer=p.ER_BULLET_HARDWARE_OPENGL)
|
| 400 |
+
|
| 401 |
+
# Get color image.
|
| 402 |
+
color_image_size = (image_size[0], image_size[1], 4)
|
| 403 |
+
color = np.array(color, dtype=np.uint8).reshape(color_image_size)
|
| 404 |
+
color = color[:, :, :3] # remove alpha channel
|
| 405 |
+
if config['noise']:
|
| 406 |
+
color = np.int32(color)
|
| 407 |
+
color += np.int32(self._random.normal(0, 3, image_size))
|
| 408 |
+
color = np.uint8(np.clip(color, 0, 255))
|
| 409 |
+
|
| 410 |
+
# Get depth image.
|
| 411 |
+
depth_image_size = (image_size[0], image_size[1])
|
| 412 |
+
zbuffer = np.array(depth).reshape(depth_image_size)
|
| 413 |
+
depth = (zfar + znear - (2. * zbuffer - 1.) * (zfar - znear))
|
| 414 |
+
depth = (2. * znear * zfar) / depth
|
| 415 |
+
if config['noise']:
|
| 416 |
+
depth += self._random.normal(0, 0.003, depth_image_size)
|
| 417 |
+
|
| 418 |
+
# Get segmentation image.
|
| 419 |
+
segm = np.uint8(segm).reshape(depth_image_size)
|
| 420 |
+
|
| 421 |
+
return color, depth, segm
|
| 422 |
+
|
| 423 |
def render_camera(self, config, image_size=None, shadow=1):
|
| 424 |
"""Render RGB-D image with specified camera configuration."""
|
| 425 |
if not image_size:
|
|
|
|
| 573 |
# Render frame.
|
| 574 |
config = self.agent_cams[0]
|
| 575 |
image_size = (self.record_cfg['video_height'], self.record_cfg['video_width'])
|
| 576 |
+
color, _, _ = self.render_camera_without_seg(config, image_size, shadow=0)
|
| 577 |
color = np.array(color)
|
| 578 |
|
| 579 |
+
# if hasattr(self.record_cfg, 'blender_render') and self.record_cfg['blender_render']:
|
| 580 |
+
# print("add blender key frame")
|
| 581 |
+
# self.blender_recorder.add_keyframe()
|
| 582 |
|
| 583 |
# Add language instruction to video.
|
| 584 |
+
# if self.record_cfg['add_text']:
|
| 585 |
+
# lang_goal = self.get_lang_goal()
|
| 586 |
+
# reward = f"Success: {self.task.get_reward():.3f}"
|
| 587 |
+
#
|
| 588 |
+
# font = cv2.FONT_HERSHEY_DUPLEX
|
| 589 |
+
# font_scale = 0.65
|
| 590 |
+
# font_thickness = 1
|
| 591 |
+
#
|
| 592 |
+
# # Write language goal.
|
| 593 |
+
# line_length = 60
|
| 594 |
+
# for i in range(len(lang_goal) // line_length + 1):
|
| 595 |
+
# lang_textsize = cv2.getTextSize(lang_goal[i*line_length:(i+1)*line_length], font, font_scale, font_thickness)[0]
|
| 596 |
+
# lang_textX = (image_size[1] - lang_textsize[0]) // 2
|
| 597 |
+
# color = cv2.putText(color, lang_goal[i*line_length:(i+1)*line_length], org=(lang_textX, 570+i*30), # 600
|
| 598 |
+
# fontScale=font_scale,
|
| 599 |
+
# fontFace=font,
|
| 600 |
+
# color=(0, 0, 0),
|
| 601 |
+
# thickness=font_thickness, lineType=cv2.LINE_AA)
|
| 602 |
+
#
|
| 603 |
+
# ## Write Reward.
|
| 604 |
+
# # reward_textsize = cv2.getTextSize(reward, font, font_scale, font_thickness)[0]
|
| 605 |
+
# # reward_textX = (image_size[1] - reward_textsize[0]) // 2
|
| 606 |
+
# #
|
| 607 |
+
# # color = cv2.putText(color, reward, org=(reward_textX, 634),
|
| 608 |
+
# # fontScale=font_scale,
|
| 609 |
+
# # fontFace=font,
|
| 610 |
+
# # color=(0, 0, 0),
|
| 611 |
+
# # thickness=font_thickness, lineType=cv2.LINE_AA)
|
| 612 |
+
#
|
| 613 |
+
# color = np.array(color)
|
| 614 |
+
#
|
| 615 |
+
# if 'add_task_text' in self.record_cfg and self.record_cfg['add_task_text']:
|
| 616 |
+
# lang_goal = self.get_task_name()
|
| 617 |
+
# reward = f"Success: {self.task.get_reward():.3f}"
|
| 618 |
+
#
|
| 619 |
+
# font = cv2.FONT_HERSHEY_DUPLEX
|
| 620 |
+
# font_scale = 1
|
| 621 |
+
# font_thickness = 2
|
| 622 |
+
#
|
| 623 |
+
# # Write language goal.
|
| 624 |
+
# lang_textsize = cv2.getTextSize(lang_goal, font, font_scale, font_thickness)[0]
|
| 625 |
+
# lang_textX = (image_size[1] - lang_textsize[0]) // 2
|
| 626 |
+
#
|
| 627 |
+
# color = cv2.putText(color, lang_goal, org=(lang_textX, 600),
|
| 628 |
+
# fontScale=font_scale,
|
| 629 |
+
# fontFace=font,
|
| 630 |
+
# color=(255, 0, 0),
|
| 631 |
+
# thickness=font_thickness, lineType=cv2.LINE_AA)
|
| 632 |
+
#
|
| 633 |
+
# color = np.array(color)
|
| 634 |
|
| 635 |
self.curr_video.append(color)
|
| 636 |
+
# self.video_writer.append_data(color)
|
| 637 |
|
| 638 |
def movep(self, pose, speed=0.01):
|
| 639 |
"""Move UR5 to target end effector pose."""
|
gensim/sim_runner.py
CHANGED
|
@@ -5,6 +5,8 @@ from cliport import tasks
|
|
| 5 |
from cliport.dataset import RavensDataset
|
| 6 |
from cliport.environments.environment import Environment
|
| 7 |
|
|
|
|
|
|
|
| 8 |
from pygments import highlight
|
| 9 |
from pygments.lexers import PythonLexer
|
| 10 |
from pygments.formatters import TerminalFormatter
|
|
@@ -164,80 +166,17 @@ class BuildWheel(Task):
|
|
| 164 |
|
| 165 |
# self.generated_task = {'task-name': 'TASK_NAME_TEMPLATE', 'task-description': 'TASK_STRING_TEMPLATE', 'assets-used': ['ASSET_1', 'ASSET_2', Ellipsis]}
|
| 166 |
print("generated_task\n", self.generated_task)
|
| 167 |
-
|
| 168 |
yield "Task Generated ==>", None, None
|
| 169 |
-
|
| 170 |
self.generated_asset = self.agent.propose_assets()
|
| 171 |
-
|
| 172 |
-
# self.generated_asset = {}
|
| 173 |
print("generated_asset\n", self.generated_asset)
|
| 174 |
yield "Task Generated ==> Asset Generated ==> ", None, None
|
| 175 |
-
|
| 176 |
self.agent.api_review()
|
| 177 |
-
|
| 178 |
-
|
| 179 |
yield "Task Generated ==> Asset Generated ==> API Reviewed ==> ", None, None
|
| 180 |
self.critic.error_review(self.generated_task)
|
| 181 |
-
|
| 182 |
-
|
| 183 |
yield "Task Generated ==> Asset Generated ==> API Reviewed ==> Error Reviewed ==> ", None, None
|
| 184 |
self.generated_code, self.curr_task_name = self.agent.implement_task()
|
| 185 |
self.task_asset_logs.append(self.generated_task["assets-used"])
|
| 186 |
self.generated_task_name = self.generated_task["task-name"]
|
| 187 |
-
|
| 188 |
-
# self.curr_task_name = self.generated_task_name = 'BuildWheel'
|
| 189 |
-
#
|
| 190 |
-
# self.generated_code = """
|
| 191 |
-
# import numpy as np
|
| 192 |
-
# from cliport.tasks.task import Task
|
| 193 |
-
# from cliport.utils import utils
|
| 194 |
-
#
|
| 195 |
-
# class BuildWheel(Task):
|
| 196 |
-
#
|
| 197 |
-
# def __init__(self):
|
| 198 |
-
# super().__init__()
|
| 199 |
-
# self.max_steps = 10
|
| 200 |
-
# self.lang_template = "Construct a wheel using blocks and a sphere. First, position eight blocks in a circular layout on the tabletop. Each block should be touching its two neighbors and colored in alternating red and blue. Then place a green sphere in the center of the circular layout, completing the wheel."
|
| 201 |
-
# self.task_completed_desc = "done building wheel."
|
| 202 |
-
# self.additional_reset()
|
| 203 |
-
#
|
| 204 |
-
# def reset(self, env):
|
| 205 |
-
# super().reset(env)
|
| 206 |
-
#
|
| 207 |
-
# # Add blocks.
|
| 208 |
-
# block_size = (0.04, 0.04, 0.04)
|
| 209 |
-
# block_urdf = 'block/block.urdf'
|
| 210 |
-
# block_colors = [utils.COLORS['red'], utils.COLORS['blue']]
|
| 211 |
-
# blocks = []
|
| 212 |
-
# for i in range(8):
|
| 213 |
-
# block_pose = self.get_random_pose(env, block_size)
|
| 214 |
-
# block_id = env.add_object(block_urdf, block_pose, color=block_colors[i % 2])
|
| 215 |
-
# blocks.append(block_id)
|
| 216 |
-
#
|
| 217 |
-
# # Add sphere.
|
| 218 |
-
# sphere_size = (0.04, 0.04, 0.04)
|
| 219 |
-
# sphere_urdf = 'sphere/sphere.urdf'
|
| 220 |
-
# sphere_color = utils.COLORS['green']
|
| 221 |
-
# sphere_pose = ((0.5, 0.0, 0.0), (0,0,0,1)) # fixed pose
|
| 222 |
-
# sphere_id = env.add_object(sphere_urdf, sphere_pose, color=sphere_color)
|
| 223 |
-
#
|
| 224 |
-
# # Goal: blocks are arranged in a circle and sphere is in the center.
|
| 225 |
-
# circle_radius = 0.1
|
| 226 |
-
# circle_center = (0, 0, block_size[2] / 2)
|
| 227 |
-
# angles = np.linspace(0, 2 * np.pi, 8, endpoint=False)
|
| 228 |
-
# block_poses = [(circle_center[0] + circle_radius * np.cos(angle),
|
| 229 |
-
# circle_center[1] + circle_radius * np.sin(angle),
|
| 230 |
-
# circle_center[2]) for angle in angles]
|
| 231 |
-
# block_poses = [(utils.apply(sphere_pose, pos), sphere_pose[1]) for pos in block_poses]
|
| 232 |
-
# self.add_goal(objs=blocks, matches=np.ones((8, 8)), targ_poses=block_poses, replace=False,
|
| 233 |
-
# rotations=True, metric='pose', params=None, step_max_reward=8 / 9)
|
| 234 |
-
#
|
| 235 |
-
# # Goal: sphere is in the center of the blocks.
|
| 236 |
-
# self.add_goal(objs=[sphere_id], matches=np.ones((1, 1)), targ_poses=[sphere_pose], replace=False,
|
| 237 |
-
# rotations=False, metric='pose', params=None, step_max_reward=1 / 9)
|
| 238 |
-
#
|
| 239 |
-
# self.lang_goals.append(self.lang_template)
|
| 240 |
-
# """
|
| 241 |
print("generated_code\n", self.generated_code)
|
| 242 |
print("curr_task_name\n", self.curr_task_name)
|
| 243 |
yield "Task Generated ==> Asset Generated ==> API Reviewed ==> Error Reviewed ==> Code Generated ==> ", self.generated_code, None
|
|
@@ -368,8 +307,8 @@ class BuildWheel(Task):
|
|
| 368 |
act = expert.act(obs, info)
|
| 369 |
episode.append((obs, act, reward, info))
|
| 370 |
lang_goal = info['lang_goal']
|
| 371 |
-
|
| 372 |
-
|
| 373 |
|
| 374 |
obs, reward, done, info = env.cur_obs, env.cur_reward, env.cur_done, env.cur_info
|
| 375 |
total_reward += reward
|
|
@@ -380,7 +319,21 @@ class BuildWheel(Task):
|
|
| 380 |
|
| 381 |
end_time = time.time()
|
| 382 |
print("end sim, time used = ", end_time - start_time)
|
| 383 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 384 |
episode.append((obs, None, reward, info))
|
| 385 |
|
| 386 |
|
|
|
|
| 5 |
from cliport.dataset import RavensDataset
|
| 6 |
from cliport.environments.environment import Environment
|
| 7 |
|
| 8 |
+
import imageio
|
| 9 |
+
|
| 10 |
from pygments import highlight
|
| 11 |
from pygments.lexers import PythonLexer
|
| 12 |
from pygments.formatters import TerminalFormatter
|
|
|
|
| 166 |
|
| 167 |
# self.generated_task = {'task-name': 'TASK_NAME_TEMPLATE', 'task-description': 'TASK_STRING_TEMPLATE', 'assets-used': ['ASSET_1', 'ASSET_2', Ellipsis]}
|
| 168 |
print("generated_task\n", self.generated_task)
|
|
|
|
| 169 |
yield "Task Generated ==>", None, None
|
|
|
|
| 170 |
self.generated_asset = self.agent.propose_assets()
|
|
|
|
|
|
|
| 171 |
print("generated_asset\n", self.generated_asset)
|
| 172 |
yield "Task Generated ==> Asset Generated ==> ", None, None
|
|
|
|
| 173 |
self.agent.api_review()
|
|
|
|
|
|
|
| 174 |
yield "Task Generated ==> Asset Generated ==> API Reviewed ==> ", None, None
|
| 175 |
self.critic.error_review(self.generated_task)
|
|
|
|
|
|
|
| 176 |
yield "Task Generated ==> Asset Generated ==> API Reviewed ==> Error Reviewed ==> ", None, None
|
| 177 |
self.generated_code, self.curr_task_name = self.agent.implement_task()
|
| 178 |
self.task_asset_logs.append(self.generated_task["assets-used"])
|
| 179 |
self.generated_task_name = self.generated_task["task-name"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 180 |
print("generated_code\n", self.generated_code)
|
| 181 |
print("curr_task_name\n", self.curr_task_name)
|
| 182 |
yield "Task Generated ==> Asset Generated ==> API Reviewed ==> Error Reviewed ==> Code Generated ==> ", self.generated_code, None
|
|
|
|
| 307 |
act = expert.act(obs, info)
|
| 308 |
episode.append((obs, act, reward, info))
|
| 309 |
lang_goal = info['lang_goal']
|
| 310 |
+
|
| 311 |
+
env.step(act)
|
| 312 |
|
| 313 |
obs, reward, done, info = env.cur_obs, env.cur_reward, env.cur_done, env.cur_info
|
| 314 |
total_reward += reward
|
|
|
|
| 319 |
|
| 320 |
end_time = time.time()
|
| 321 |
print("end sim, time used = ", end_time - start_time)
|
| 322 |
+
|
| 323 |
+
if not os.path.exists(env.record_cfg['save_video_path']):
|
| 324 |
+
os.mkdir(env.record_cfg['save_video_path'])
|
| 325 |
+
self.video_path = os.path.join(env.record_cfg['save_video_path'], "123.mp4")
|
| 326 |
+
video_writer = imageio.get_writer(self.video_path,
|
| 327 |
+
fps=env.record_cfg['fps'],
|
| 328 |
+
format='FFMPEG',
|
| 329 |
+
codec='h264', )
|
| 330 |
+
print(f"has {len(env.curr_video)} frames to save")
|
| 331 |
+
for color in env.curr_video:
|
| 332 |
+
video_writer.append_data(color)
|
| 333 |
+
video_writer.close()
|
| 334 |
+
print("save video to ", self.video_path)
|
| 335 |
+
|
| 336 |
+
yield "Task Generated ==> Asset Generated ==> API Reviewed ==> Error Reviewed ==> Code Generated ==> Simulation Running completed", self.generated_code, self.video_path
|
| 337 |
episode.append((obs, None, reward, info))
|
| 338 |
|
| 339 |
|
temp/BuildWheel_error.txt
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
Traceback (most recent call last):
|
| 2 |
-
File "/home/baochen/Desktop/projects/GPT-CLIPort/gensim/sim_runner.py", line
|
| 3 |
-
yield "Task Generated ==> Asset Generated ==> Code Generated ==> Running
|
| 4 |
-
AttributeError: '
|
|
|
|
| 1 |
Traceback (most recent call last):
|
| 2 |
+
File "/home/baochen/Desktop/projects/GPT-CLIPort/gensim/sim_runner.py", line 339, in simulate_task
|
| 3 |
+
yield "Task Generated ==> Asset Generated ==> API Reviewed ==> Error Reviewed ==> Code Generated ==> Simulation Running completed", self.generated_code, env.video_path
|
| 4 |
+
AttributeError: 'Environment' object has no attribute 'video_path'
|