Canstralian commited on
Commit
226a637
·
verified ·
1 Parent(s): fac4417

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +75 -0
app.py ADDED
@@ -0,0 +1,75 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import streamlit as st
3
+ import pandas as pd
4
+ import matplotlib.pyplot as plt
5
+ import dask.dataframe as dd
6
+ from dotenv import load_dotenv
7
+ from itertools import combinations
8
+ from collections import defaultdict
9
+
10
+ # Load environment variables
11
+ load_dotenv()
12
+
13
+ # Configuration from environment variables
14
+ FILE_UPLOAD_LIMIT = int(os.getenv('FILE_UPLOAD_LIMIT', 200))
15
+ EXECUTION_TIME_LIMIT = int(os.getenv('EXECUTION_TIME_LIMIT', 300))
16
+ RESOURCE_LIMIT = int(os.getenv('RESOURCE_LIMIT', 1024)) # in MB
17
+ DATA_DIR = os.getenv('DATA_DIR', './data')
18
+ CONFIG_FLAG = os.getenv('CONFIG_FLAG', 'default')
19
+
20
+ # Main application logic
21
+ def main():
22
+ st.title("CyberOps Dashboard")
23
+
24
+ # Sidebar for user inputs
25
+ st.sidebar.header("Options")
26
+
27
+ # Option to select a CSV file
28
+ uploaded_file = st.sidebar.file_uploader("Select a CSV file:", type=["csv"])
29
+
30
+ if uploaded_file:
31
+ @st.cache_data
32
+ def load_csv(file):
33
+ return pd.read_csv(file)
34
+
35
+ @st.cache_data
36
+ def load_dask_csv(file):
37
+ return dd.read_csv(file)
38
+
39
+ if os.path.getsize(uploaded_file) < RESOURCE_LIMIT * 1024 * 1024:
40
+ df = load_csv(uploaded_file)
41
+ else:
42
+ df = load_dask_csv(uploaded_file)
43
+
44
+ if not df.empty:
45
+ st.write("Data Preview:")
46
+ st.dataframe(df.compute() if isinstance(df, dd.DataFrame) else df)
47
+
48
+ # Select columns for plotting
49
+ x_column = st.sidebar.selectbox('Select X-axis:', df.columns)
50
+ y_column = st.sidebar.selectbox('Select Y-axis:', df.columns)
51
+
52
+ # Plotting
53
+ fig, ax = plt.subplots()
54
+ ax.plot(df[x_column], df[y_column], marker='o')
55
+ ax.set_xlabel(x_column)
56
+ ax.set_ylabel(y_column)
57
+ ax.set_title(f"{y_column} vs {x_column}")
58
+ st.pyplot(fig)
59
+
60
+ # Combinatorial analysis
61
+ col_combinations = st.sidebar.multiselect('Select columns for combinations:', df.columns)
62
+ if col_combinations:
63
+ st.write("Column Combinations:")
64
+ comb = list(combinations(col_combinations, 2))
65
+ st.write(comb)
66
+
67
+ # Grouping and aggregation
68
+ group_by_column = st.sidebar.selectbox('Select column to group by:', df.columns)
69
+ if group_by_column:
70
+ grouped_df = df.groupby(group_by_column).agg(list)
71
+ st.write("Grouped Data:")
72
+ st.dataframe(grouped_df.compute() if isinstance(grouped_df, dd.DataFrame) else grouped_df)
73
+
74
+ if __name__ == "__main__":
75
+ main()