-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update app.py with read in app feature
- Loading branch information
Showing
1 changed file
with
26 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,40 @@ | ||
import streamlit as st | ||
import pandas as pd | ||
from pathlib import Path | ||
from pathlib import Path | ||
from PyPDF2 import PdfFileWriter, PdfFileReader | ||
import uuid | ||
|
||
st.title("PDF Viewer App") | ||
|
||
pdfs = {} | ||
|
||
# Allow multiple uploads with a while loop | ||
uploaded = True | ||
# Allow multiple uploads | ||
uploaded = True | ||
|
||
while uploaded: | ||
key = str(uuid.uuid4()) | ||
uploaded_file = st.file_uploader("Choose a PDF", type=['pdf'], key=key) | ||
|
||
key = str(uuid.uuid4()) | ||
uploaded_file = st.file_uploader("Choose PDF", type=['pdf'], key=key) | ||
|
||
if uploaded_file is not None: | ||
file_details = {"FileName":uploaded_file.name,"FileType":uploaded_file.type} | ||
|
||
file_details = {"FileName":uploaded_file.name,"FileType":uploaded_file.type} | ||
pdfs[uploaded_file.name] = uploaded_file.read() | ||
|
||
# Save to temp file | ||
with open(Path("temp.pdf"), "wb") as f: | ||
f.write(uploaded_file.getbuffer()) | ||
|
||
# Read PDF | ||
pdf_reader = PdfFileReader(Path("temp.pdf")) | ||
|
||
# Display pages | ||
for page_num in range(pdf_reader.numPages): | ||
page = pdf_reader.getPage(page_num) | ||
st.write(page) | ||
|
||
else: | ||
uploaded = False | ||
uploaded = False | ||
|
||
# Display all uploaded PDFs | ||
for name, data in pdfs.items(): | ||
# List uploaded PDFs | ||
for name in pdfs: | ||
st.write(name) | ||
if st.checkbox(f'Show {name}'): | ||
st.write(data) |