jkushwaha commited on
Commit
4af6a0b
·
verified ·
1 Parent(s): 72ccfb8

Update on.py

Browse files
Files changed (1) hide show
  1. on.py +110 -0
on.py CHANGED
@@ -0,0 +1,110 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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():
8
+ # Assuming 'abc' is the folder containing documents
9
+ document_ids = [file.split('_')[0] for file in os.listdir('abc') if file.endswith('.png')]
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])
56
+
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
+ # Wrap the image into a vertical slider
70
+ st.slider("", 0, 1, 0, 1, key="image_slider", value=0, orientation='vertical', format="")
71
+ st.image(im_path, use_column_width=True)
72
+ else:
73
+ st.write("Image not found")
74
+
75
+ # Display DataFrame Panel
76
+ with col3:
77
+ st.write("### Display DataFrame")
78
+ df = load_dataframe(auto_csv_path, document_id, page_number, display_cols)
79
+ if df is not None:
80
+ columns_to_display = st.multiselect("Select Columns to Display", df.columns)
81
+ if len(columns_to_display) > 0:
82
+ st.write(df[columns_to_display])
83
+
84
+ # Input area for comments and suggestions
85
+ st.subheader("Comments and Suggestions")
86
+ comment = st.text_area("Add your comment here")
87
+ suggestions = st.text_area("Add your suggestions here")
88
+
89
+ # Save comments and suggestions to CSV when submitted
90
+ if st.button("Submit"):
91
+ data = {
92
+ "Document ID": [document_id],
93
+ "Page": [page_number],
94
+ "Comment": [comment],
95
+ "Suggestions": [suggestions]
96
+ }
97
+ comments_df = pd.DataFrame(data)
98
+ comments_csv = "comments.csv"
99
+ if os.path.exists(comments_csv):
100
+ comments_df.to_csv(comments_csv, mode="a", header=False, index=False)
101
+ else:
102
+ comments_df.to_csv(comments_csv, index=False)
103
+
104
+ else:
105
+ st.write("No columns selected")
106
+ else:
107
+ st.write("DataFrame not found")
108
+
109
+ if __name__ == "__main__":
110
+ main()