File size: 5,320 Bytes
cad13b9 33fa796 cb51936 cad13b9 2897fa4 cad13b9 64e9b94 cad13b9 cb51936 cad13b9 33fa796 64e9b94 cb51936 64e9b94 cb51936 64e9b94 cb51936 64e9b94 cb51936 64e9b94 cb51936 64e9b94 384dece cb51936 384dece cad13b9 384dece cb51936 64e9b94 cad13b9 cb51936 384dece cb51936 384dece cb51936 384dece cb51936 2897fa4 cb51936 2897fa4 384dece cb51936 384dece cb51936 384dece cb51936 384dece cb51936 384dece cb51936 64e9b94 cb51936 64e9b94 cb51936 384dece 2897fa4 16f92fb cad13b9 2897fa4 64e9b94 |
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 |
import streamlit as st
import pandas as pd
from processor import DataProcessor
from llm_handler import DDoSInference
class DDoSResistanceHelper:
def __init__(self):
"""Initialize the DDoS Resistance Helper app."""
self.setup_streamlit_page()
self.setup_session_state()
self.processor = DataProcessor()
self.llm_handler = DDoSInference()
self.themes = self.define_themes()
def setup_streamlit_page(self):
"""Set up Streamlit page configurations."""
st.set_page_config(
page_title="DDoS Resistance Helper | LLM Network Analyzer",
page_icon="π‘οΈ",
layout="wide"
)
def setup_session_state(self):
"""Initialize necessary session state variables."""
session_keys = [
'chat_history', 'current_file', 'analysis_complete',
'selected_theme', 'preview_data'
]
for key in session_keys:
if key not in st.session_state:
st.session_state[key] = [] if key == 'chat_history' else None if key != 'selected_theme' else 'Light'
def define_themes(self):
"""Define available themes for the app."""
return {
'Light': {
'base': 'light', 'primaryColor': '#3B82F6',
'backgroundColor': '#FFFFFF', 'secondaryBackgroundColor': '#F3F4F6', 'textColor': '#000000'
},
'Dark': {
'base': 'dark', 'primaryColor': '#10B981',
'backgroundColor': '#1F2937', 'secondaryBackgroundColor': '#374151', 'textColor': '#FFFFFF'
},
'Neon': {
'base': 'dark', 'primaryColor': '#22D3EE',
'backgroundColor': '#000000', 'secondaryBackgroundColor': '#1F2937', 'textColor': '#22D3EE'
}
}
def apply_theme(self):
"""Apply the selected theme to the Streamlit app."""
theme = self.themes.get(st.session_state.selected_theme, self.themes['Light'])
st.markdown(f"""
<style>
.stApp {{
background-color: {theme['backgroundColor']};
color: {theme['textColor']};
}}
</style>
""", unsafe_allow_html=True)
def render_theme_selector(self):
"""Render theme selection buttons."""
col1, col2, col3 = st.columns(3)
with col1:
if st.button("π Light"):
st.session_state.selected_theme = 'Light'
self.apply_theme()
with col2:
if st.button("π Dark"):
st.session_state.selected_theme = 'Dark'
self.apply_theme()
with col3:
if st.button("π‘ Neon"):
st.session_state.selected_theme = 'Neon'
self.apply_theme()
def render_file_upload(self):
"""Render file upload section."""
st.title("DDoS Resistance Helper | LLM Network Analyzer")
uploaded_file = st.file_uploader("Upload Data File π", type=['csv'])
if uploaded_file:
st.session_state.current_file = uploaded_file
st.session_state.preview_data = pd.read_csv(uploaded_file).head(5)
if st.button("π Process Data"):
self.process_uploaded_file(uploaded_file)
def process_uploaded_file(self, file):
"""Process the uploaded file and perform analysis."""
try:
with st.spinner("Processing file..."):
df = self.processor.preprocess_data(file)
results = self.llm_handler.process_dataset() # Assuming this method returns results
st.session_state.analysis_complete = True
st.success("Analysis completed!")
except Exception as e:
st.error(f"Error: {e}")
def render_chat_interface(self):
"""Render chat interface in the sidebar."""
st.sidebar.header("π¬ Chat Interface")
for msg in st.session_state.chat_history:
st.sidebar.write(f"[{msg['role'].capitalize()}]: {msg['content']}")
new_chat = st.sidebar.text_input("Ask a question...")
if new_chat:
st.session_state.chat_history.append({"role": "user", "content": new_chat})
response = self.llm_handler.get_chat_response(new_chat)
st.session_state.chat_history.append({"role": "assistant", "content": response})
def render_analysis_interface(self):
"""Render analysis results interface."""
if st.session_state.preview_data is not None:
st.subheader("π Data Preview")
st.dataframe(st.session_state.preview_data)
if st.session_state.analysis_complete:
st.subheader("π Analysis Results")
# Display analysis results (e.g., visualizations)
def main(self):
"""Run the main application."""
self.apply_theme()
# Layout sections
cols = st.columns([2, 1])
with cols[0]:
self.render_file_upload()
with cols[1]:
self.render_analysis_interface()
self.render_chat_interface()
if __name__ == "__main__":
app = DDoSResistanceHelper()
app.main()
|