Spaces:
Sleeping
Sleeping
finally working
Browse files- app.py +6 -12
- nginx.conf +14 -19
app.py
CHANGED
|
@@ -2,17 +2,17 @@ import gradio as gr
|
|
| 2 |
import numpy as np
|
| 3 |
from robots import LiveRobot
|
| 4 |
|
| 5 |
-
ROBOTS = ["ur5", "ur10",
|
| 6 |
|
| 7 |
# single global instance to keep the MeshCat connection alive
|
| 8 |
-
robot = LiveRobot("
|
| 9 |
|
| 10 |
with gr.Blocks(title="Pinocchio + MeshCat β Live") as demo:
|
| 11 |
gr.Markdown("### π€ Pinocchio + MeshCat β Live Viewer\n"
|
| 12 |
"Sliders update the robot in real time (no reload).")
|
| 13 |
|
| 14 |
with gr.Row():
|
| 15 |
-
robot_dd = gr.Dropdown(ROBOTS, value="
|
| 16 |
neutral_btn = gr.Button("Neutral")
|
| 17 |
|
| 18 |
viewer = gr.HTML(robot.iframe())
|
|
@@ -45,16 +45,10 @@ with gr.Blocks(title="Pinocchio + MeshCat β Live") as demo:
|
|
| 45 |
robot = LiveRobot(name)
|
| 46 |
# rebuild slider values to the new robot's neutral
|
| 47 |
viewer_html = robot.iframe()
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
# Clear existing sliders
|
| 51 |
-
sliders = []
|
| 52 |
-
# Create new sliders for the new robot
|
| 53 |
-
for label, (lo, hi), qi in zip(robot.labels, robot.bounds, robot.idxs):
|
| 54 |
-
sliders.append(gr.Slider(minimum=lo, maximum=hi, step=0.01,
|
| 55 |
-
value=float(robot.q[qi]), label=label))
|
| 56 |
# Return viewer and new sliders
|
| 57 |
-
return [viewer_html] +
|
| 58 |
|
| 59 |
robot_dd.change(on_change_robot, inputs=robot_dd,
|
| 60 |
outputs=[viewer] + sliders, queue=False)
|
|
|
|
| 2 |
import numpy as np
|
| 3 |
from robots import LiveRobot
|
| 4 |
|
| 5 |
+
ROBOTS = ["panda", "ur5", "ur10", "talos"]
|
| 6 |
|
| 7 |
# single global instance to keep the MeshCat connection alive
|
| 8 |
+
robot = LiveRobot("panda")
|
| 9 |
|
| 10 |
with gr.Blocks(title="Pinocchio + MeshCat β Live") as demo:
|
| 11 |
gr.Markdown("### π€ Pinocchio + MeshCat β Live Viewer\n"
|
| 12 |
"Sliders update the robot in real time (no reload).")
|
| 13 |
|
| 14 |
with gr.Row():
|
| 15 |
+
robot_dd = gr.Dropdown(ROBOTS, value="panda", label="Robot")
|
| 16 |
neutral_btn = gr.Button("Neutral")
|
| 17 |
|
| 18 |
viewer = gr.HTML(robot.iframe())
|
|
|
|
| 45 |
robot = LiveRobot(name)
|
| 46 |
# rebuild slider values to the new robot's neutral
|
| 47 |
viewer_html = robot.iframe()
|
| 48 |
+
updates = [gr.update(value=(lo+hi)/2, label=label, minimum=lo, maximum=hi)
|
| 49 |
+
for (label,(lo,hi)) in zip(robot.labels, robot.bounds)]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
# Return viewer and new sliders
|
| 51 |
+
return [viewer_html] + updates
|
| 52 |
|
| 53 |
robot_dd.change(on_change_robot, inputs=robot_dd,
|
| 54 |
outputs=[viewer] + sliders, queue=False)
|
nginx.conf
CHANGED
|
@@ -6,35 +6,38 @@ http {
|
|
| 6 |
default_type application/octet-stream;
|
| 7 |
sendfile on;
|
| 8 |
|
| 9 |
-
# ws upgrade
|
| 10 |
map $http_upgrade $connection_upgrade { default upgrade; '' close; }
|
| 11 |
|
| 12 |
-
#
|
| 13 |
map $http_upgrade $root_backend {
|
| 14 |
-
default http://127.0.0.1:
|
| 15 |
-
"~*upgrade" http://127.0.0.1:8765;
|
| 16 |
"~*websocket" http://127.0.0.1:8765;
|
| 17 |
}
|
| 18 |
|
| 19 |
upstream app { server 127.0.0.1:8501; } # Gradio
|
| 20 |
-
upstream meshcat { server 127.0.0.1:7000; } # MeshCat HTTP
|
| 21 |
|
| 22 |
server {
|
| 23 |
listen 7860;
|
| 24 |
|
| 25 |
-
#
|
| 26 |
location /meshcat/ {
|
| 27 |
-
proxy_pass http://meshcat/static/;
|
| 28 |
proxy_set_header Host $host;
|
| 29 |
}
|
| 30 |
|
| 31 |
-
# MeshCat
|
| 32 |
location /static/ {
|
| 33 |
proxy_pass http://meshcat/static/;
|
| 34 |
proxy_set_header Host $host;
|
| 35 |
}
|
| 36 |
-
|
| 37 |
-
|
|
|
|
|
|
|
|
|
|
| 38 |
proxy_http_version 1.1;
|
| 39 |
proxy_set_header Upgrade $http_upgrade;
|
| 40 |
proxy_set_header Connection $connection_upgrade;
|
|
@@ -43,13 +46,5 @@ http {
|
|
| 43 |
proxy_send_timeout 3600s;
|
| 44 |
proxy_pass $root_backend;
|
| 45 |
}
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
# ---- Your app at /ui/
|
| 49 |
-
location /ui/ {
|
| 50 |
-
proxy_pass http://app/; # trailing slash keeps subpaths OK
|
| 51 |
-
proxy_set_header Host $host;
|
| 52 |
-
}
|
| 53 |
-
|
| 54 |
}
|
| 55 |
-
}
|
|
|
|
| 6 |
default_type application/octet-stream;
|
| 7 |
sendfile on;
|
| 8 |
|
| 9 |
+
# helper for ws upgrade header
|
| 10 |
map $http_upgrade $connection_upgrade { default upgrade; '' close; }
|
| 11 |
|
| 12 |
+
# decide if request at "/" is a websocket upgrade:
|
| 13 |
map $http_upgrade $root_backend {
|
| 14 |
+
default http://127.0.0.1:8501; # normal HTTP -> Gradio
|
| 15 |
+
"~*upgrade" http://127.0.0.1:8765; # WS upgrade -> bridge
|
| 16 |
"~*websocket" http://127.0.0.1:8765;
|
| 17 |
}
|
| 18 |
|
| 19 |
upstream app { server 127.0.0.1:8501; } # Gradio
|
| 20 |
+
upstream meshcat { server 127.0.0.1:7000; } # MeshCat HTTP (/static) & WS at "/"
|
| 21 |
|
| 22 |
server {
|
| 23 |
listen 7860;
|
| 24 |
|
| 25 |
+
# MeshCat viewer HTML lives under /static/ β mount at /meshcat/
|
| 26 |
location /meshcat/ {
|
| 27 |
+
proxy_pass http://meshcat/static/; # trailing slash matters
|
| 28 |
proxy_set_header Host $host;
|
| 29 |
}
|
| 30 |
|
| 31 |
+
# MeshCat HTML references /static/... absolutely β forward those too
|
| 32 |
location /static/ {
|
| 33 |
proxy_pass http://meshcat/static/;
|
| 34 |
proxy_set_header Host $host;
|
| 35 |
}
|
| 36 |
+
|
| 37 |
+
# ROOT "/":
|
| 38 |
+
# - normal HTTP (page loads, XHR, etc.) -> Gradio app
|
| 39 |
+
# - WebSocket upgrade (opened by MeshCat JS to ws://HOST:7860/) -> WS bridge
|
| 40 |
+
location / {
|
| 41 |
proxy_http_version 1.1;
|
| 42 |
proxy_set_header Upgrade $http_upgrade;
|
| 43 |
proxy_set_header Connection $connection_upgrade;
|
|
|
|
| 46 |
proxy_send_timeout 3600s;
|
| 47 |
proxy_pass $root_backend;
|
| 48 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
}
|
| 50 |
+
}
|