Spaces:
Build error
Build error
Robotics commited on
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,9 +1,4 @@
|
|
| 1 |
-
import
|
| 2 |
-
import pybullet as p
|
| 3 |
-
from contactvla.env import BoxPushEnv
|
| 4 |
-
from contactvla.mppi import MPPI
|
| 5 |
-
from contactvla.llm_feedback import LLMFeedback
|
| 6 |
-
import numpy as np
|
| 7 |
|
| 8 |
def run_demo(api_key):
|
| 9 |
cid = p.connect(p.DIRECT)
|
|
@@ -11,21 +6,37 @@ def run_demo(api_key):
|
|
| 11 |
mppi = MPPI(env)
|
| 12 |
llm = LLMFeedback(api_key)
|
| 13 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
env.reset()
|
| 15 |
history = []
|
| 16 |
-
|
|
|
|
| 17 |
u = mppi.compute_control()
|
| 18 |
box_pos, ee_pos = env.step(u)
|
| 19 |
cost = env.state_cost()
|
| 20 |
-
history.append({"step":step,"box_pos":box_pos.tolist(),"cost":cost})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
code, expl = llm.ask_state_cost_fn("Flip the box using the wall", history, env)
|
| 22 |
env.update_state_cost(code)
|
| 23 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
|
| 25 |
gr.Interface(
|
| 26 |
fn=run_demo,
|
| 27 |
-
inputs=gr.Textbox(label="Enter your OpenAI API Key", type="password"),
|
| 28 |
-
outputs="text",
|
| 29 |
title="ContactVLA: LLM-guided Box Pushing",
|
| 30 |
-
description="
|
| 31 |
).launch()
|
|
|
|
| 1 |
+
import cv2, numpy as np, imageio, tempfile, os
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
def run_demo(api_key):
|
| 4 |
cid = p.connect(p.DIRECT)
|
|
|
|
| 6 |
mppi = MPPI(env)
|
| 7 |
llm = LLMFeedback(api_key)
|
| 8 |
|
| 9 |
+
cam_w, cam_h = 320, 240
|
| 10 |
+
view = p.computeViewMatrix([0.5, -2, 1], [0.5, 0, 0.5], [0, 0, 1])
|
| 11 |
+
proj = p.computeProjectionMatrixFOV(60, cam_w / cam_h, 0.1, 10)
|
| 12 |
+
frames = []
|
| 13 |
+
|
| 14 |
env.reset()
|
| 15 |
history = []
|
| 16 |
+
|
| 17 |
+
for step in range(20):
|
| 18 |
u = mppi.compute_control()
|
| 19 |
box_pos, ee_pos = env.step(u)
|
| 20 |
cost = env.state_cost()
|
| 21 |
+
history.append({"step": step, "box_pos": box_pos.tolist(), "cost": cost})
|
| 22 |
+
|
| 23 |
+
# render frame off-screen
|
| 24 |
+
_, _, rgb, _, _ = p.getCameraImage(cam_w, cam_h, view, proj, renderer=p.ER_TINY_RENDERER)
|
| 25 |
+
frame = np.array(rgb, dtype=np.uint8).reshape(cam_h, cam_w, 4)[:, :, :3]
|
| 26 |
+
frames.append(frame)
|
| 27 |
+
|
| 28 |
code, expl = llm.ask_state_cost_fn("Flip the box using the wall", history, env)
|
| 29 |
env.update_state_cost(code)
|
| 30 |
+
|
| 31 |
+
tmp_path = tempfile.NamedTemporaryFile(delete=False, suffix=".mp4").name
|
| 32 |
+
imageio.mimsave(tmp_path, frames, fps=10)
|
| 33 |
+
|
| 34 |
+
return tmp_path, f"LLM updated cost:\n{code}\n\nExplanation:\n{expl}"
|
| 35 |
|
| 36 |
gr.Interface(
|
| 37 |
fn=run_demo,
|
| 38 |
+
inputs=gr.Textbox(label="Enter your OpenAI API Key (without quotation marks)", type="password"),
|
| 39 |
+
outputs=["video", "text"],
|
| 40 |
title="ContactVLA: LLM-guided Box Pushing",
|
| 41 |
+
description="Watch the box being pushed and flipped using an LLM-driven controller."
|
| 42 |
).launch()
|