From 8c762424281f162c31f7efd3005d4dd88a02c663 Mon Sep 17 00:00:00 2001 From: "AARETE\\agupta" Date: Tue, 4 Jun 2024 12:57:14 -0500 Subject: [PATCH] Made changes for the PDF viewer to be able to pull the bytes from the S3 Bucket and display it. --- streamlit/interface_2.py | 74 ++++++++++++++++++++++------ streamlit/local/local_interface_2.py | 2 +- 2 files changed, 59 insertions(+), 17 deletions(-) diff --git a/streamlit/interface_2.py b/streamlit/interface_2.py index ed8c494..824509a 100644 --- a/streamlit/interface_2.py +++ b/streamlit/interface_2.py @@ -10,6 +10,7 @@ from langchain.chains import RetrievalQA import streamlit as st from streamlit_extras.add_vertical_space import add_vertical_space +from streamlit_pdf_viewer import pdf_viewer # needs to be installed on the server import os import pandas as pd import numpy as np @@ -18,24 +19,26 @@ import anthropic from pydantic import BaseModel from typing import List import re +import base64 from sf_conn import get_snowflake_conn +import io REDIRECT_URI = 'https://doczydev.aarete.com:8502' 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") _,c1= st.columns([5,1]) try: @@ -91,13 +94,11 @@ for obj in objects['Contents']: contract_list = sorted(file_list) - - file_row = st.columns([0.2, 0.7, 0.1]) with file_row[0]: st.write("**Contract Name**") with file_row[1]: - file_name = st.selectbox('Select a file', contract_list + ['All'], label_visibility = "collapsed") + file_name = st.selectbox('Select a file', ['All'] + contract_list, label_visibility = "collapsed", index= None) # MODIFIED - Append 'All' in the front instead of at the end field_row = st.columns([0.2, 0.7, 0.1]) with field_row[0]: @@ -107,7 +108,7 @@ with field_row[1]: , 'Pricing Before Carveouts - II', 'Carveout Indicator, Code Type and Code #s - I' , 'Carveout Indicator, Code Type and Code #s - II', 'Carveout Indicator, Code Type and Code #s - III' , 'Optimize Carving Indic.', 'Carveout Method - I', 'Carveout Method - II', 'Provider' - , 'Timeline'), label_visibility = "collapsed") + , 'Timeline'), label_visibility = "collapsed", index = None) if field_group == 'Unique Key': fields = fields[fields['PRIORITY'] == 'A'] @@ -151,10 +152,51 @@ if st.button("Show Results"): df2 = pd.DataFrame.from_records(iter(cur), columns=[x[0] for x in cur.description]) # get this dataframe from snowflake table - # df2 = pd.DataFrame(columns=['Contract Name','Field Name', 'SF_DB_COL_NAME', 'Snippet','Page Number' - # , 'Field Extracted Value', 'Actual Value','Imputed Value']) + df2 = pd.DataFrame(columns=['Contract Name','Field Name', 'SF_DB_COL_NAME', 'Snippet','Page Number' + , 'Field Extracted Value', 'Actual Value','Imputed Value']) df2.to_csv('temp2.csv', index=False) +if st.button("Show PDF"): + if file_name == None or file_name == "All": + st.error("Choose one specific file.") + else: + with st.sidebar: + st.markdown( + """ + + """, + unsafe_allow_html=True, + ) + s3_client.Object(bucket,file_name) + data=obj.get()['Body'].read() + pdf_viewer(io.BytesIO(data), width=1500) + +# if st.button("Show PDF"): +# if file_name == None or file_name == "All": +# st.error("Choose one specific file.") +# else: +# with st.sidebar: +# with open(file_name, "rb") as f: +# base64_pdf = base64.b64encode(f.read()).decode('utf-8') +# # Embedding PDF in HTML +# pdf_display = F'' +# # Displaying File +# st.markdown( +# """ +# +# """, +# unsafe_allow_html=True, +# ) +# st.markdown(pdf_display, unsafe_allow_html=True) + df2 = pd.read_csv('temp2.csv') df2['Imputed Value'] = '' edited_df = st.data_editor(df2) diff --git a/streamlit/local/local_interface_2.py b/streamlit/local/local_interface_2.py index 7e40615..18702f3 100644 --- a/streamlit/local/local_interface_2.py +++ b/streamlit/local/local_interface_2.py @@ -10,7 +10,7 @@ from langchain.chains import RetrievalQA import streamlit as st from streamlit_extras.add_vertical_space import add_vertical_space -from streamlit_pdf_viewer import pdf_viewer +from streamlit_pdf_viewer import pdf_viewer # needs to be installed on the server import os import pandas as pd import numpy as np