-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
95 lines (78 loc) · 3.02 KB
/
main.py
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
import pandas as pd
import streamlit as st
import os
import time
from util import process_dataset, overall_class_stats
st.set_page_config(layout="wide")
# Initialize session state for dataframe
if 'df' not in st.session_state:
st.session_state.df = None
# File uploader
uploaded = st.file_uploader(label='Upload the CSV file', type='csv')
if uploaded is not None:
with st.spinner("Processing"):
df = process_dataset(uploaded)
# Handle processing errors
if isinstance(df, str):
st.error(df)
else:
message_placeholder = st.empty()
message_placeholder.success('File successfully uploaded and processed.')
time.sleep(3)
message_placeholder.empty() # Clear the success message after 3 seconds
st.session_state.df = df
# Sidebar for filtering
st.sidebar.header("Filter :")
col1, col2 = st.sidebar.columns(2)
if 'class_type' not in st.session_state:
st.session_state.class_type = df["Overall class"].unique().tolist()
# Select All and Clear All buttons
if col1.button("Select All"):
st.session_state.class_type = df["Overall class"].unique().tolist()
if col2.button("Clear All"):
st.session_state.class_type = []
# Multiselect for class filtering
class_type = st.sidebar.multiselect(
"Select the Overall class:",
options=df["Overall class"].unique(),
default=st.session_state.class_type
)
# Display filtered dataframe preview
df_preview = df[df["Overall class"].isin(class_type)].head()
if df_preview.empty:
st.warning("No data available based on the current filters!")
st.stop()
st.dataframe(df_preview)
# Create download button for processed dataset
original_filename = os.path.splitext(uploaded.name)[0]
processed_filename = f"{original_filename}_processed.csv"
csv = df.to_csv(index=False)
st.download_button(
label="Download Processed Dataset",
data=csv,
file_name=processed_filename,
mime="text/csv",
)
# Navigation buttons
col1, col2, col3,col4 = st.columns(4)
with col1:
if col1.button("View Plots"):
st.switch_page("pages/1_Plots.py")
with col2:
if col2.button("View EDA"):
st.switch_page("pages/2_EDA.py")
with col3:
if col3.button("Prone Time Visualization"):
st.switch_page("pages/3_Prone.py")
with col4:
if col4.button("Sensor Data Over Time"):
st.switch_page("pages/4_Sensor Data Over Time.py")
### Depreciated : Only for inital analysis done using jupyter notebook
# with col3:
# if col3.button("View Blocks"):
# st.switch_page("pages/3_Blocks.py")
# with col4:
# if col4.button("View Blocks Over Time Plot"):
# st.switch_page("pages/4_Blocks_Over_Time.py")
else:
st.warning("Please upload a CSV file to get started.")