NexusInstruments's picture
Update pages/Omnieye.py
0c0c724 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 re
from utils.file_utils import keyword_search
from utils.summarizer import summarize_text
st.title("👁️ Omnieye")
st.write("Keyword/file analyzer module with AI summarization")
# Initialize counters if not set
if "uploaded_files" not in st.session_state:
st.session_state.uploaded_files = []
if "errors" not in st.session_state:
st.session_state.errors = []
uploaded = st.file_uploader("Upload a text/log file", type=["txt", "log"])
if uploaded:
try:
content = uploaded.read().decode("utf-8", errors="ignore")
# Track uploaded file
st.session_state.uploaded_files.append(uploaded.name)
# Keyword search
query = st.text_input("🔍 Search for keyword")
matches = []
if query:
matches = keyword_search(content, query)
st.write(f"Found {len(matches)} matches")
st.code("\n".join(matches[:50]))
# File preview
st.subheader("📋 File Preview")
st.code("\n".join(content.splitlines()[:30]))
# AI Summarization
st.subheader("🧠 AI Summary")
summary = summarize_text(content)
st.write(summary)
# Save results to session state (for Chatbot context)
st.session_state.omnieye_output = {
"file_preview": "\n".join(content.splitlines()[:30]),
"matches": matches[:50],
"summary": summary,
}
except Exception as e:
st.error(f"⚠️ Error processing file: {e}")
st.session_state.errors.append(str(e))