This is my app the answer will come in form of dataframe make better and ui should be clean and pleasing
To upload files, please first save the app
import streamlit as st
import pandas as pd
import plotly.express as px
from sklearn.preprocessing import LabelEncoder
# Configure page
st.set_page_config(
page_title="SecPen Cybersecurity Threat Classifier",
page_icon="🛡️",
layout="wide"
)
# Custom CSS
st.markdown("""
<style>
.main {
padding: 2rem;
}
.stTitle {
color: #ffffff;
font-size: 2.5rem !important;
padding-bottom: 2rem;
}
.upload-section {
background-color: #1E2130;
padding: 2rem;
border-radius: 10px;
margin-bottom: 2rem;
}
.results-section {
background-color: #1E2130;
padding: 2rem;
border-radius: 10px;
}
</style>
""", unsafe_allow_html=True)
# Title and description
st.title("🛡️ SecPen Cybersecurity Threat Classifier")
st.markdown("Upload a CSV of network flows to predict threat type and analyze patterns.")
# File upload section
with st.container():
st.markdown('<div class="upload-section">', unsafe_allow_html=True)
uploaded_file = st.file_uploader(
"Upload CSV file",
type=['csv'],
help="Upload a CSV file containing network flow features"
)
st.markdown('</div>', unsafe_allow_html=True)
if uploaded_file is not None:
try:
# Load and process data
df = pd.read_csv(uploaded_file)
# Display results in tabs
with st.container():
st.markdown('<div class="results-section">', unsafe_allow_html=True)
tabs = st.tabs(["📊 Data Overview", "📈 Visualizations", "🔍 Detailed Analysis"])
with tabs[0]:
col1, col2 = st.columns(2)
with col1:
st.subheader("Dataset Summary")
st.dataframe(df.describe(), use_container_width=True)
with col2:
st.subheader("Sample Data")
st.dataframe(df.head(), use_container_width=True)
with tabs[1]:
if len(df.select_dtypes(include=['float64', 'int64']).columns) > 0:
numeric_col = st.selectbox(
"Select feature for distribution plot",
df.select_dtypes(include=['float64', 'int64']).columns
)
fig = px.histogram(df, x=numeric_col, title=f'Distribution of {numeric_col}')
st.plotly_chart(fig, use_container_width=True)
with tabs[2]:
st.subheader("Correlation Analysis")
numeric_df = df.select_dtypes(include=['float64', 'int64'])
if not numeric_df.empty:
corr = numeric_df.corr()
fig = px.imshow(
corr,
title="Feature Correlation Matrix",
color_continuous_scale='RdBu'
)
st.plotly_chart(fig, use_container_width=True)
st.markdown('</div>', unsafe_allow_html=True)
except Exception as e:
st.error(f"Error processing file: {str(e)}")
else:
# Show placeholder when no file is uploaded
st.info("Please upload a CSV file containing the network flow features used for prediction.")
Hi! I can help you with any questions about Streamlit and Python. What would you like to know?