awacke1 commited on
Commit
6bc6b8f
ยท
1 Parent(s): 886ae54

Create app.py

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