Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,88 +1,50 @@
|
|
| 1 |
-
from
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 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")
|
| 26 |
-
|
| 27 |
-
# ─── Title ──────────────────────────────────────────────────────
|
| 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 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 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 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 81 |
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
try:
|
| 86 |
-
|
|
|
|
|
|
|
| 87 |
except Exception as e:
|
| 88 |
-
|
|
|
|
| 1 |
+
from fastapi import FastAPI, UploadFile, Form
|
| 2 |
+
from fastapi.responses import JSONResponse
|
| 3 |
+
from utils.summarizer import summarize_text
|
| 4 |
+
from utils.file_utils import normalize_log_line, keyword_search
|
| 5 |
+
from utils.docgen import generate_doc
|
| 6 |
+
|
| 7 |
+
app = FastAPI(title="Omniscient Backend API")
|
| 8 |
+
|
| 9 |
+
# ─── Health Check ─────────────────────────────────────────────
|
| 10 |
+
@app.get("/health")
|
| 11 |
+
def health():
|
| 12 |
+
return JSONResponse({"ok": True, "message": "Omniscient backend alive"})
|
| 13 |
+
|
| 14 |
+
# ─── File Summarization ───────────────────────────────────────
|
| 15 |
+
@app.post("/summarize")
|
| 16 |
+
async def summarize(file: UploadFile):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
try:
|
| 18 |
+
content = (await file.read()).decode("utf-8", errors="ignore")
|
| 19 |
+
summary = summarize_text(content)
|
| 20 |
+
return {"file": file.filename, "summary": summary}
|
| 21 |
+
except Exception as e:
|
| 22 |
+
return {"error": str(e)}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
|
| 24 |
+
# ─── Log Normalization & Search ───────────────────────────────
|
| 25 |
+
@app.post("/analyze-log")
|
| 26 |
+
async def analyze_log(file: UploadFile, query: str = Form(None)):
|
| 27 |
+
try:
|
| 28 |
+
content = (await file.read()).decode("utf-8", errors="ignore")
|
| 29 |
+
normalized = [normalize_log_line(line) for line in content.splitlines()]
|
| 30 |
+
result = {
|
| 31 |
+
"total_lines": len(normalized),
|
| 32 |
+
"unique_entries": len(set(normalized)),
|
| 33 |
+
"preview": normalized[:50],
|
| 34 |
+
}
|
| 35 |
+
if query:
|
| 36 |
+
matches = keyword_search("\n".join(normalized), query)
|
| 37 |
+
result["matches"] = matches[:50]
|
| 38 |
+
return {"file": file.filename, "analysis": result}
|
| 39 |
+
except Exception as e:
|
| 40 |
+
return {"error": str(e)}
|
| 41 |
|
| 42 |
+
# ─── Script Documentation Generator ──────────────────────────
|
| 43 |
+
@app.post("/generate-doc")
|
| 44 |
+
async def gen_doc(file: UploadFile):
|
| 45 |
try:
|
| 46 |
+
content = (await file.read()).decode("utf-8", errors="ignore")
|
| 47 |
+
doc = generate_doc(file.filename, "uploaded", content)
|
| 48 |
+
return {"file": file.filename, "doc": doc}
|
| 49 |
except Exception as e:
|
| 50 |
+
return {"error": str(e)}
|