From 18bba9579a164b1cc60393000a6c154dea691b9d Mon Sep 17 00:00:00 2001 From: "AARETE\\agupta" Date: Tue, 18 Jun 2024 20:56:09 -0500 Subject: [PATCH] New changes to multipageApp functionality --- streamlit/interface_0.py | 7 +++-- streamlit/interface_1.py | 27 +++++++++--------- streamlit/interface_2.py | 22 +++++++-------- streamlit/multipage/Interface_0.py | 10 +++---- streamlit/multipage/pages/Interface_1.py | 28 +++++++++--------- streamlit/multipage/pages/Interface_2.py | 36 +++++++++++++----------- streamlit/multipage/pages/Interface_3.py | 3 +- 7 files changed, 66 insertions(+), 67 deletions(-) diff --git a/streamlit/interface_0.py b/streamlit/interface_0.py index 26a4b57..a2809f3 100644 --- a/streamlit/interface_0.py +++ b/streamlit/interface_0.py @@ -145,12 +145,13 @@ with buttons[1]: try: batch_id = json.loads(json.loads(response.text)['body'])['batch_id'] landing_zone = json.loads(json.loads(response.text)['body'])['landing_zone'] + landing_zone = 'contracts-landing-zone/' except: # st.write(myobj) # st.write(response.text) st.write("Internal Error. Reach out to Doczy.AI Team.") batch_id = 'failed_cases' - landing_zone = 'contracts-landing-zone' + landing_zone = 'contracts-landing-zone/' else: st.error("Failed") for uploaded_file in file_list: @@ -158,8 +159,8 @@ with buttons[1]: stringio.seek(0) s3_client.put_object(Bucket=client_bucket, Body=stringio.getvalue(), Key= landing_zone+batch_id+'/'+str(uploaded_file.name)) - # s3_client.put_object_tagging(Bucket=client_bucket, Key= - # landing_zone+batch_id+'/'+str(uploaded_file.name), Tagging = {'TagSet': [ { 'Key': 'BatchId', 'Value': batch_id }]}) + s3_client.put_object_tagging(Bucket=client_bucket, Key= + landing_zone+batch_id+'/'+str(uploaded_file.name), Tagging = {'TagSet': [ { 'Key': 'BatchId', 'Value': batch_id }]}) # TODO: Test this insert function with snowflake upload_log = insert_upload_logs(batch_id, client, str(uploaded_file.name), datetime.now().strftime("%Y-%m-%d %H:%M:%S"), user_mail) diff --git a/streamlit/interface_1.py b/streamlit/interface_1.py index d4e3a3b..48fc09d 100644 --- a/streamlit/interface_1.py +++ b/streamlit/interface_1.py @@ -15,21 +15,20 @@ from constants import USER_LIST (REDIRECT_URI, create_batch_url, doczy_pipeline) = util.load_page_details(1) -REDIRECT_URI = 'https://doczydev.aarete.com:8501' user_list = USER_LIST st.set_page_config(layout = "wide") -# # Sidebar contents -# with st.sidebar: -# st.title("Doczy.AI ™") -# st.markdown( -# """ -# ## About -# This app extracts data from contracts +# Sidebar contents +with st.sidebar: + st.title("Doczy.AI ™") + st.markdown( + """ + ## About + This app extracts data from contracts -# """ -# ) -# add_vertical_space(15) -# # st.write("Doczy") + """ + ) + add_vertical_space(15) + # st.write("Doczy") # AARETE LOGO x,y,z = st.columns([15,2,15]) @@ -87,7 +86,7 @@ client_bucket = client_s3_paths.get(client) client_bucket = 'doczy-dev-infra-textract' batch_objects = s3_client.list_objects_v2(Bucket=client_bucket - , Prefix="contracts-landing-zone/", Delimiter='/') + , Prefix="contracts-landing-zone/", Delimiter='/') batch_list = [] for prefix in batch_objects['CommonPrefixes']: @@ -157,7 +156,7 @@ df = pd.DataFrame(columns=['Contract Name', 'Unique Key','Pricing Before Carveou , 'Contract Related', 'Provider', 'Timeline', 'Carveout Indicator', 'Carveout Methodology']) file_list = [] file_objects = s3_client.list_objects_v2(Bucket=client_bucket - , Prefix="contracts_landing_zone/"+batch_id+"/", Delimiter='/') + , Prefix="contracts-landing-zone/"+batch_id+"/", Delimiter='/') # Hardcoded file_list for testing purposes # file_list = ['Boilerplate_TX Amendment Mission Health Network effective_040114 MU.pdf', 'Custom_TX - MP AMENDMENT - MISSION HEALTH NETWORK - MU.pdf', diff --git a/streamlit/interface_2.py b/streamlit/interface_2.py index 5d273fe..a0b8568 100644 --- a/streamlit/interface_2.py +++ b/streamlit/interface_2.py @@ -29,17 +29,17 @@ user_list = USER_LIST st.set_page_config(layout = "wide") # Sidebar contents -# with st.sidebar: -# st.title("Doczy.AI ™") -# st.markdown( -# """ -# ## About -# This app extracts data from contracts +with st.sidebar: + st.title("Doczy.AI ™") + st.markdown( + """ + ## About + This app extracts data from contracts -# """ -# ) -# add_vertical_space(15) -# # st.write("Doczy") + """ + ) + add_vertical_space(15) + # st.write("Doczy") # AARETE LOGO x,y,z = st.columns([15,2,15]) @@ -130,7 +130,7 @@ with path_row[1]: if batch_id: - objects = s3_client.list_objects_v2(Bucket=client_bucket, Prefix="contract-landing-zone/"+batch_id+"/") + objects = s3_client.list_objects_v2(Bucket=client_bucket, Prefix="contracts-landing-zone/"+batch_id+"/") file_list = [] if 'Contents' in objects: for obj in objects['Contents']: diff --git a/streamlit/multipage/Interface_0.py b/streamlit/multipage/Interface_0.py index 24042b6..aab28b8 100644 --- a/streamlit/multipage/Interface_0.py +++ b/streamlit/multipage/Interface_0.py @@ -16,8 +16,7 @@ import time from sf_conn import get_client_names, insert_upload_logs from constants import USER_LIST -(REDIRECT_URI, create_batch_url, doczy_pipeline) = util.load_page_details(0) -REDIRECT_URI = 'https://doczydev.aarete.com:8505' +(REDIRECT_URI, create_batch_url, doczy_pipeline) = util.load_page_details(5) user_list = USER_LIST if 'uploading' not in st.session_state: @@ -146,12 +145,13 @@ with buttons[1]: try: batch_id = json.loads(json.loads(response.text)['body'])['batch_id'] landing_zone = json.loads(json.loads(response.text)['body'])['landing_zone'] + landing_zone = 'contracts-landing-zone/' except: # st.write(myobj) # st.write(response.text) st.write("Internal Error. Reach out to Doczy.AI Team.") batch_id = 'failed_cases' - landing_zone = 'contracts-landing-zone' + landing_zone = 'contracts-landing-zone/' else: st.error("Failed") for uploaded_file in file_list: @@ -159,8 +159,8 @@ with buttons[1]: stringio.seek(0) s3_client.put_object(Bucket=client_bucket, Body=stringio.getvalue(), Key= landing_zone+batch_id+'/'+str(uploaded_file.name)) - # s3_client.put_object_tagging(Bucket=client_bucket, Key= - # landing_zone+batch_id+'/'+str(uploaded_file.name), Tagging = {'TagSet': [ { 'Key': 'BatchId', 'Value': batch_id }]}) + s3_client.put_object_tagging(Bucket=client_bucket, Key= + landing_zone+batch_id+'/'+str(uploaded_file.name), Tagging = {'TagSet': [ { 'Key': 'BatchId', 'Value': batch_id }]}) # TODO: Test this insert function with snowflake upload_log = insert_upload_logs(batch_id, client, str(uploaded_file.name), datetime.now().strftime("%Y-%m-%d %H:%M:%S"), user_mail) diff --git a/streamlit/multipage/pages/Interface_1.py b/streamlit/multipage/pages/Interface_1.py index d79ca67..bc214ee 100644 --- a/streamlit/multipage/pages/Interface_1.py +++ b/streamlit/multipage/pages/Interface_1.py @@ -13,24 +13,22 @@ import time from sf_conn import get_client_names, get_secret, save_to_sf from constants import USER_LIST -(REDIRECT_URI, create_batch_url, doczy_pipeline) = util.load_page_details(1) - -REDIRECT_URI = 'https://doczydev.aarete.com:8505/Interface_1' +(REDIRECT_URI, create_batch_url, doczy_pipeline) = util.load_page_details(5) user_list = USER_LIST st.set_page_config(layout = "wide") -# # Sidebar contents -# with st.sidebar: -# st.title("Doczy.AI ™") -# st.markdown( -# """ -# ## About -# This app extracts data from contracts +# Sidebar contents +with st.sidebar: + st.title("Doczy.AI ™") + st.markdown( + """ + ## About + This app extracts data from contracts -# """ -# ) -# add_vertical_space(15) -# # st.write("Doczy") + """ + ) + add_vertical_space(15) + # st.write("Doczy") # AARETE LOGO x,y,z = st.columns([15,2,15]) @@ -158,7 +156,7 @@ df = pd.DataFrame(columns=['Contract Name', 'Unique Key','Pricing Before Carveou , 'Contract Related', 'Provider', 'Timeline', 'Carveout Indicator', 'Carveout Methodology']) file_list = [] file_objects = s3_client.list_objects_v2(Bucket=client_bucket - , Prefix="contracts_landing_zone/"+batch_id+"/", Delimiter='/') + , Prefix="contracts-landing-zone/"+batch_id+"/", Delimiter='/') # Hardcoded file_list for testing purposes # file_list = ['Boilerplate_TX Amendment Mission Health Network effective_040114 MU.pdf', 'Custom_TX - MP AMENDMENT - MISSION HEALTH NETWORK - MU.pdf', diff --git a/streamlit/multipage/pages/Interface_2.py b/streamlit/multipage/pages/Interface_2.py index d42e15c..59c6a55 100644 --- a/streamlit/multipage/pages/Interface_2.py +++ b/streamlit/multipage/pages/Interface_2.py @@ -24,23 +24,22 @@ from sf_conn import get_snowflake_conn from sf_conn import get_client_names, get_secret, save_to_sf import io -(REDIRECT_URI, create_batch_url, doczy_pipeline) = util.load_page_details(2) -REDIRECT_URI = 'https://doczydev.aarete.com:8505/Interface_2' +(REDIRECT_URI, create_batch_url, doczy_pipeline) = util.load_page_details(5) user_list = USER_LIST st.set_page_config(layout = "wide") # Sidebar contents -# with st.sidebar: -# st.title("Doczy.AI ™") -# st.markdown( -# """ -# ## About -# This app extracts data from contracts +with st.sidebar: + st.title("Doczy.AI ™") + st.markdown( + """ + ## About + This app extracts data from contracts -# """ -# ) -# add_vertical_space(15) -# # st.write("Doczy") + """ + ) + add_vertical_space(15) + # st.write("Doczy") # AARETE LOGO x,y,z = st.columns([15,2,15]) @@ -131,11 +130,14 @@ with path_row[1]: if batch_id: - objects = s3_client.list_objects_v2(Bucket=client_bucket, Prefix="contract-text-file/"+batch_id+"/") + objects = s3_client.list_objects_v2(Bucket=client_bucket, Prefix="contracts-landing-zone/"+batch_id+"/") file_list = [] - for obj in objects['Contents']: - if not obj['Key'].endswith('/'): - file_list.append(obj['Key']) + if 'Contents' in objects: + for obj in objects['Contents']: + if not obj['Key'].endswith('/'): + file_list.append(obj['Key']) + else: + st.error('This batch_id is empty.') contract_list = sorted(file_list) @@ -216,7 +218,7 @@ if batch_id: """, unsafe_allow_html=True, ) - s3_obj = s3_client.get_object(Bucket = bucket, Key = 'textract-receiver-processed-pdfs/batch_2/2000-01-01 UCSD Medical Center PPA 14007097.PDF') + s3_obj = s3_client.get_object(Bucket = client_bucket, Key = file_name) data=s3_obj['Body'].read() pdf_viewer(data, width=1500) diff --git a/streamlit/multipage/pages/Interface_3.py b/streamlit/multipage/pages/Interface_3.py index 8c57927..fa43f2a 100644 --- a/streamlit/multipage/pages/Interface_3.py +++ b/streamlit/multipage/pages/Interface_3.py @@ -24,8 +24,7 @@ from sf_conn import get_secret, save_to_sf from io import StringIO -(REDIRECT_URI, create_batch_url, doczy_pipeline) = util.load_page_details(3) -REDIRECT_URI = 'https://doczydev.aarete.com:8505/Interface_3' +(REDIRECT_URI, create_batch_url, doczy_pipeline) = util.load_page_details(5) user_list = USER_LIST st.set_page_config(layout = "wide")