app updated
Browse files- app.py +3 -0
- helper/utils.py +26 -0
app.py
CHANGED
@@ -59,6 +59,9 @@ with st.sidebar:
|
|
59 |
# Clear button
|
60 |
clear_button = st.sidebar.button("Clear Conversation", key="clear")
|
61 |
|
|
|
|
|
|
|
62 |
|
63 |
# Initialize chat history
|
64 |
if "messages" not in st.session_state:
|
|
|
59 |
# Clear button
|
60 |
clear_button = st.sidebar.button("Clear Conversation", key="clear")
|
61 |
|
62 |
+
# Display pdf
|
63 |
+
displayPDF(uploaded_files)
|
64 |
+
|
65 |
|
66 |
# Initialize chat history
|
67 |
if "messages" not in st.session_state:
|
helper/utils.py
CHANGED
@@ -1,6 +1,8 @@
|
|
1 |
import os
|
2 |
from typing import Any, Dict, List, Tuple, Union
|
3 |
|
|
|
|
|
4 |
import numpy as np
|
5 |
import pandas as pd
|
6 |
import PyPDF2
|
@@ -45,6 +47,30 @@ def read_and_textify(
|
|
45 |
return [text_list, sources_list]
|
46 |
|
47 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
48 |
client = OpenAI(api_key=os.environ["OPENAI_API_KEY"])
|
49 |
|
50 |
|
|
|
1 |
import os
|
2 |
from typing import Any, Dict, List, Tuple, Union
|
3 |
|
4 |
+
import base64
|
5 |
+
import streamlit as st
|
6 |
import numpy as np
|
7 |
import pandas as pd
|
8 |
import PyPDF2
|
|
|
47 |
return [text_list, sources_list]
|
48 |
|
49 |
|
50 |
+
def displayPDF(file: str) -> None:
|
51 |
+
"""
|
52 |
+
This function reads a PDF file, encodes it into base64 and then displays it on a Streamlit app using markdown.
|
53 |
+
|
54 |
+
Parameters:
|
55 |
+
- file (str): The file path to the PDF file that needs to be displayed.
|
56 |
+
|
57 |
+
Returns:
|
58 |
+
- None
|
59 |
+
"""
|
60 |
+
|
61 |
+
# Opening file from file path
|
62 |
+
with open(file, "rb") as f:
|
63 |
+
# Encoding file content to base64
|
64 |
+
base64_pdf = base64.b64encode(f.read()).decode('utf-8')
|
65 |
+
|
66 |
+
# Embedding PDF in HTML with specific size and type
|
67 |
+
pdf_display = F'<embed src="data:application/pdf;base64,{base64_pdf}" width="700" height="1000" type="application/pdf">'
|
68 |
+
|
69 |
+
# Displaying File in Streamlit app by allowing unsafe HTML
|
70 |
+
st.markdown(pdf_display, unsafe_allow_html=True)
|
71 |
+
|
72 |
+
|
73 |
+
|
74 |
client = OpenAI(api_key=os.environ["OPENAI_API_KEY"])
|
75 |
|
76 |
|