Spaces:
Build error
Build error
| # How can I add row to an iterable dataset | |
| #π€Datasets | |
| #This is the first time xbilek25 has posted β letβs welcome them to our community! | |
| #xbilek25 | |
| #2 | |
| #9h | |
| #I need any working option to add row to a dataset, where streaming=True. While working with normal dataset I define new item and use code like this: | |
| #tmp_dataset = tmp_dataset.add_item(new_item), but i canβt figure out how to do this while my dataset is streaming=True. | |
| #Can anyone help me to find solution, please? | |
| import streamlit as st | |
| st.set_page_config(page_icon="π", page_title="πAI-EIO-Editorπ", layout="wide") | |
| if st.checkbox('Show Anatomy Table'): | |
| st.markdown(""" | |
| ## Anatomy Head to Toe Table with Body Organs Costly Conditions, Spending, CPT Codes and Frequency | |
| | Table Num | Body Part | Organ/Part | Description | π Costly Condition | π° Spending (billions) | CPT Range Start | CPT Range Finish | Frequency | | |
| |-----------|------------------|----------------------|-------------------------------|------------------------------|------------------------|-----------------|------------------|----------------| | |
| | 1 | π§ Head | π§ Brain | Controls mental processes | π¨ Anxiety & Depression | 210 | 90791 | 90899 | 1 in 5 | | |
| | 2 | π Eyes | ποΈ Optic Nerve | Vision | π Cataracts | 10.7 | 92002 | 92499 | 1 in 6 (over 40 years) | | |
| | 3 | π Ears | π Cochlea | Hearing | π’ Hearing Loss | 7.1 | 92502 | 92700 | 1 in 8 (over 12 years) | | |
| | 4 | π Nose | π Olfactory Bulb | Smell | π€§ Allergies | 25 | 31231 | 31294 | 1 in 3 | | |
| | 5 | π Mouth | π Tongue | Taste | π¦· Dental Issues | 130 | 00100 | 00192 | 1 in 2 | | |
| | 6 | π« Neck | π¦ Thyroid | Metabolism | π¦ Hypothyroidism | 3.1 | 60210 | 60271 | 1 in 20 | | |
| | 7 | πͺ Upper Body | β€οΈ Heart | Circulation | π Heart Disease | 230 | 92920 | 93799 | 1 in 4 (over 65 years) | | |
| | 8 | πͺ Upper Body | π« Lungs | Respiration | π· Chronic Obstructive Pulmonary Disease | 70 | 94002 | 94799 | 1 in 20 (over 45 years) | | |
| | 9 | πͺ Upper Body | π· Liver | Detoxification | πΊ Liver Disease | 40 | 47000 | 47999 | 1 in 10 | | |
| | 10 | πͺ Upper Body | πΉ Kidneys | Filtration | π Chronic Kidney Disease | 110 | 50010 | 50999 | 1 in 7 | | |
| | 11 | πͺ Upper Body | π Pancreas | Insulin secretion | π¬ Diabetes | 327 | 48100 | 48999 | 1 in 10 | | |
| | 12 | πͺ Upper Body | π½οΈ Stomach | Digestion | π₯ Gastroesophageal Reflux Disease | 17 | 43200 | 43289 | 1 in 5 | | |
| | 13 | πͺ Upper Body | π‘οΈ Spleen | Immune functions | π©Έ Anemia | 5.6 | 38100 | 38199 | 1 in 6 | | |
| | 14 | πͺ Upper Body | π« Blood Vessels | Circulation of blood | π Hypertension | 55 | 40110 | 40599 | 1 in 3 | | |
| | 15 | 𦡠Lower Body | π Colon | Absorption of water, minerals | π Colorectal Cancer | 14 | 45378 | 45378 | 1 in 23 | | |
| | 16 | 𦡠Lower Body | π½ Bladder | Urine excretion | π§ Urinary Incontinence | 8 | 51700 | 51798 | 1 in 4 (over 65 years) | | |
| | 17 | 𦡠Lower Body | π Reproductive Organs | Sex hormone secretion | ποΈ Endometriosis | 22 | 56405 | 58999 | 1 in 10 (women) | | |
| | 18 | π¦Ά Feet | π― Nerve endings | Balance and movement | π€ Peripheral Neuropathy | 19 | 95900 | 96004 | 1 in 30 | | |
| | 19 | π¦Ά Feet | π‘οΈ Skin | Temperature regulation | π Skin Cancer | 8.1 | 96910 | 96999 | 1 in 5 | | |
| | 20 | π¦Ά Feet | πͺ Muscles | Movement and strength | ποΈββοΈ Musculoskeletal Disorders | 176 | 97110 | 97799 | 1 in 2 | | |
| """) | |
| 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 st_aggrid import GridUpdateMode, DataReturnMode | |
| 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("") | |
| import base64 | |
| import pandas as pd | |
| # Example DataFrame | |
| data = {'Column1': [1, 2], 'Column2': [3, 4]} | |
| df = pd.DataFrame(data) | |
| # Function to convert DataFrame to CSV and then encode to base64 | |
| def to_base64_csv(df): | |
| csv = df.to_csv(index=False) | |
| b64 = base64.b64encode(csv.encode()).decode() | |
| return f"data:text/csv;base64,{b64}" | |
| # Function to convert DataFrame to TXT and then encode to base64 | |
| def to_base64_txt(df): | |
| txt = df.to_csv(index=False, sep='\t') | |
| b64 = base64.b64encode(txt.encode()).decode() | |
| return f"data:text/plain;base64,{b64}" | |
| # Generate base64 encoded links | |
| csv_link = to_base64_csv(df) | |
| txt_link = to_base64_txt(df) | |
| # Markdown format for hyperlinks in bold font with emojis | |
| markdown_csv_link = f"**[π₯ Download Dataset as CSV]({csv_link})**" | |
| markdown_txt_link = f"**[π₯ Download Dataset as TXT]({txt_link})**" | |
| # Display as markdown (hypothetical, depends on how you render markdown in your application) | |
| print(markdown_csv_link) | |
| print(markdown_txt_link) | |
| st.markdown(markdown_csv_link, unsafe_allow_html=True) | |
| st.markdown(markdown_txt_link, unsafe_allow_html=True) | |
| #----------------------------------------------------------------------- | |
| import streamlit as st | |
| import pandas as pd | |
| # Load dataset | |
| def load_data(): | |
| return pd.read_csv('anatomy_dataset.csv') | |
| # Save dataset | |
| def save_data(df): | |
| df.to_csv('anatomy_dataset.csv', index=False) | |
| # CRUD Operations | |
| def add_data(df): | |
| # Add a row to the dataframe (Example) | |
| # You can modify this function to take input from the user | |
| new_row = {'Table Num': 21, 'Body Part': 'New Part', 'Organ/Part': 'New Organ', 'Description': 'New Description', | |
| 'Costly Condition': 'New Condition', 'Spending (billions)': 0, 'CPT Range Start': 0, 'CPT Range Finish': 0, | |
| 'Frequency': 'New Frequency'} | |
| df = df.append(new_row, ignore_index=True) | |
| return df | |
| def update_data(df): | |
| # Update a row in the dataframe (Example) | |
| # Implement the update logic based on your requirements | |
| if not df.empty: | |
| df.at[0, 'Description'] = 'Updated Description' | |
| return df | |
| def delete_data(df): | |
| # Delete a row from the dataframe (Example) | |
| # Implement the delete logic based on your requirements | |
| if not df.empty: | |
| df = df.drop(df.index[0]) | |
| return df | |
| # Streamlit UI | |
| st.title("Anatomy Head to Toe CRUD Operations") | |
| # Display the table if checkbox is checked | |
| if st.checkbox('Show Anatomy Table as Dataframe'): | |
| df = load_data() | |
| st.markdown("## Anatomy Head to Toe Table with Body Organs Costly Conditions, Spending, CPT Codes and Frequency") | |
| st.dataframe(df) | |
| # CRUD operation buttons | |
| col1, col2, col3, col4 = st.columns(4) | |
| if col1.button('β Add'): | |
| df = load_data() | |
| df = add_data(df) | |
| save_data(df) | |
| if col2.button('π Update'): | |
| df = load_data() | |
| df = update_data(df) | |
| save_data(df) | |
| if col3.button('β Delete'): | |
| df = load_data() | |
| df = delete_data(df) | |
| save_data(df) | |
| if col4.button('πΎ Save'): | |
| df = load_data() | |
| save_data(df) | |
| st.success("Data saved to CSV!") | |