Spaces:
Configuration error
Configuration error
File size: 5,769 Bytes
8a0e083 |
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 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 |
# src/llmguardian/dashboard/app.py
import streamlit as st
import plotly.express as px
import pandas as pd
from datetime import datetime, timedelta
from typing import Dict, List, Any
from ..core.config import Config
from ..data.privacy_guard import PrivacyGuard
from ..monitors.usage_monitor import UsageMonitor
from ..vectors.vector_scanner import VectorScanner
class LLMGuardianDashboard:
def __init__(self):
self.config = Config()
self.privacy_guard = PrivacyGuard()
self.usage_monitor = UsageMonitor()
self.vector_scanner = VectorScanner()
def run(self):
st.set_page_config(page_title="LLMGuardian Dashboard", layout="wide")
st.title("LLMGuardian Security Dashboard")
# Sidebar navigation
page = st.sidebar.selectbox(
"Navigation",
["Overview", "Privacy Monitor", "Vector Security", "Usage Stats", "Settings"]
)
if page == "Overview":
self._render_overview()
elif page == "Privacy Monitor":
self._render_privacy_monitor()
elif page == "Vector Security":
self._render_vector_security()
elif page == "Usage Stats":
self._render_usage_stats()
elif page == "Settings":
self._render_settings()
def _render_overview(self):
col1, col2, col3 = st.columns(3)
with col1:
st.metric(
"Privacy Violations",
self._get_privacy_violations_count(),
self._get_privacy_violations_delta()
)
with col2:
st.metric(
"Security Score",
f"{self._calculate_security_score()}%",
self._get_security_score_delta()
)
with col3:
st.metric(
"Active Monitors",
self._get_active_monitors_count()
)
# Security alerts
st.subheader("Recent Security Alerts")
alerts = self._get_recent_alerts()
for alert in alerts:
st.error(alert)
# Usage trends
st.subheader("Usage Trends")
fig = self._create_usage_trend_chart()
st.plotly_chart(fig, use_container_width=True)
def _render_privacy_monitor(self):
st.subheader("Privacy Monitoring")
# Privacy violations by category
violations_df = self._get_privacy_violations_data()
fig = px.pie(violations_df, values='count', names='category',
title='Privacy Violations by Category')
st.plotly_chart(fig)
# Privacy rules status
st.subheader("Privacy Rules Status")
rules_df = self._get_privacy_rules_status()
st.dataframe(rules_df)
# Real-time monitoring
st.subheader("Real-time Privacy Monitoring")
if st.button("Check Privacy Now"):
self._run_privacy_check()
def _render_vector_security(self):
st.subheader("Vector Security Analysis")
# Vector anomalies
anomalies_df = self._get_vector_anomalies()
st.dataframe(anomalies_df)
# Vector clustering visualization
fig = self._create_vector_cluster_chart()
st.plotly_chart(fig)
# Scan vectors
st.subheader("Vector Scanner")
if st.button("Scan Vectors"):
self._run_vector_scan()
def _render_usage_stats(self):
st.subheader("System Usage Statistics")
# Resource usage
col1, col2, col3 = st.columns(3)
with col1:
st.metric("CPU Usage", f"{self._get_cpu_usage()}%")
with col2:
st.metric("Memory Usage", f"{self._get_memory_usage()}%")
with col3:
st.metric("Request Rate", f"{self._get_request_rate()}/min")
# Usage history
st.line_chart(self._get_usage_history())
def _render_settings(self):
st.subheader("LLMGuardian Settings")
# Config sections
with st.expander("Security Settings"):
self._render_security_settings()
with st.expander("Privacy Settings"):
self._render_privacy_settings()
with st.expander("Monitoring Settings"):
self._render_monitoring_settings()
def _calculate_security_score(self) -> float:
# Implementation of security score calculation
return 85.5
def _get_privacy_violations_count(self) -> int:
# Get privacy violations count
return len(self.privacy_guard.check_history)
def _get_recent_alerts(self) -> List[str]:
# Get recent security alerts
return ["Critical: High risk privacy violation detected",
"Warning: Unusual vector pattern detected"]
def _create_usage_trend_chart(self):
# Create usage trend visualization
df = pd.DataFrame({
'timestamp': pd.date_range(start='2024-01-01', periods=10),
'value': [10, 15, 13, 17, 20, 25, 30, 35, 45, 50]
})
return px.line(df, x='timestamp', y='value', title='Usage Trend')
def _get_vector_anomalies(self) -> pd.DataFrame:
# Get vector anomalies data
return pd.DataFrame({
'timestamp': ['2024-01-01', '2024-01-02'],
'type': ['outlier', 'cluster'],
'severity': ['high', 'medium']
})
def _run_privacy_check(self):
st.info("Running privacy check...")
# Implement privacy check logic
st.success("Privacy check completed")
def _run_vector_scan(self):
st.info("Scanning vectors...")
# Implement vector scan logic
st.success("Vector scan completed")
if __name__ == "__main__":
dashboard = LLMGuardianDashboard()
dashboard.run() |