File size: 4,318 Bytes
9e63941
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
"""
CyberForge Dashboard - Hugging Face Spaces Version
"""
import os
import sys
import streamlit as st
from streamlit_extras.add_vertical_space import add_vertical_space
from streamlit_extras.colored_header import colored_header

# Check if we're running on Hugging Face Spaces
is_huggingface = os.environ.get('SPACE_ID') is not None

# Set the page config
st.set_page_config(
    page_title="CyberForge Dashboard",
    page_icon="πŸ•΅οΈβ€β™‚οΈ",
    layout="wide",
    initial_sidebar_state="expanded"
)

# Add custom CSS
st.markdown("""
<style>
    .stApp {
        background-color: #0e1117;
    }
    .sidebar .sidebar-content {
        background-color: #262730;
    }
    h1, h2, h3 {
        color: #f8f9fa;
    }
    .cybertext {
        color: #00ff8d;
        font-family: monospace;
    }
</style>
""", unsafe_allow_html=True)

# Choose between HF demo mode or regular mode
if is_huggingface:
    # Initialize in-memory database for Hugging Face
    import hf_database
    st.session_state.is_demo = True
    
    # Show demo mode banner
    st.warning("⚠️ Running in Hugging Face Spaces DEMO MODE. Data is stored in-memory and will be reset when the space restarts.")
else:
    # Regular database initialization
    import src.database_init
    
# Import components
from components.dashboard import render_dashboard
from components.threats import render_threats
from components.monitoring import render_monitoring
from components.alerts import render_alerts
from components.reports import render_reports
from components.live_feed import render_live_feed, render_content_analysis
from components.web_scraper import render_web_scraper_ui

# Custom notification function
def add_notification(title, message, severity="info", icon="πŸ””"):
    """Add a notification to the session state"""
    if "notifications" not in st.session_state:
        st.session_state.notifications = []
    
    # Add notification with timestamp
    import time
    notification = {
        "id": int(time.time() * 1000),
        "title": title,
        "message": message,
        "severity": severity,
        "icon": icon,
        "read": False,
        "timestamp": time.time()
    }
    st.session_state.notifications.insert(0, notification)

# Initialize notifications if needed
if "notifications" not in st.session_state:
    st.session_state.notifications = []

# Sidebar navigation
with st.sidebar:
    st.image("assets/cyberforge_logo.svg", width=200)
    st.title("CyberForge")
    
    # Demo badge
    if st.session_state.get("is_demo", False):
        st.markdown("#### πŸ” Demo Mode")
    
    st.markdown("---")
    
    # Navigation
    nav_selection = st.radio(
        "Navigation",
        ["Dashboard", "Threats", "Monitoring", "Alerts", "Reports", "Live Feed", "Content Analysis", "Web Scraper"]
    )
    
    # User information
    st.markdown("---")
    st.markdown("### User Info")
    if st.session_state.get("is_demo", False):
        st.markdown("πŸ‘€ **Admin User** (Demo)")
        st.markdown("πŸ”‘ Role: Administrator")
    else:
        st.markdown("πŸ‘€ **Analyst**")
        st.markdown("πŸ”‘ Role: Security Analyst")
    
    # Notification count
    unread_count = sum(1 for n in st.session_state.notifications if not n["read"])
    if unread_count > 0:
        st.markdown(f"πŸ”” **{unread_count}** unread notifications")
    
    # Credits
    st.markdown("---")
    st.markdown("### CyberForge v1.0")
    st.markdown("Β© 2025 Chemically Motivated Solutions")
    
    # HF badge if on Hugging Face
    if is_huggingface:
        st.markdown("---")
        st.markdown("""
        <a href="https://huggingface.co./spaces" target="_blank">
        <img src="https://img.shields.io/badge/Hosted%20on-HF%20Spaces-blue" alt="HuggingFace Spaces"/>
        </a>
        """, unsafe_allow_html=True)

# Main content area
if nav_selection == "Dashboard":
    render_dashboard()
elif nav_selection == "Threats":
    render_threats()
elif nav_selection == "Monitoring":
    render_monitoring()
elif nav_selection == "Alerts":
    render_alerts()
elif nav_selection == "Reports":
    render_reports()
elif nav_selection == "Live Feed":
    render_live_feed()
elif nav_selection == "Content Analysis":
    render_content_analysis()
elif nav_selection == "Web Scraper":
    render_web_scraper_ui()