Spaces:
Runtime error
Runtime error
Commit ·
96cef35
1
Parent(s): a824fc0
fix: use exec() wrapper — eliminates double set_page_config crash
Browse files- streamlit_app.py +16 -30
streamlit_app.py
CHANGED
|
@@ -1,39 +1,25 @@
|
|
| 1 |
-
import streamlit as st
|
| 2 |
import sys, os, traceback
|
| 3 |
from pathlib import Path
|
| 4 |
|
| 5 |
-
#
|
| 6 |
-
#
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
layout="wide",
|
| 13 |
-
initial_sidebar_state="collapsed",
|
| 14 |
-
)
|
| 15 |
-
_orig_spc = st.set_page_config
|
| 16 |
-
st.set_page_config = lambda *a, **kw: None # silence double-call from demo
|
| 17 |
-
|
| 18 |
-
root = Path(__file__).resolve().parent
|
| 19 |
-
demo_dir = root / "demo"
|
| 20 |
-
for p in (str(root), str(demo_dir)):
|
| 21 |
-
if p not in sys.path:
|
| 22 |
-
sys.path.insert(0, p)
|
| 23 |
-
os.chdir(str(root))
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
@st.cache_resource(show_spinner="Loading SpindleFlow RL…")
|
| 27 |
-
def _load_app():
|
| 28 |
-
"""Cache the demo module so the 10–20 s ML import only happens once."""
|
| 29 |
-
import demo.streamlit_app as _app # noqa: PLC0415
|
| 30 |
-
return _app
|
| 31 |
|
|
|
|
| 32 |
|
|
|
|
| 33 |
try:
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
except SystemExit:
|
| 38 |
pass
|
| 39 |
except Exception as exc:
|
|
|
|
|
|
|
| 1 |
import sys, os, traceback
|
| 2 |
from pathlib import Path
|
| 3 |
|
| 4 |
+
# Make env.*, reward.*, agents.* (from repo root) and orchestrator_widget
|
| 5 |
+
# (from demo/) importable before demo/streamlit_app.py starts.
|
| 6 |
+
_root = Path(__file__).resolve().parent
|
| 7 |
+
for _p in (str(_root), str(_root / "demo")):
|
| 8 |
+
if _p not in sys.path:
|
| 9 |
+
sys.path.insert(0, _p)
|
| 10 |
+
os.chdir(str(_root))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
+
import streamlit as st # needed only for the error fallback below
|
| 13 |
|
| 14 |
+
_demo = _root / "demo" / "streamlit_app.py"
|
| 15 |
try:
|
| 16 |
+
# Run demo/streamlit_app.py exactly as if it were the entry-point script.
|
| 17 |
+
# __file__ must point to the demo file so its own Path(__file__) logic
|
| 18 |
+
# resolves paths correctly (e.g. demo/assets, orchestrator_widget).
|
| 19 |
+
exec(
|
| 20 |
+
compile(_demo.read_text(encoding="utf-8"), str(_demo), "exec"),
|
| 21 |
+
{"__file__": str(_demo), "__name__": "__main__"},
|
| 22 |
+
)
|
| 23 |
except SystemExit:
|
| 24 |
pass
|
| 25 |
except Exception as exc:
|