NexusInstruments's picture
Update app.py
63ff4f2 verified
raw
history blame
3.99 kB
from dotenv import load_dotenv
import streamlit as st
import sys, os, requests, pathlib, contextlib
# ─── Load Configuration from .env ───────────────────────────────
def load_config():
load_dotenv()
config = {
"APP_MODE": os.getenv("APP_MODE", "streamlit"),
"OLLAMA_MODEL": os.getenv("OLLAMA_MODEL", "llama3"),
"HF_API_KEY": os.getenv("HF_API_KEY", ""),
"BACKEND_URL": os.getenv("BACKEND_URL", "http://localhost:9000"),
"TAIPY_URL": os.getenv("TAIPY_URL", "http://localhost:8080"),
}
return config
config = load_config()
# ─── Ensure utils/ importable ───────────────────────────────────
ROOT_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
if ROOT_PATH not in sys.path:
sys.path.insert(0, ROOT_PATH)
# ─── Page Config ────────────────────────────────────────────────
st.set_page_config(page_title="Omniscient Dashboard", layout="wide")
# ─── Title ──────────────────────────────────────────────────────
st.title("🤖 Omniscient LLM Dashboard")
st.write("Welcome! This Space is running **Streamlit multipage mode** with Taipy integration.")
# ─── Backend Health Check ───────────────────────────────────────
def backend_status(url):
try:
res = requests.get(f"{url}/health", timeout=3)
return "🟢 Online" if res.ok else "🟠 Unresponsive"
except Exception:
return "🔴 Offline"
# ─── Metrics Section ────────────────────────────────────────────
col1, col2, col3, col4 = st.columns(4)
active_sessions = len(st.session_state.get("messages", []))
col1.metric("💬 Active Sessions", active_sessions)
uploaded_files = len(st.session_state.get("uploaded_files", []))
col2.metric("📂 Uploaded Files", uploaded_files)
errors = len(st.session_state.get("errors", []))
col3.metric("⚠️ Errors", errors)
col4.metric("🔌 API Backend", backend_status(config["BACKEND_URL"]))
st.success("System ready ✅")
# ─── Dynamic Sidebar Navigation ─────────────────────────────────
st.sidebar.header("📑 Navigation")
pages_path = os.path.join(os.path.dirname(__file__), "pages")
if os.path.isdir(pages_path):
st.sidebar.write("**Modules:**")
pages = sorted([p.stem for p in pathlib.Path(pages_path).glob("*.py")])
for page in pages:
st.sidebar.markdown(f"- {page}")
st.sidebar.markdown("---")
st.sidebar.info("🧠 Omniscient Framework v0.1 — AI-driven OSINT & DFIR Hub")
# ─── Session Debug (optional) ───────────────────────────────────
with st.expander("🧩 Session Diagnostics", expanded=False):
st.json({k: v for k, v in st.session_state.items() if len(str(v)) < 1000})
# ─── Embed Taipy Realtime Dashboard ─────────────────────────────
st.subheader("📊 Realtime System Dashboard (Taipy)")
space_id = None
with contextlib.suppress(Exception):
secrets_obj = getattr(st, "secrets", None)
if secrets_obj:
with contextlib.suppress(Exception):
space_id = secrets_obj.get("SPACE_ID", None)
if space_id:
st.info("Taipy dashboard is disabled on Hugging Face Spaces (requires local port).")
else:
try:
st.components.v1.iframe(config["TAIPY_URL"], height=600)
except Exception as e:
st.warning(f"Unable to load Taipy dashboard: {e}")