2024-03-27 18:59:29 +05:30
|
|
|
import streamlit as st
|
|
|
|
|
from streamlit_extras.add_vertical_space import add_vertical_space
|
|
|
|
|
import os
|
|
|
|
|
import streamlit as st
|
|
|
|
|
import pandas as pd
|
|
|
|
|
from io import StringIO
|
|
|
|
|
from datetime import datetime
|
|
|
|
|
import boto3
|
|
|
|
|
import util
|
|
|
|
|
import requests
|
|
|
|
|
|
|
|
|
|
doczy_pipeline = 'https://8ir4vi1ri4.execute-api.us-east-2.amazonaws.com/dev/'
|
|
|
|
|
|
|
|
|
|
REDIRECT_URI = 'https://doczy.aarete.com:8500'
|
|
|
|
|
user_list = ['maamseek@aarete.com', 'smahdavian@aarete.com', 'ahinge@aarete.com', 'akadam@aarete.com', 'pkatariya@aarete.com'
|
|
|
|
|
, 'piragavarapu@aarete.com', 'umistry@aarete.com', 'ahutchison@aarete.com', 'bgrunst@aarete.com', 'ddimeglio@aarete.com'
|
|
|
|
|
, 'vnair@aarete.com']
|
|
|
|
|
st.set_page_config(layout = "wide")
|
|
|
|
|
# # 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")
|
|
|
|
|
|
|
|
|
|
try:
|
2024-03-27 19:01:11 +05:30
|
|
|
util.setup_page(REDIRECT_URI)
|
2024-03-27 18:59:29 +05:30
|
|
|
_,c1= st.columns([5,1])
|
|
|
|
|
c1.write(f"User: **{st.session_state.user_info['displayName']}**")
|
|
|
|
|
user_mail = st.session_state.user_info['mail']
|
|
|
|
|
except:
|
|
|
|
|
user_mail = 'maamseek@aarete.com'
|
|
|
|
|
|
|
|
|
|
if user_mail in user_list:
|
|
|
|
|
|
|
|
|
|
s3_client = boto3.client('s3',
|
|
|
|
|
region_name="us-east-1",
|
|
|
|
|
)
|
|
|
|
|
objects = s3_client.list_objects_v2(Bucket='doczy-dev-infra-textract'
|
|
|
|
|
, Prefix="batches/batch_1/", Delimiter='/')
|
|
|
|
|
|
|
|
|
|
folder_list = []
|
|
|
|
|
for prefix in objects['CommonPrefixes']:
|
|
|
|
|
folder_list.append(prefix['Prefix'][:-1].split('/')[-1])
|
|
|
|
|
|
|
|
|
|
# # to be deleted later
|
|
|
|
|
# folder_list = ['Delaware First Health, Inc.', 'Community Health Choice, Inc','CareSource Network Partners LLC',
|
|
|
|
|
# 'HealthNet of Cali', 'Oklahoma Complete Health, Inc', 'HealthFirst', 'Molina Healthcare of TX', 'AvMed', 'Arizona Care1st',
|
|
|
|
|
# 'WellCare New Jersey']
|
|
|
|
|
|
|
|
|
|
client_row = st.columns([0.1, 0.8])
|
|
|
|
|
with client_row[0]:
|
|
|
|
|
st.write("**Client Name**")
|
|
|
|
|
with client_row[1]:
|
|
|
|
|
client = st.selectbox('Client Name',(folder_list), label_visibility = "collapsed")
|
|
|
|
|
|
|
|
|
|
# # to be deleted later
|
|
|
|
|
# client = 'textract-receiver-processed-file'
|
|
|
|
|
|
|
|
|
|
folder_objects = s3_client.list_objects_v2(Bucket='doczy-dev-infra-textract'
|
|
|
|
|
, Prefix="batches/batch_1/"+client+"/", Delimiter='/')
|
|
|
|
|
|
|
|
|
|
folder_list_2 = []
|
|
|
|
|
for prefix in folder_objects['CommonPrefixes']:
|
|
|
|
|
folder_list_2.append(prefix['Prefix'][:-1].split('/')[-1])
|
|
|
|
|
|
|
|
|
|
path_row = st.columns([0.1, 0.8])
|
|
|
|
|
with path_row[0]:
|
|
|
|
|
st.write("**Path to folder**")
|
|
|
|
|
with path_row[1]:
|
|
|
|
|
Directory = st.selectbox('**Path to folder**', folder_list_2, label_visibility = "collapsed")
|
|
|
|
|
|
|
|
|
|
add_vertical_space(1)
|
|
|
|
|
|
|
|
|
|
df = pd.DataFrame(columns=['Contract Name','Unique Key','Pricing Before Carveouts'
|
|
|
|
|
, 'Contract Related', 'Provider', 'Timeline', 'Carveout Indicator', 'Carveout Methodology'])
|
|
|
|
|
file_list = []
|
|
|
|
|
file_objects = s3_client.list_objects_v2(Bucket='doczy-dev-infra-textract'
|
|
|
|
|
, Prefix="batches/batch_1/"+client+"/"+Directory+"/", Delimiter='/')
|
|
|
|
|
|
|
|
|
|
if st.button("Create Batch"):
|
|
|
|
|
for obj in file_objects.get('Contents',[]):
|
|
|
|
|
if not obj['Key'].endswith('/'):
|
|
|
|
|
file_list.append(obj['Key'].split('/')[-1])
|
|
|
|
|
|
|
|
|
|
df['Contract Name'] = file_list
|
|
|
|
|
|
|
|
|
|
add_vertical_space(1)
|
|
|
|
|
|
|
|
|
|
@st.cache_data
|
|
|
|
|
def convert_df(df):
|
|
|
|
|
return df.to_csv(index=False).encode('utf-8')
|
|
|
|
|
|
|
|
|
|
csv = convert_df(df)
|
|
|
|
|
|
|
|
|
|
df = df.reset_index() # make sure indexes pair with number of rows
|
|
|
|
|
|
|
|
|
|
# contract_list = []
|
|
|
|
|
# for index, row in df.iterrows():
|
|
|
|
|
# group_list = []
|
|
|
|
|
# if row['Unique Key']:
|
|
|
|
|
# group_list.append('Unique Key')
|
|
|
|
|
# if row['Pricing Before Carveouts']:
|
|
|
|
|
# group_list.append('Pricing Before Carveouts')
|
|
|
|
|
# if row['Contract Related']:
|
|
|
|
|
# group_list.append('Contract Related')
|
|
|
|
|
# if row['Provider']:
|
|
|
|
|
# group_list.append('Provider')
|
|
|
|
|
# if row['Timeline']:
|
|
|
|
|
# group_list.append('Timeline')
|
|
|
|
|
# if row['Carveout Indicator']:
|
|
|
|
|
# group_list.append('Carveout Indicator')
|
|
|
|
|
# if row['Carveout Methodology']:
|
|
|
|
|
# group_list.append('Carveout Methodology')
|
|
|
|
|
# entry_dict = {
|
|
|
|
|
# "contract_name": row['Contract Name'],
|
|
|
|
|
# "groups": group_list,
|
|
|
|
|
# "contract_source_path": "batches/batch_1/"+client+"/"+row['Contract Name']
|
|
|
|
|
# }
|
|
|
|
|
# contract_list.append(entry_dict)
|
|
|
|
|
contract_list = list(df['Contract Name'])
|
|
|
|
|
|
|
|
|
|
myobj = {
|
|
|
|
|
"s3_bucket": 'doczy-dev-infra-textract',
|
|
|
|
|
"batch_id": "1",
|
|
|
|
|
"client_name": client,
|
|
|
|
|
"username": user_mail,
|
|
|
|
|
"contract_list": contract_list
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
buttons = st.columns([0.8, 0.2])
|
|
|
|
|
with buttons[0]:
|
|
|
|
|
st.download_button("Download Table", csv, "file.csv", "text/csv", key='download-csv')
|
|
|
|
|
with buttons[1]:
|
|
|
|
|
if st.button("Upload to DB"):
|
|
|
|
|
response = requests.post(doczy_pipeline, json = myobj)
|
|
|
|
|
if response.status_code >= 200 and response.status_code < 300:
|
|
|
|
|
st.write("Success")
|
|
|
|
|
else:
|
|
|
|
|
st.write("Failed")
|
|
|
|
|
# st.write(response.text)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
st.write("Access Denied")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|