Spaces:
Sleeping
Sleeping
File size: 3,891 Bytes
6bc6b8f dfd0247 6bc6b8f cbc4d80 6bc6b8f cbc4d80 6bc6b8f cbc4d80 6bc6b8f cbc4d80 6bc6b8f cbc4d80 |
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 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
import streamlit as st
import pandas as pd
import traceback
import sys
from st_aggrid import AgGrid
from st_aggrid.grid_options_builder import GridOptionsBuilder
from st_aggrid.shared import JsCode
from download import download_button
from st_aggrid import GridUpdateMode, DataReturnMode
# Page config is set once with icon title and display style. Wide mode since we want screen real estate for wide CSV files
st.set_page_config(page_icon="๐", page_title="๐AI-EIO-Editor๐", layout="wide")
def parse(file, condition, data=[], ind_append=False):
for line in file:
st.write(line)
data.append(line)
return data
def read_csv_any_file(file):
dropBlanks=True
logResult=True
logResultStartSymbol = "["
if file is not None:
data = []
df = pd.DataFrame()
for line in file:
if line == b' \r\n':
if dropBlanks == False:
st.write(line.decode('UTF-8'))
else:
if logResult:
st.write(line.decode('UTF-8'))
data.append(line.decode('UTF-8'))
df = pd.DataFrame(data, columns=['InputLines'])
return df
# Style
def _max_width_():
max_width_str = f"max-width: 1800px;"
st.markdown(
f"""
<style>
.reportview-container .main .block-container{{
{max_width_str}
}}
</style>
""",
unsafe_allow_html=True,
)
# Title Bar with Images and Icons
col1, col2, col3 = st.columns([1,6,1])
with col1:
st.image("https://cdnb.artstation.com/p/assets/images/images/054/910/875/large/aaron-wacker-cyberpunk-computer-brain-design.jpg?1665656558",width=64,)
with col2:
st.title("๐Double Line AI Editor๐")
with col3:
st.image("https://cdna.artstation.com/p/assets/images/images/054/910/878/large/aaron-wacker-cyberpunk-computer-devices-iot.jpg?1665656564",width=64,)
# Upload
c29, c30, c31 = st.columns([1, 6, 1])
with c30:
uploaded_file = st.file_uploader("", key="1", help="To activate 'wide mode', go to the menu > Settings > turn on 'wide mode'",)
if uploaded_file is not None:
file_container = st.expander("Check your uploaded .csv")
#try:
shows = read_csv_any_file(uploaded_file)
#shows = pd.read_csv(uploaded_file)
#except:
# print(sys.exc_info()[2])
uploaded_file.seek(0)
file_container.write(shows)
else:
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)""")
st.stop()
# DisplayGrid
#gb = GridOptionsBuilder.from_dataframe(shows)
#z = [[" ".join(i.split()[:2]),str(i.split()[2])] for i in shows]
#df = pd.DataFrame(z,columns=['Str','Str2'])
gb = GridOptionsBuilder.from_dataframe(shows)
gb.configure_default_column(enablePivot=True, enableValue=True, enableRowGroup=True)
gb.configure_selection(selection_mode="multiple", use_checkbox=True)
gb.configure_side_bar()
gridOptions = gb.build()
st.success(f"""๐ก Tip! Hold shift key when selecting rows to select multiple rows at once.""")
response = AgGrid(
shows,
gridOptions=gridOptions,
enable_enterprise_modules=True,
update_mode=GridUpdateMode.MODEL_CHANGED,
data_return_mode=DataReturnMode.FILTERED_AND_SORTED,
fit_columns_on_grid_load=False,
)
# Filters
df = pd.DataFrame(response["selected_rows"])
st.subheader("Filtered data will appear below ๐ ")
st.text("")
st.table(df)
st.text("")
# Download
c29, c30, c31 = st.columns([1, 1, 2])
with c29:
CSVButton = download_button(df,"Dataset.csv","Download CSV file",)
with c30:
CSVButton = download_button(df,"Dataset.txt","Download TXT file",)
|