jkushwaha commited on
Commit
291559f
·
verified ·
1 Parent(s): 631d564

Update final_code.py

Browse files
Files changed (1) hide show
  1. final_code.py +37 -17
final_code.py CHANGED
@@ -1,6 +1,7 @@
1
  import streamlit as st
2
  import pandas as pd
3
  import os
 
4
 
5
  # Function to get list of document IDs
6
  def get_document_ids():
@@ -9,28 +10,46 @@ def get_document_ids():
9
  return list(set(document_ids))
10
 
11
  # Function to load image based on selected document ID and page number
12
- def load_image(document_id, page_number):
13
- image_path = f'abc/{document_id}_{page_number}.png'
14
- if os.path.exists(image_path):
15
- return image_path
16
  else:
17
  return None
18
 
19
  # Function to load dataframe based on selected document ID
20
- def load_dataframe(document_id):
21
- csv_path = f'abc/{document_id}_1.csv'
22
- if os.path.exists(csv_path):
23
- return pd.read_csv(csv_path)
 
 
 
24
  else:
25
  return None
 
 
 
 
 
 
 
26
 
27
  def main():
 
 
 
 
 
 
 
 
28
  st.set_page_config(layout="wide") # Set layout to wide
29
 
30
  # Slider to adjust the width of the columns
31
  col1_width = st.sidebar.slider("Width of First Column", 0.1, 10.0, 1.0, 0.1)
32
- col2_width = st.sidebar.slider("Width of Second Column", 0.1, 10.0, 3.0, 0.1)
33
- col3_width = st.sidebar.slider("Width of Third Column", 0.1, 10.0, 2.0, 0.1)
34
 
35
  # Divide the screen into three vertical panels with specified widths
36
  col1, col2, col3 = st.columns([col1_width, col2_width, col3_width])
@@ -38,22 +57,23 @@ def main():
38
  # Document Selection Panel
39
  with col1:
40
  st.write("### Document Selection")
41
- document_id = st.selectbox("Select Document ID", options=get_document_ids())
42
- page_number = st.number_input("Page Number", min_value=1, step=1, value=1)
 
43
 
44
  # Display Image Panel
45
  with col2:
46
  st.write("### Display Image")
47
- image_path = load_image(document_id, page_number)
48
- if image_path:
49
- st.image(image_path)
50
  else:
51
  st.write("Image not found")
52
 
53
  # Display DataFrame Panel
54
  with col3:
55
  st.write("### Display DataFrame")
56
- df = load_dataframe(document_id)
57
  if df is not None:
58
  columns_to_display = st.multiselect("Select Columns to Display", df.columns)
59
  if len(columns_to_display) > 0:
@@ -64,4 +84,4 @@ def main():
64
  st.write("DataFrame not found")
65
 
66
  if __name__ == "__main__":
67
- main()
 
1
  import streamlit as st
2
  import pandas as pd
3
  import os
4
+ from glob import glob
5
 
6
  # Function to get list of document IDs
7
  def get_document_ids():
 
10
  return list(set(document_ids))
11
 
12
  # Function to load image based on selected document ID and page number
13
+ def load_image(image_path, document_id, page_number):
14
+ im_path = f"{image_path}{document_id}-{page_number-1}.png"
15
+ if os.path.exists(im_path):
16
+ return im_path
17
  else:
18
  return None
19
 
20
  # Function to load dataframe based on selected document ID
21
+ def load_dataframe(auto_csv_path, document_id, page_number, cols):
22
+ csv_path = glob(f'{auto_csv_path}*{document_id}*auto.csv')
23
+ print(csv_path)
24
+ if len(csv_path)>0:
25
+ auto_df = pd.read_csv(csv_path[0])
26
+ auto_df_page = auto_df[auto_df['Page#']==page_number][cols]
27
+ return auto_df_page
28
  else:
29
  return None
30
+
31
+ def path_setting(inbound_df_path):
32
+ auto_csv_path = 'PhaseData/Batch1/NLP_batch/'
33
+ image_path = 'PhaseData/Data/output/images/'
34
+ inbound_df = pd.read_csv(inbound_df_path)
35
+ pif_list = list(inbound_df.pif_key.values)
36
+ return pif_list, image_path, auto_csv_path
37
 
38
  def main():
39
+ inbound_df_path = 'inbound_issues_tempus_2_q2.csv'
40
+ display_cols = ['Biomarker Name Source', 'Biomarker Test Type', 'NLP Result','NLP Value', 'NLP Variant',
41
+ 'Biomarker Test Result Value Numeric 1', 'Biomarker Test Result Value Unit 1',
42
+ 'Biomarker Test Result Value Numeric 2', 'Biomarker Test Result Value Unit 2',
43
+ 'Biomarker Test Threshold Value Numeric 1', 'Biomarker Test Threshold Value Unit1',
44
+ 'Biomarker Test Threshold Value Numeric 2', 'Biomarker Test Threshold Value Unit2']
45
+ pif_list, image_path, auto_csv_path = path_setting(inbound_df_path)
46
+
47
  st.set_page_config(layout="wide") # Set layout to wide
48
 
49
  # Slider to adjust the width of the columns
50
  col1_width = st.sidebar.slider("Width of First Column", 0.1, 10.0, 1.0, 0.1)
51
+ col2_width = st.sidebar.slider("Width of Second Column", 0.1, 10.0, 6.5, 0.1)
52
+ col3_width = st.sidebar.slider("Width of Third Column", 0.1, 10.0, 5.0, 0.1)
53
 
54
  # Divide the screen into three vertical panels with specified widths
55
  col1, col2, col3 = st.columns([col1_width, col2_width, col3_width])
 
57
  # Document Selection Panel
58
  with col1:
59
  st.write("### Document Selection")
60
+ document_id = st.selectbox("Select Document ID", options=pif_list)
61
+ pages = [int(i.split('-')[-1].split('.')[0]) for i in glob(f"{image_path}{document_id}*.png")]
62
+ page_number = st.number_input("Page Number", min_value=1, max_value=len(pages), step=1, value=1)
63
 
64
  # Display Image Panel
65
  with col2:
66
  st.write("### Display Image")
67
+ im_path = load_image(image_path, document_id, page_number)
68
+ if im_path:
69
+ st.image(im_path)
70
  else:
71
  st.write("Image not found")
72
 
73
  # Display DataFrame Panel
74
  with col3:
75
  st.write("### Display DataFrame")
76
+ df = load_dataframe(auto_csv_path, document_id, page_number, display_cols)
77
  if df is not None:
78
  columns_to_display = st.multiselect("Select Columns to Display", df.columns)
79
  if len(columns_to_display) > 0:
 
84
  st.write("DataFrame not found")
85
 
86
  if __name__ == "__main__":
87
+ main()