williambr commited on
Commit
7f68f20
โ€ข
1 Parent(s): 90b45fc

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +76 -0
app.py ADDED
@@ -0,0 +1,76 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pandas as pd
3
+ from st_aggrid import AgGrid
4
+ from st_aggrid.grid_options_builder import GridOptionsBuilder
5
+ from st_aggrid.shared import JsCode
6
+ from download import download_button
7
+ from st_aggrid import GridUpdateMode, DataReturnMode
8
+
9
+ # Page config is set once with icon title and display style. Wide mode since we want screen real estate for wide CSV files
10
+ st.set_page_config(page_icon="๐Ÿ“", page_title="๐Ÿ“CSV Data Analyzer๐Ÿ“Š", layout="wide")
11
+
12
+ # Style
13
+ def _max_width_():
14
+ max_width_str = f"max-width: 1800px;"
15
+ st.markdown(
16
+ f"""
17
+ <style>
18
+ .reportview-container .main .block-container{{
19
+ {max_width_str}
20
+ }}
21
+ </style>
22
+ """,
23
+ unsafe_allow_html=True,
24
+ )
25
+
26
+ # Title Bar with Images and Icons
27
+ col1, col2, col3 = st.columns([1,6,1])
28
+ with col1:
29
+ st.image("https://cdnb.artstation.com/p/assets/images/images/054/910/875/large/aaron-wacker-cyberpunk-computer-brain-design.jpg?1665656558",width=80,)
30
+ with col2:
31
+ st.title("๐Ÿ“ CSV Data Analyzer ๐Ÿ“Š")
32
+ with col3:
33
+ st.image("https://cdna.artstation.com/p/assets/images/images/054/910/878/large/aaron-wacker-cyberpunk-computer-devices-iot.jpg?1665656564",width=80,)
34
+
35
+ # Upload
36
+ c29, c30, c31 = st.columns([1, 6, 1])
37
+ with c30:
38
+ uploaded_file = st.file_uploader("", key="1", help="To activate 'wide mode', go to the menu > Settings > turn on 'wide mode'",)
39
+ if uploaded_file is not None:
40
+ file_container = st.expander("Check your uploaded .csv")
41
+ shows = pd.read_csv(uploaded_file)
42
+ uploaded_file.seek(0)
43
+ file_container.write(shows)
44
+ else:
45
+ st.info(f"""โฌ†๏ธUpload a ๐Ÿ“.CSV file. Examples: [Chatbot](https://huggingface.co/datasets/awacke1/Carddata.csv) [Mindfulness](https://huggingface.co/datasets/awacke1/MindfulStory.csv) [Wikipedia](https://huggingface.co/datasets/awacke1/WikipediaSearch)""")
46
+ st.stop()
47
+
48
+ # DisplayGrid
49
+ gb = GridOptionsBuilder.from_dataframe(shows)
50
+ gb.configure_default_column(enablePivot=True, enableValue=True, enableRowGroup=True)
51
+ gb.configure_selection(selection_mode="multiple", use_checkbox=True)
52
+ gb.configure_side_bar()
53
+ gridOptions = gb.build()
54
+ st.success(f"""๐Ÿ’ก Tip! Hold shift key when selecting rows to select multiple rows at once.""")
55
+ response = AgGrid(
56
+ shows,
57
+ gridOptions=gridOptions,
58
+ enable_enterprise_modules=True,
59
+ update_mode=GridUpdateMode.MODEL_CHANGED,
60
+ data_return_mode=DataReturnMode.FILTERED_AND_SORTED,
61
+ fit_columns_on_grid_load=False,
62
+ )
63
+
64
+ # Filters
65
+ df = pd.DataFrame(response["selected_rows"])
66
+ st.subheader("Filtered data will appear below ๐Ÿ“Š ")
67
+ st.text("")
68
+ st.table(df)
69
+ st.text("")
70
+
71
+ # Download
72
+ c29, c30, c31 = st.columns([1, 1, 2])
73
+ with c29:
74
+ CSVButton = download_button(df,"Dataset.csv","Download CSV file",)
75
+ with c30:
76
+ CSVButton = download_button(df,"Dataset.txt","Download TXT file",)