import streamlit as st from parse_logs import parse_log_file from detect import load_model, detect_anomaly import matplotlib.pyplot as plt st.set_page_config(page_title="LogShield - AI-Powered Log Anomaly Detector") st.title("🔒 LogShield - AI-Powered Log Anomaly Detector") uploaded_file = st.file_uploader("📁 Upload your log file (.txt):", type="txt") if uploaded_file: st.success("✅ File Uploaded Successfully!") logs = parse_log_file(uploaded_file.read()) st.write(f"Total Log Lines: {len(logs)}") with st.spinner("Analyzing Logs..."): model = load_model() results = detect_anomaly(model, logs) # Display results anomaly_count = results.count("Anomaly") normal_count = results.count("Normal") st.subheader("🚨 Anomaly Detection Results:") for log, result in zip(logs, results): color = "red" if result == "Anomaly" else "green" st.markdown(f"{result}: {log}", unsafe_allow_html=True) # Display Summary st.subheader("🔍 Summary Chart") fig, ax = plt.subplots() ax.bar(["Normal", "Anomaly"], [normal_count, anomaly_count], color=["green", "red"]) ax.set_ylabel("Count") ax.set_title("Log Summary") st.pyplot(fig)