Spaces:
Runtime error
Runtime error
File size: 3,922 Bytes
642c7c4 740a6e1 5a6eb9d 44806de 5a6eb9d 44806de 3ed79ac 740a6e1 44806de 740a6e1 44806de 740a6e1 44806de 740a6e1 44806de 740a6e1 44806de 740a6e1 44806de 740a6e1 44806de 740a6e1 44806de 740a6e1 44806de 740a6e1 44806de 740a6e1 44806de 740a6e1 44806de 740a6e1 44806de 740a6e1 44806de 740a6e1 44806de 740a6e1 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
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 os, hashlib, re, sys
# ─── Ensure omniscientframework package is importable ────────────────
ROOT_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
PACKAGE_PATH = os.path.abspath(os.path.join(ROOT_PATH, ".."))
if PACKAGE_PATH not in sys.path:
sys.path.insert(0, PACKAGE_PATH)
# ─── Import project utilities ────────────────────────────────────────
from omniscientframework.utils.file_utils import normalize_log_line
from omniscientframework.utils.summarizer import summarize_text
from omniscientframework.utils.docgen import generate_doc
# ─── Page Setup ─────────────────────────────────────────────────────
st.title("📂 AI Bulk Digest")
st.write("Upload multiple files for batch digestion, summarization, and documentation.")
# ─── Initialize Session State ───────────────────────────────────────
for key in ("uploaded_files", "errors", "bulk_digests"):
if key not in st.session_state:
st.session_state[key] = []
# ─── File Upload ────────────────────────────────────────────────────
uploads = st.file_uploader(
"Upload files (scripts, logs, text, PDFs)",
type=["py", "sh", "txt", "log", "pdf"],
accept_multiple_files=True
)
# ─── Bulk Processing Logic ─────────────────────────────────────────
if uploads:
digests = []
for f in uploads:
try:
# Read content
content = f.read().decode("utf-8", errors="ignore")
sha1 = hashlib.sha1(content.encode()).hexdigest()
# File type detection
is_log = f.name.endswith(".log")
is_script = f.name.endswith((".py", ".sh"))
# Normalize log lines
if is_log:
normalized = [normalize_log_line(line) for line in content.splitlines()]
preview = "\n".join(normalized[:30])
else:
preview = "\n".join(content.splitlines()[:30])
# Generate AI summary
summary = summarize_text(content)
# Auto-generate documentation for scripts
doc = generate_doc(f.name, "uploaded", content) if is_script else None
# Build result object
result = {
"name": f.name,
"sha1": sha1,
"preview": preview,
"summary": summary,
"doc": doc,
}
digests.append(result)
# Track file name
st.session_state.uploaded_files.append(f.name)
# ─── Display Results ───────────────────────────────
st.subheader(f"📄 {f.name}")
st.code(preview)
st.markdown(f"**SHA1:** `{sha1}`")
st.write("🧠 **Summary:**", summary)
if doc:
st.write("📘 **Generated Documentation:**")
st.markdown(doc)
except Exception as e:
st.error(f"⚠️ Error processing {f.name}: {e}")
st.session_state.errors.append(str(e))
# Save to session state
st.session_state.bulk_digests = digests
st.success(f"✅ Bulk digestion complete for {len(digests)} files.")
|