NexusInstruments commited on
Commit
ac88c70
·
verified ·
1 Parent(s): 5424273

Create LocalScripts.py

Browse files
Files changed (1) hide show
  1. pages/LocalScripts.py +66 -0
pages/LocalScripts.py ADDED
@@ -0,0 +1,66 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import sys, os, hashlib
3
+
4
+ # ─── Ensure utils/ is importable ──────────────────────────────
5
+ UTILS_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
6
+ if UTILS_PATH not in sys.path:
7
+ sys.path.append(UTILS_PATH)
8
+
9
+ from utils.docgen import generate_doc
10
+ from utils.summarizer import summarize_text
11
+
12
+ st.title("📂 Local Script Ingestion")
13
+ st.write("Automatically scan and document Omniscient scripts from `/opt/omniscient`.")
14
+
15
+ # Init state
16
+ if "local_scripts" not in st.session_state:
17
+ st.session_state.local_scripts = []
18
+
19
+ # Directories to scan
20
+ SCAN_DIRS = [
21
+ "/opt/omniscient/bin",
22
+ "/opt/omniscient/scripts",
23
+ "/opt/omniscient/ai"
24
+ ]
25
+
26
+ def scan_scripts():
27
+ scripts = []
28
+ for d in SCAN_DIRS:
29
+ if os.path.exists(d):
30
+ for root, _, files in os.walk(d):
31
+ for f in files:
32
+ if f.endswith((".sh", ".py")):
33
+ path = os.path.join(root, f)
34
+ try:
35
+ with open(path, "r", errors="ignore") as fh:
36
+ content = fh.read()
37
+ sha1 = hashlib.sha1(content.encode()).hexdigest()
38
+ doc = generate_doc(f, path, content)
39
+ summary = summarize_text(content)
40
+
41
+ scripts.append({
42
+ "name": f,
43
+ "path": path,
44
+ "sha1": sha1,
45
+ "doc": doc,
46
+ "summary": summary
47
+ })
48
+ except Exception as e:
49
+ st.error(f"⚠️ Error reading {f}: {e}")
50
+ return scripts
51
+
52
+ # Run scanner
53
+ if st.button("🔍 Scan Local Scripts"):
54
+ scripts = scan_scripts()
55
+ if scripts:
56
+ st.session_state.local_scripts = scripts
57
+ st.success(f"✅ Found {len(scripts)} scripts.")
58
+ else:
59
+ st.warning("No scripts found in scan directories.")
60
+
61
+ # Display results
62
+ if st.session_state.local_scripts:
63
+ for s in st.session_state.local_scripts:
64
+ st.subheader(f"📄 {s['name']} ({s['sha1'][:8]})")
65
+ st.markdown(s["doc"])
66
+ st.write("🧠 Summary:", s["summary"])