Spaces:
Sleeping
Sleeping
Fix load Parameter 0 error + 2D default on HF
Browse files- app.py +18 -8
- build_info.py +1 -1
- demo_core.py +13 -2
app.py
CHANGED
|
@@ -57,6 +57,7 @@ from demo_core import (
|
|
| 57 |
RUN_MODES,
|
| 58 |
TRAJECTORY_VIEW_CHOICES,
|
| 59 |
WEBGL_PROBE_JS,
|
|
|
|
| 60 |
resolve_trajectory_mode,
|
| 61 |
webgl_status_markdown,
|
| 62 |
get_overview_composite_path,
|
|
@@ -950,10 +951,15 @@ def _apply_run_mode_with_3d(mode: str, history: dict | None, traj_view: str, web
|
|
| 950 |
return _apply_run_mode(mode) + _plot_3d_for_mode(mode, history, traj_view, webgl_ok)
|
| 951 |
|
| 952 |
|
| 953 |
-
def _on_webgl_probe(probe: str
|
| 954 |
-
ok = str(probe
|
| 955 |
-
|
| 956 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 957 |
|
| 958 |
|
| 959 |
def _on_trajectory_view_change(view: str, webgl_ok: bool) -> str:
|
|
@@ -2648,6 +2654,7 @@ def build_app() -> gr.Blocks:
|
|
| 2648 |
|
| 2649 |
opt_history_state = gr.State(None)
|
| 2650 |
webgl_ok_state = gr.State(True)
|
|
|
|
| 2651 |
|
| 2652 |
with gr.Tabs():
|
| 2653 |
with gr.Tab("OPTIMIZE"):
|
|
@@ -2658,12 +2665,15 @@ def build_app() -> gr.Blocks:
|
|
| 2658 |
)
|
| 2659 |
trajectory_view = gr.Radio(
|
| 2660 |
choices=TRAJECTORY_VIEW_CHOICES,
|
| 2661 |
-
value=
|
| 2662 |
label="Trajectory view",
|
| 2663 |
-
info="
|
| 2664 |
elem_classes=["vqc-trajectory-view-radio"],
|
| 2665 |
)
|
| 2666 |
-
webgl_status = gr.Markdown(
|
|
|
|
|
|
|
|
|
|
| 2667 |
with gr.Row():
|
| 2668 |
with gr.Column(
|
| 2669 |
visible=False,
|
|
@@ -3012,7 +3022,7 @@ def build_app() -> gr.Blocks:
|
|
| 3012 |
demo.load(_stream_term_boot, outputs=term_keypad_outputs)
|
| 3013 |
demo.load(
|
| 3014 |
_on_webgl_probe,
|
| 3015 |
-
inputs=
|
| 3016 |
outputs=[webgl_ok_state, trajectory_view, webgl_status],
|
| 3017 |
js=WEBGL_PROBE_JS,
|
| 3018 |
)
|
|
|
|
| 57 |
RUN_MODES,
|
| 58 |
TRAJECTORY_VIEW_CHOICES,
|
| 59 |
WEBGL_PROBE_JS,
|
| 60 |
+
default_trajectory_view,
|
| 61 |
resolve_trajectory_mode,
|
| 62 |
webgl_status_markdown,
|
| 63 |
get_overview_composite_path,
|
|
|
|
| 951 |
return _apply_run_mode(mode) + _plot_3d_for_mode(mode, history, traj_view, webgl_ok)
|
| 952 |
|
| 953 |
|
| 954 |
+
def _on_webgl_probe(probe: str) -> tuple:
|
| 955 |
+
ok = str(probe).strip() != "0"
|
| 956 |
+
if is_hf_space():
|
| 957 |
+
view = "2d"
|
| 958 |
+
elif not ok:
|
| 959 |
+
view = "2d"
|
| 960 |
+
else:
|
| 961 |
+
view = "auto"
|
| 962 |
+
return ok, gr.update(value=view), webgl_status_markdown(ok, view)
|
| 963 |
|
| 964 |
|
| 965 |
def _on_trajectory_view_change(view: str, webgl_ok: bool) -> str:
|
|
|
|
| 2654 |
|
| 2655 |
opt_history_state = gr.State(None)
|
| 2656 |
webgl_ok_state = gr.State(True)
|
| 2657 |
+
webgl_probe = gr.Textbox(value="1", visible=False, elem_classes=["vqc-webgl-probe"])
|
| 2658 |
|
| 2659 |
with gr.Tabs():
|
| 2660 |
with gr.Tab("OPTIMIZE"):
|
|
|
|
| 2665 |
)
|
| 2666 |
trajectory_view = gr.Radio(
|
| 2667 |
choices=TRAJECTORY_VIEW_CHOICES,
|
| 2668 |
+
value=default_trajectory_view(),
|
| 2669 |
label="Trajectory view",
|
| 2670 |
+
info="2D is recommended on HF free tier. Choose 3D only if WebGL works in your browser.",
|
| 2671 |
elem_classes=["vqc-trajectory-view-radio"],
|
| 2672 |
)
|
| 2673 |
+
webgl_status = gr.Markdown(
|
| 2674 |
+
webgl_status_markdown(True, default_trajectory_view()),
|
| 2675 |
+
elem_classes=["vqc-webgl-status"],
|
| 2676 |
+
)
|
| 2677 |
with gr.Row():
|
| 2678 |
with gr.Column(
|
| 2679 |
visible=False,
|
|
|
|
| 3022 |
demo.load(_stream_term_boot, outputs=term_keypad_outputs)
|
| 3023 |
demo.load(
|
| 3024 |
_on_webgl_probe,
|
| 3025 |
+
inputs=[webgl_probe],
|
| 3026 |
outputs=[webgl_ok_state, trajectory_view, webgl_status],
|
| 3027 |
js=WEBGL_PROBE_JS,
|
| 3028 |
)
|
build_info.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
"""Auto-generated by scripts/deploy_hf_space.sh — do not edit by hand."""
|
| 2 |
|
| 3 |
BUILD_COMMIT = "97b4a81"
|
| 4 |
-
BUILD_UPDATED_UTC = "2026-06-28T17:
|
|
|
|
| 1 |
"""Auto-generated by scripts/deploy_hf_space.sh — do not edit by hand."""
|
| 2 |
|
| 3 |
BUILD_COMMIT = "97b4a81"
|
| 4 |
+
BUILD_UPDATED_UTC = "2026-06-28T17:19:51Z"
|
demo_core.py
CHANGED
|
@@ -449,8 +449,20 @@ def resolve_trajectory_mode(view_pref: str, webgl_ok: bool) -> str:
|
|
| 449 |
return "2d" if not webgl_ok else "3d"
|
| 450 |
|
| 451 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 452 |
def webgl_status_markdown(webgl_ok: bool, view_pref: str) -> str:
|
| 453 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 454 |
if not webgl_ok:
|
| 455 |
return (
|
| 456 |
"⚠ **WebGL unavailable** — trajectory uses **2D stereographic projections**. "
|
|
@@ -754,7 +766,6 @@ def _make_loss_figure(
|
|
| 754 |
line_width=1,
|
| 755 |
line_dash="dot",
|
| 756 |
line_color=color,
|
| 757 |
-
opacity=0.55,
|
| 758 |
)
|
| 759 |
if i == len(monitor.burst_events[-12:]) - 1:
|
| 760 |
fig.add_annotation(
|
|
|
|
| 449 |
return "2d" if not webgl_ok else "3d"
|
| 450 |
|
| 451 |
|
| 452 |
+
def default_trajectory_view() -> str:
|
| 453 |
+
"""HF free tier defaults to 2D for maximum browser compatibility."""
|
| 454 |
+
return "2d" if is_hf_space() else "auto"
|
| 455 |
+
|
| 456 |
+
|
| 457 |
def webgl_status_markdown(webgl_ok: bool, view_pref: str) -> str:
|
| 458 |
+
if is_hf_space() and view_pref == "2d":
|
| 459 |
+
lead = (
|
| 460 |
+
"**HF free tier:** **2D (WebGL-safe)** trajectory is the default for maximum compatibility. "
|
| 461 |
+
"Switch to **3D interactive** if your browser supports WebGL."
|
| 462 |
+
)
|
| 463 |
+
if not webgl_ok:
|
| 464 |
+
return f"⚠ {lead} (WebGL probe failed — staying in 2D.)"
|
| 465 |
+
return lead
|
| 466 |
if not webgl_ok:
|
| 467 |
return (
|
| 468 |
"⚠ **WebGL unavailable** — trajectory uses **2D stereographic projections**. "
|
|
|
|
| 766 |
line_width=1,
|
| 767 |
line_dash="dot",
|
| 768 |
line_color=color,
|
|
|
|
| 769 |
)
|
| 770 |
if i == len(monitor.burst_events[-12:]) - 1:
|
| 771 |
fig.add_annotation(
|