Canstralian's picture
Create app.py
226a637 verified
raw
history blame
2.57 kB
import os
import streamlit as st
import pandas as pd
import matplotlib.pyplot as plt
import dask.dataframe as dd
from dotenv import load_dotenv
from itertools import combinations
from collections import defaultdict
# Load environment variables
load_dotenv()
# Configuration from environment variables
FILE_UPLOAD_LIMIT = int(os.getenv('FILE_UPLOAD_LIMIT', 200))
EXECUTION_TIME_LIMIT = int(os.getenv('EXECUTION_TIME_LIMIT', 300))
RESOURCE_LIMIT = int(os.getenv('RESOURCE_LIMIT', 1024)) # in MB
DATA_DIR = os.getenv('DATA_DIR', './data')
CONFIG_FLAG = os.getenv('CONFIG_FLAG', 'default')
# Main application logic
def main():
st.title("CyberOps Dashboard")
# Sidebar for user inputs
st.sidebar.header("Options")
# Option to select a CSV file
uploaded_file = st.sidebar.file_uploader("Select a CSV file:", type=["csv"])
if uploaded_file:
@st.cache_data
def load_csv(file):
return pd.read_csv(file)
@st.cache_data
def load_dask_csv(file):
return dd.read_csv(file)
if os.path.getsize(uploaded_file) < RESOURCE_LIMIT * 1024 * 1024:
df = load_csv(uploaded_file)
else:
df = load_dask_csv(uploaded_file)
if not df.empty:
st.write("Data Preview:")
st.dataframe(df.compute() if isinstance(df, dd.DataFrame) else df)
# Select columns for plotting
x_column = st.sidebar.selectbox('Select X-axis:', df.columns)
y_column = st.sidebar.selectbox('Select Y-axis:', df.columns)
# Plotting
fig, ax = plt.subplots()
ax.plot(df[x_column], df[y_column], marker='o')
ax.set_xlabel(x_column)
ax.set_ylabel(y_column)
ax.set_title(f"{y_column} vs {x_column}")
st.pyplot(fig)
# Combinatorial analysis
col_combinations = st.sidebar.multiselect('Select columns for combinations:', df.columns)
if col_combinations:
st.write("Column Combinations:")
comb = list(combinations(col_combinations, 2))
st.write(comb)
# Grouping and aggregation
group_by_column = st.sidebar.selectbox('Select column to group by:', df.columns)
if group_by_column:
grouped_df = df.groupby(group_by_column).agg(list)
st.write("Grouped Data:")
st.dataframe(grouped_df.compute() if isinstance(grouped_df, dd.DataFrame) else grouped_df)
if __name__ == "__main__":
main()