omniscientframework / pages /LocalScripts.py
NexusInstruments's picture
Update pages/LocalScripts.py
53d5811 verified
import sys, os
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
UTILS_DIR = os.path.join(BASE_DIR, "utils")
if UTILS_DIR not in sys.path:
sys.path.insert(0, UTILS_DIR)
import streamlit as st
import sys, os, hashlib
# ─── Ensure utils/ is importable ──────────────────────────────
UTILS_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
if UTILS_PATH not in sys.path:
sys.path.append(UTILS_PATH)
from utils.docgen import generate_doc
from utils.summarizer import summarize_text
st.title("📂 Local Script Ingestion")
st.write("Automatically scan and document Omniscient scripts from `/opt/omniscient`.")
# Init state
if "local_scripts" not in st.session_state:
st.session_state.local_scripts = []
# Directories to scan
SCAN_DIRS = [
"/opt/omniscient/bin",
"/opt/omniscient/scripts",
"/opt/omniscient/ai"
]
def scan_scripts():
scripts = []
for d in SCAN_DIRS:
if os.path.exists(d):
for root, _, files in os.walk(d):
for f in files:
if f.endswith((".sh", ".py")):
path = os.path.join(root, f)
try:
with open(path, "r", errors="ignore") as fh:
content = fh.read()
sha1 = hashlib.sha1(content.encode()).hexdigest()
doc = generate_doc(f, path, content)
summary = summarize_text(content)
scripts.append({
"name": f,
"path": path,
"sha1": sha1,
"doc": doc,
"summary": summary
})
except Exception as e:
st.error(f"⚠️ Error reading {f}: {e}")
return scripts
# Run scanner
if st.button("🔍 Scan Local Scripts"):
scripts = scan_scripts()
if scripts:
st.session_state.local_scripts = scripts
st.success(f"✅ Found {len(scripts)} scripts.")
else:
st.warning("No scripts found in scan directories.")
# Display results
if st.session_state.local_scripts:
for s in st.session_state.local_scripts:
st.subheader(f"📄 {s['name']} ({s['sha1'][:8]})")
st.markdown(s["doc"])
st.write("🧠 Summary:", s["summary"])