Canstralian's picture
Update app.py
e080f90 verified
raw
history blame
1.74 kB
import os
import streamlit as st
from components.dashboard import Dashboard
from PurpleTeamIDS import analyze_security_log, API_TOKEN
import time
# Must be the first Streamlit command
st.set_page_config(
page_title="Cybersecurity IDS Dashboard",
page_icon="🛡️",
layout="wide",
initial_sidebar_state="expanded"
)
def main():
# Get API token from environment or sidebar securely
api_token = st.sidebar.text_input(
"Hugging Face API Token",
value=os.getenv("HUGGING_FACE_API_TOKEN", API_TOKEN),
type="password",
key="huggingface_api_token"
)
if not api_token or api_token == "your_huggingface_api_token_here":
st.warning("Please enter your Hugging Face API token in the sidebar.")
st.stop()
# Initialize dashboard
dashboard = Dashboard()
# Load custom CSS
css_path = "styles/custom.css"
try:
with open(css_path) as f:
st.markdown(f"<style>{f.read()}</style>", unsafe_allow_html=True)
except FileNotFoundError:
st.error(f"CSS file not found: {css_path}")
# Render main content
dashboard.render_main_content()
# Simulate real-time log analysis
sample_logs = [
"Failed SSH login attempt from IP 192.168.1.10",
"Multiple port scan detected from IP 10.0.0.5",
"Suspicious outbound connection to known malicious IP",
"Brute force attack detected on admin portal"
]
# Process sample logs
for log in sample_logs:
threat_data = analyze_security_log(log)
dashboard.threat_analysis.process_new_threat(threat_data)
time.sleep(2) # Simulate real-time updates
st.experimental_rerun()
if __name__ == "__main__":
main()