Download final_code.py from jkushwaha/streamlit: direct link, hf CLI and curl.
- Browser
- Download file 3.61 kB
-
https://huggingface.co/jkushwaha/streamlit/resolve/main/final_code.py
- Command line
-
hf download hf://jkushwaha/streamlit/final_code.py
-
curl -L -o final_code.py https://huggingface.co/jkushwaha/streamlit/resolve/main/final_code.py
3.61 kB
| import streamlit as st | |
| import pandas as pd | |
| import os | |
| from glob import glob | |
| # Function to get list of document IDs | |
| def get_document_ids(): | |
| # Assuming 'abc' is the folder containing documents | |
| document_ids = [file.split('_')[0] for file in os.listdir('abc') if file.endswith('.png')] | |
| return list(set(document_ids)) | |
| # Function to load image based on selected document ID and page number | |
| def load_image(image_path, document_id, page_number): | |
| im_path = f"{image_path}{document_id}-{page_number-1}.png" | |
| if os.path.exists(im_path): | |
| return im_path | |
| else: | |
| return None | |
| # Function to load dataframe based on selected document ID | |
| def load_dataframe(auto_csv_path, document_id, page_number, cols): | |
| csv_path = glob(f'{auto_csv_path}*{document_id}*auto.csv') | |
| print(csv_path) | |
| if len(csv_path)>0: | |
| auto_df = pd.read_csv(csv_path[0]) | |
| auto_df_page = auto_df[auto_df['Page#']==page_number][cols] | |
| return auto_df_page | |
| else: | |
| return None | |
| def path_setting(inbound_df_path): | |
| auto_csv_path = 'PhaseData/Batch1/NLP_batch/' | |
| image_path = 'PhaseData/Data/output/images/' | |
| inbound_df = pd.read_csv(inbound_df_path) | |
| pif_list = list(inbound_df.pif_key.values) | |
| return pif_list, image_path, auto_csv_path | |
| def main(): | |
| inbound_df_path = 'inbound_issues_tempus_2_q2.csv' | |
| display_cols = ['Biomarker Name Source', 'Biomarker Test Type', 'NLP Result','NLP Value', 'NLP Variant', | |
| 'Biomarker Test Result Value Numeric 1', 'Biomarker Test Result Value Unit 1', | |
| 'Biomarker Test Result Value Numeric 2', 'Biomarker Test Result Value Unit 2', | |
| 'Biomarker Test Threshold Value Numeric 1', 'Biomarker Test Threshold Value Unit1', | |
| 'Biomarker Test Threshold Value Numeric 2', 'Biomarker Test Threshold Value Unit2'] | |
| pif_list, image_path, auto_csv_path = path_setting(inbound_df_path) | |
| st.set_page_config(layout="wide") # Set layout to wide | |
| # Slider to adjust the width of the columns | |
| col1_width = st.sidebar.slider("Width of First Column", 0.1, 10.0, 1.0, 0.1) | |
| col2_width = st.sidebar.slider("Width of Second Column", 0.1, 10.0, 6.5, 0.1) | |
| col3_width = st.sidebar.slider("Width of Third Column", 0.1, 10.0, 5.0, 0.1) | |
| # Divide the screen into three vertical panels with specified widths | |
| col1, col2, col3 = st.columns([col1_width, col2_width, col3_width]) | |
| # Document Selection Panel | |
| with col1: | |
| st.write("### Document Selection") | |
| document_id = st.selectbox("Select Document ID", options=pif_list) | |
| pages = [int(i.split('-')[-1].split('.')[0]) for i in glob(f"{image_path}{document_id}*.png")] | |
| page_number = st.number_input("Page Number", min_value=1, max_value=len(pages), step=1, value=1) | |
| # Display Image Panel | |
| with col2: | |
| st.write("### Display Image") | |
| im_path = load_image(image_path, document_id, page_number) | |
| if im_path: | |
| st.image(im_path) | |
| else: | |
| st.write("Image not found") | |
| # Display DataFrame Panel | |
| with col3: | |
| st.write("### Display DataFrame") | |
| df = load_dataframe(auto_csv_path, document_id, page_number, display_cols) | |
| if df is not None: | |
| columns_to_display = st.multiselect("Select Columns to Display", df.columns) | |
| if len(columns_to_display) > 0: | |
| st.write(df[columns_to_display]) | |
| else: | |
| st.write("No columns selected") | |
| else: | |
| st.write("DataFrame not found") | |
| if __name__ == "__main__": | |
| main() |