Replit Deployment commited on
Commit
9e63941
Β·
1 Parent(s): bb6d7b4

Deployment from Replit

Browse files
Files changed (1) hide show
  1. app.py +146 -0
app.py ADDED
@@ -0,0 +1,146 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ CyberForge Dashboard - Hugging Face Spaces Version
3
+ """
4
+ import os
5
+ import sys
6
+ import streamlit as st
7
+ from streamlit_extras.add_vertical_space import add_vertical_space
8
+ from streamlit_extras.colored_header import colored_header
9
+
10
+ # Check if we're running on Hugging Face Spaces
11
+ is_huggingface = os.environ.get('SPACE_ID') is not None
12
+
13
+ # Set the page config
14
+ st.set_page_config(
15
+ page_title="CyberForge Dashboard",
16
+ page_icon="πŸ•΅οΈβ€β™‚οΈ",
17
+ layout="wide",
18
+ initial_sidebar_state="expanded"
19
+ )
20
+
21
+ # Add custom CSS
22
+ st.markdown("""
23
+ <style>
24
+ .stApp {
25
+ background-color: #0e1117;
26
+ }
27
+ .sidebar .sidebar-content {
28
+ background-color: #262730;
29
+ }
30
+ h1, h2, h3 {
31
+ color: #f8f9fa;
32
+ }
33
+ .cybertext {
34
+ color: #00ff8d;
35
+ font-family: monospace;
36
+ }
37
+ </style>
38
+ """, unsafe_allow_html=True)
39
+
40
+ # Choose between HF demo mode or regular mode
41
+ if is_huggingface:
42
+ # Initialize in-memory database for Hugging Face
43
+ import hf_database
44
+ st.session_state.is_demo = True
45
+
46
+ # Show demo mode banner
47
+ st.warning("⚠️ Running in Hugging Face Spaces DEMO MODE. Data is stored in-memory and will be reset when the space restarts.")
48
+ else:
49
+ # Regular database initialization
50
+ import src.database_init
51
+
52
+ # Import components
53
+ from components.dashboard import render_dashboard
54
+ from components.threats import render_threats
55
+ from components.monitoring import render_monitoring
56
+ from components.alerts import render_alerts
57
+ from components.reports import render_reports
58
+ from components.live_feed import render_live_feed, render_content_analysis
59
+ from components.web_scraper import render_web_scraper_ui
60
+
61
+ # Custom notification function
62
+ def add_notification(title, message, severity="info", icon="πŸ””"):
63
+ """Add a notification to the session state"""
64
+ if "notifications" not in st.session_state:
65
+ st.session_state.notifications = []
66
+
67
+ # Add notification with timestamp
68
+ import time
69
+ notification = {
70
+ "id": int(time.time() * 1000),
71
+ "title": title,
72
+ "message": message,
73
+ "severity": severity,
74
+ "icon": icon,
75
+ "read": False,
76
+ "timestamp": time.time()
77
+ }
78
+ st.session_state.notifications.insert(0, notification)
79
+
80
+ # Initialize notifications if needed
81
+ if "notifications" not in st.session_state:
82
+ st.session_state.notifications = []
83
+
84
+ # Sidebar navigation
85
+ with st.sidebar:
86
+ st.image("assets/cyberforge_logo.svg", width=200)
87
+ st.title("CyberForge")
88
+
89
+ # Demo badge
90
+ if st.session_state.get("is_demo", False):
91
+ st.markdown("#### πŸ” Demo Mode")
92
+
93
+ st.markdown("---")
94
+
95
+ # Navigation
96
+ nav_selection = st.radio(
97
+ "Navigation",
98
+ ["Dashboard", "Threats", "Monitoring", "Alerts", "Reports", "Live Feed", "Content Analysis", "Web Scraper"]
99
+ )
100
+
101
+ # User information
102
+ st.markdown("---")
103
+ st.markdown("### User Info")
104
+ if st.session_state.get("is_demo", False):
105
+ st.markdown("πŸ‘€ **Admin User** (Demo)")
106
+ st.markdown("πŸ”‘ Role: Administrator")
107
+ else:
108
+ st.markdown("πŸ‘€ **Analyst**")
109
+ st.markdown("πŸ”‘ Role: Security Analyst")
110
+
111
+ # Notification count
112
+ unread_count = sum(1 for n in st.session_state.notifications if not n["read"])
113
+ if unread_count > 0:
114
+ st.markdown(f"πŸ”” **{unread_count}** unread notifications")
115
+
116
+ # Credits
117
+ st.markdown("---")
118
+ st.markdown("### CyberForge v1.0")
119
+ st.markdown("Β© 2025 Chemically Motivated Solutions")
120
+
121
+ # HF badge if on Hugging Face
122
+ if is_huggingface:
123
+ st.markdown("---")
124
+ st.markdown("""
125
+ <a href="https://huggingface.co/spaces" target="_blank">
126
+ <img src="https://img.shields.io/badge/Hosted%20on-HF%20Spaces-blue" alt="HuggingFace Spaces"/>
127
+ </a>
128
+ """, unsafe_allow_html=True)
129
+
130
+ # Main content area
131
+ if nav_selection == "Dashboard":
132
+ render_dashboard()
133
+ elif nav_selection == "Threats":
134
+ render_threats()
135
+ elif nav_selection == "Monitoring":
136
+ render_monitoring()
137
+ elif nav_selection == "Alerts":
138
+ render_alerts()
139
+ elif nav_selection == "Reports":
140
+ render_reports()
141
+ elif nav_selection == "Live Feed":
142
+ render_live_feed()
143
+ elif nav_selection == "Content Analysis":
144
+ render_content_analysis()
145
+ elif nav_selection == "Web Scraper":
146
+ render_web_scraper_ui()