Spaces:
Runtime error
Runtime error
Commit Β·
b5fdc1f
1
Parent(s): 96cef35
fix: call set_page_config before heavy imports; patch duplicate call
Browse files- streamlit_app.py +20 -7
streamlit_app.py
CHANGED
|
@@ -1,21 +1,32 @@
|
|
| 1 |
import sys, os, traceback
|
| 2 |
from pathlib import Path
|
|
|
|
| 3 |
|
| 4 |
-
#
|
| 5 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
-
|
| 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__"},
|
|
@@ -25,3 +36,5 @@ except SystemExit:
|
|
| 25 |
except Exception as exc:
|
| 26 |
st.error(f"SpindleFlow failed to load: {exc}")
|
| 27 |
st.code(traceback.format_exc())
|
|
|
|
|
|
|
|
|
| 1 |
import sys, os, traceback
|
| 2 |
from pathlib import Path
|
| 3 |
+
import streamlit as st
|
| 4 |
|
| 5 |
+
# ββ 1. Page config fires immediately so the browser gets a live response
|
| 6 |
+
# before the 10-30 s ML imports below.
|
| 7 |
+
st.set_page_config(
|
| 8 |
+
page_title="SpindleFlow RL",
|
| 9 |
+
page_icon="β‘",
|
| 10 |
+
layout="wide",
|
| 11 |
+
initial_sidebar_state="collapsed",
|
| 12 |
+
)
|
| 13 |
+
|
| 14 |
+
# ββ 2. Silence the duplicate set_page_config call inside demo/streamlit_app.py
|
| 15 |
+
# (it also has one at module level β would raise StreamlitAPIException).
|
| 16 |
+
_real_spc = st.set_page_config
|
| 17 |
+
st.set_page_config = lambda *a, **kw: None
|
| 18 |
+
|
| 19 |
+
# ββ 3. Make env.*, reward.*, agents.* and orchestrator_widget importable.
|
| 20 |
_root = Path(__file__).resolve().parent
|
| 21 |
for _p in (str(_root), str(_root / "demo")):
|
| 22 |
if _p not in sys.path:
|
| 23 |
sys.path.insert(0, _p)
|
| 24 |
os.chdir(str(_root))
|
| 25 |
|
| 26 |
+
# ββ 4. Run demo/streamlit_app.py exactly as __main__.
|
| 27 |
+
# Its st.set_page_config() call is now a no-op; main() draws the UI.
|
| 28 |
_demo = _root / "demo" / "streamlit_app.py"
|
| 29 |
try:
|
|
|
|
|
|
|
|
|
|
| 30 |
exec(
|
| 31 |
compile(_demo.read_text(encoding="utf-8"), str(_demo), "exec"),
|
| 32 |
{"__file__": str(_demo), "__name__": "__main__"},
|
|
|
|
| 36 |
except Exception as exc:
|
| 37 |
st.error(f"SpindleFlow failed to load: {exc}")
|
| 38 |
st.code(traceback.format_exc())
|
| 39 |
+
finally:
|
| 40 |
+
st.set_page_config = _real_spc # restore for subsequent Streamlit re-runs
|