Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from PyPDF2 import PdfReader
|
| 3 |
+
import base64
|
| 4 |
+
|
| 5 |
+
# Function to display the PDF
|
| 6 |
+
def display_pdf(pdf_path):
|
| 7 |
+
# Reading PDF file and converting it to base64 to display in Streamlit
|
| 8 |
+
with open(pdf_path, "rb") as pdf_file:
|
| 9 |
+
pdf_bytes = pdf_file.read()
|
| 10 |
+
pdf_base64 = base64.b64encode(pdf_bytes).decode('utf-8')
|
| 11 |
+
|
| 12 |
+
# Display the PDF in Streamlit using an HTML tag
|
| 13 |
+
pdf_display = f'<embed src="data:application/pdf;base64,{pdf_base64}" width="700" height="900" type="application/pdf">'
|
| 14 |
+
st.markdown(pdf_display, unsafe_allow_html=True)
|
| 15 |
+
|
| 16 |
+
# Title of the app
|
| 17 |
+
st.title("Diagnostic Pathology Test Results - PDF Report")
|
| 18 |
+
|
| 19 |
+
# Option to upload PDF file if needed
|
| 20 |
+
pdf_file = st.file_uploader("Upload PDF Report", type="pdf")
|
| 21 |
+
|
| 22 |
+
# If the user uploads a PDF, display it
|
| 23 |
+
if pdf_file is not None:
|
| 24 |
+
st.write("### Displaying Uploaded Report")
|
| 25 |
+
display_pdf(pdf_file)
|
| 26 |
+
|
| 27 |
+
else:
|
| 28 |
+
# Or display a static PDF from your local machine
|
| 29 |
+
st.write("### Displaying Static PDF Report")
|
| 30 |
+
display_pdf("path_to_your_pdf_report.pdf") # Replace with the path to your static PDF
|