Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,11 +1,25 @@
|
|
| 1 |
from dotenv import load_dotenv
|
| 2 |
-
load_dotenv()
|
| 3 |
-
|
| 4 |
import streamlit as st
|
| 5 |
-
import sys, os
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
-
# ───
|
| 8 |
-
|
|
|
|
|
|
|
| 9 |
|
| 10 |
# ─── Page Config ────────────────────────────────────────────────
|
| 11 |
st.set_page_config(page_title="Omniscient Dashboard", layout="wide")
|
|
@@ -14,46 +28,54 @@ st.set_page_config(page_title="Omniscient Dashboard", layout="wide")
|
|
| 14 |
st.title("🤖 Omniscient LLM Dashboard")
|
| 15 |
st.write("Welcome! This Space is running **Streamlit multipage mode** with Taipy integration.")
|
| 16 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
# ─── Metrics Section ────────────────────────────────────────────
|
| 18 |
-
col1, col2, col3 = st.columns(
|
| 19 |
|
| 20 |
-
# Active chat sessions
|
| 21 |
active_sessions = len(st.session_state.get("messages", []))
|
| 22 |
col1.metric("💬 Active Sessions", active_sessions)
|
| 23 |
|
| 24 |
-
# Uploaded files counter
|
| 25 |
uploaded_files = len(st.session_state.get("uploaded_files", []))
|
| 26 |
col2.metric("📂 Uploaded Files", uploaded_files)
|
| 27 |
|
| 28 |
-
# Error counter
|
| 29 |
errors = len(st.session_state.get("errors", []))
|
| 30 |
col3.metric("⚠️ Errors", errors)
|
| 31 |
|
|
|
|
|
|
|
| 32 |
st.success("System ready ✅")
|
| 33 |
|
| 34 |
-
# ─── Sidebar Navigation
|
| 35 |
-
st.
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
- 🖥️ SysMonitor → local system metrics from `/proc/`
|
| 53 |
-
- 🧪 Example → placeholder demo
|
| 54 |
-
""")
|
| 55 |
-
|
| 56 |
-
# ─── Embed Taipy Realtime Dashboard ───────────────────────────
|
| 57 |
st.subheader("📊 Realtime System Dashboard (Taipy)")
|
| 58 |
-
|
| 59 |
-
st.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
from dotenv import load_dotenv
|
|
|
|
|
|
|
| 2 |
import streamlit as st
|
| 3 |
+
import sys, os, requests, pathlib
|
| 4 |
+
|
| 5 |
+
# ─── Load Configuration from .env ───────────────────────────────
|
| 6 |
+
def load_config():
|
| 7 |
+
load_dotenv()
|
| 8 |
+
config = {
|
| 9 |
+
"APP_MODE": os.getenv("APP_MODE", "streamlit"),
|
| 10 |
+
"OLLAMA_MODEL": os.getenv("OLLAMA_MODEL", "llama3"),
|
| 11 |
+
"HF_API_KEY": os.getenv("HF_API_KEY", ""),
|
| 12 |
+
"BACKEND_URL": os.getenv("BACKEND_URL", "http://localhost:9000"),
|
| 13 |
+
"TAIPY_URL": os.getenv("TAIPY_URL", "http://localhost:8080"),
|
| 14 |
+
}
|
| 15 |
+
return config
|
| 16 |
+
|
| 17 |
+
config = load_config()
|
| 18 |
|
| 19 |
+
# ─── Ensure utils/ importable ───────────────────────────────────
|
| 20 |
+
ROOT_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
|
| 21 |
+
if ROOT_PATH not in sys.path:
|
| 22 |
+
sys.path.insert(0, ROOT_PATH)
|
| 23 |
|
| 24 |
# ─── Page Config ────────────────────────────────────────────────
|
| 25 |
st.set_page_config(page_title="Omniscient Dashboard", layout="wide")
|
|
|
|
| 28 |
st.title("🤖 Omniscient LLM Dashboard")
|
| 29 |
st.write("Welcome! This Space is running **Streamlit multipage mode** with Taipy integration.")
|
| 30 |
|
| 31 |
+
# ─── Backend Health Check ───────────────────────────────────────
|
| 32 |
+
def backend_status(url):
|
| 33 |
+
try:
|
| 34 |
+
res = requests.get(f"{url}/health", timeout=3)
|
| 35 |
+
return "🟢 Online" if res.ok else "🟠 Unresponsive"
|
| 36 |
+
except Exception:
|
| 37 |
+
return "🔴 Offline"
|
| 38 |
+
|
| 39 |
# ─── Metrics Section ────────────────────────────────────────────
|
| 40 |
+
col1, col2, col3, col4 = st.columns(4)
|
| 41 |
|
|
|
|
| 42 |
active_sessions = len(st.session_state.get("messages", []))
|
| 43 |
col1.metric("💬 Active Sessions", active_sessions)
|
| 44 |
|
|
|
|
| 45 |
uploaded_files = len(st.session_state.get("uploaded_files", []))
|
| 46 |
col2.metric("📂 Uploaded Files", uploaded_files)
|
| 47 |
|
|
|
|
| 48 |
errors = len(st.session_state.get("errors", []))
|
| 49 |
col3.metric("⚠️ Errors", errors)
|
| 50 |
|
| 51 |
+
col4.metric("🔌 API Backend", backend_status(config["BACKEND_URL"]))
|
| 52 |
+
|
| 53 |
st.success("System ready ✅")
|
| 54 |
|
| 55 |
+
# ─── Dynamic Sidebar Navigation ─────────────────────────────────
|
| 56 |
+
st.sidebar.header("📑 Navigation")
|
| 57 |
+
|
| 58 |
+
pages_path = os.path.join(os.path.dirname(__file__), "pages")
|
| 59 |
+
if os.path.isdir(pages_path):
|
| 60 |
+
st.sidebar.write("**Modules:**")
|
| 61 |
+
pages = sorted([p.stem for p in pathlib.Path(pages_path).glob("*.py")])
|
| 62 |
+
for page in pages:
|
| 63 |
+
st.sidebar.markdown(f"- {page}")
|
| 64 |
+
|
| 65 |
+
st.sidebar.markdown("---")
|
| 66 |
+
st.sidebar.info("🧠 Omniscient Framework v0.1 — AI-driven OSINT & DFIR Hub")
|
| 67 |
+
|
| 68 |
+
# ─── Session Debug (optional) ───────────────────────────────────
|
| 69 |
+
with st.expander("🧩 Session Diagnostics", expanded=False):
|
| 70 |
+
st.json({k: v for k, v in st.session_state.items() if len(str(v)) < 1000})
|
| 71 |
+
|
| 72 |
+
# ─── Embed Taipy Realtime Dashboard ─────────────────────────────
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 73 |
st.subheader("📊 Realtime System Dashboard (Taipy)")
|
| 74 |
+
|
| 75 |
+
if "SPACE_ID" in st.secrets: # running on Hugging Face
|
| 76 |
+
st.info("Taipy dashboard is disabled on Hugging Face Spaces (requires local port).")
|
| 77 |
+
else:
|
| 78 |
+
try:
|
| 79 |
+
st.components.v1.iframe(config["TAIPY_URL"], height=600)
|
| 80 |
+
except Exception:
|
| 81 |
+
st.warning("Unable to load Taipy dashboard.")
|