Spaces:
Sleeping
Sleeping
devjas1
commited on
Commit
·
de280d1
1
Parent(s):
e484a46
(ui): add multi-modality routing skeleton to dashboard.
Browse files- Restructured dashboard to support multi-modality routing.
- Built a robust interface foundation that enables long-term support for Raman, Image, FTIR pathways.
- Per-modality page routing: Raman(Dashboard, Model MGMT, Inferece); Image & FTIR(placeholder shells).
- All modlaity and page selections preserved via 'st.session_state'.
- dashboard/app.py +138 -0
dashboard/app.py
ADDED
|
@@ -0,0 +1,138 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Streamlit UI for ml-polymer-recycling — Step 3a: Multi-Modality Interface Skeleton
|
| 3 |
+
- Introduces top-level modality selector (Raman | Image | FTIR)
|
| 4 |
+
- Modular routing for each modality with scoped navigation
|
| 5 |
+
- Only Raman pages are active (Model Management, Inference)
|
| 6 |
+
- Image/FTIR pages show 'Coming Soon' placeholders
|
| 7 |
+
- All routing and session state preserved cleanly
|
| 8 |
+
"""
|
| 9 |
+
|
| 10 |
+
import streamlit as st
|
| 11 |
+
from pathlib import Path
|
| 12 |
+
|
| 13 |
+
# --- PAGE CONFIGURATION ---
|
| 14 |
+
st.set_page_config(
|
| 15 |
+
page_title="ML Polymer Recycling",
|
| 16 |
+
page_icon="🧪",
|
| 17 |
+
layout="wide"
|
| 18 |
+
)
|
| 19 |
+
|
| 20 |
+
# --- SESSION STATE INITIALIZATION ---
|
| 21 |
+
def init_session_state():
|
| 22 |
+
if "status_message" not in st.session_state:
|
| 23 |
+
st.session_state.status_message = "Ready."
|
| 24 |
+
if "status_type" not in st.session_state:
|
| 25 |
+
st.session_state.status_type = "ok"
|
| 26 |
+
if "modality" not in st.session_state:
|
| 27 |
+
st.session_state.modality = "Raman"
|
| 28 |
+
|
| 29 |
+
# --- STATUS BANNER ---
|
| 30 |
+
def display_status():
|
| 31 |
+
style_map = {
|
| 32 |
+
"ok": ("#e8f5e9", "#2e7d32"),
|
| 33 |
+
"warn": ("#fff8e1", "#f9a825"),
|
| 34 |
+
"err": ("#ffebee", "#c62828")
|
| 35 |
+
}
|
| 36 |
+
bg_color, text_color = style_map.get(st.session_state.status_type, ("#f0f0f0", "#333"))
|
| 37 |
+
st.markdown(f"""
|
| 38 |
+
<div style='background-color:{bg_color}; padding:0.75em 1em; border-radius:8px; color:{text_color};'>
|
| 39 |
+
<b>Status:</b> {st.session_state.status_message}
|
| 40 |
+
</div>
|
| 41 |
+
""", unsafe_allow_html=True)
|
| 42 |
+
|
| 43 |
+
# --- SIDEBAR NAVIGATION ---
|
| 44 |
+
def display_sidebar():
|
| 45 |
+
with st.sidebar:
|
| 46 |
+
st.header("🧪 ML Polymer Dashboard")
|
| 47 |
+
|
| 48 |
+
modality = st.radio("Modality", ["Raman", "Image", "FTIR"])
|
| 49 |
+
st.session_state.modality = modality
|
| 50 |
+
|
| 51 |
+
if modality == "Raman":
|
| 52 |
+
page = st.radio("Raman Pages", ["Dashboard", "Model Management", "Inference"])
|
| 53 |
+
elif modality == "Image":
|
| 54 |
+
page = st.radio("Image Pages", ["Model Management", "Inference"])
|
| 55 |
+
elif modality == "FTIR":
|
| 56 |
+
page = st.radio("FTIR Pages", ["Model Management", "Inference"])
|
| 57 |
+
|
| 58 |
+
return modality, page
|
| 59 |
+
|
| 60 |
+
# --- HEADER BAR ---
|
| 61 |
+
def display_header(title: str):
|
| 62 |
+
st.title(title)
|
| 63 |
+
display_status()
|
| 64 |
+
st.markdown("---")
|
| 65 |
+
|
| 66 |
+
# --- MODEL DISCOVERY (Raman only for now) ---
|
| 67 |
+
def discover_models(outputs_dir="outputs"):
|
| 68 |
+
out = []
|
| 69 |
+
root = Path(outputs_dir)
|
| 70 |
+
if not root.exists():
|
| 71 |
+
return []
|
| 72 |
+
for p in sorted(root.rglob("*.pth")):
|
| 73 |
+
out.append(p)
|
| 74 |
+
return out
|
| 75 |
+
|
| 76 |
+
# --- RAMAN PAGES ---
|
| 77 |
+
def raman_dashboard():
|
| 78 |
+
display_header("Raman Dashboard")
|
| 79 |
+
st.write("This will house future metrics, model count, and version history.")
|
| 80 |
+
|
| 81 |
+
def raman_model_management():
|
| 82 |
+
display_header("Raman Model Management")
|
| 83 |
+
models = discover_models()
|
| 84 |
+
if not models:
|
| 85 |
+
st.info("No model weights found in outputs/. Place .pth files there to make them discoverable.")
|
| 86 |
+
else:
|
| 87 |
+
st.markdown(f"**Discovered {len(models)} model weight file(s):**")
|
| 88 |
+
for m in models:
|
| 89 |
+
st.code(str(m), language="text")
|
| 90 |
+
|
| 91 |
+
def raman_inference():
|
| 92 |
+
display_header("Raman Inference")
|
| 93 |
+
st.write("This will house the real-time spectrum upload and model prediction interface.")
|
| 94 |
+
|
| 95 |
+
# --- IMAGE + FTIR PLACEHOLDERS ---
|
| 96 |
+
def image_model_management():
|
| 97 |
+
display_header("Image Model Management")
|
| 98 |
+
st.info("Image-based model integration is coming soon.")
|
| 99 |
+
|
| 100 |
+
def image_inference():
|
| 101 |
+
display_header("Image Inference")
|
| 102 |
+
st.info("This page will allow batch image upload and multi-model prediction.")
|
| 103 |
+
|
| 104 |
+
def ftir_model_management():
|
| 105 |
+
display_header("FTIR Model Management")
|
| 106 |
+
st.info("FTIR model support is planned and will be developed after clarification with Dr. K.")
|
| 107 |
+
|
| 108 |
+
def ftir_inference():
|
| 109 |
+
display_header("FTIR Inference")
|
| 110 |
+
st.info("FTIR input and prediction support will be added in a future phase.")
|
| 111 |
+
|
| 112 |
+
# --- MAIN ENTRY POINT ---
|
| 113 |
+
def main():
|
| 114 |
+
init_session_state()
|
| 115 |
+
modality, page = display_sidebar()
|
| 116 |
+
|
| 117 |
+
if modality == "Raman":
|
| 118 |
+
if page == "Dashboard":
|
| 119 |
+
raman_dashboard()
|
| 120 |
+
elif page == "Model Management":
|
| 121 |
+
raman_model_management()
|
| 122 |
+
elif page == "Inference":
|
| 123 |
+
raman_inference()
|
| 124 |
+
|
| 125 |
+
elif modality == "Image":
|
| 126 |
+
if page == "Model Management":
|
| 127 |
+
image_model_management()
|
| 128 |
+
elif page == "Inference":
|
| 129 |
+
image_inference()
|
| 130 |
+
|
| 131 |
+
elif modality == "FTIR":
|
| 132 |
+
if page == "Model Management":
|
| 133 |
+
ftir_model_management()
|
| 134 |
+
elif page == "Inference":
|
| 135 |
+
ftir_inference()
|
| 136 |
+
|
| 137 |
+
if __name__ == "__main__":
|
| 138 |
+
main()
|