File size: 1,034 Bytes
b51440d 254b285 b51440d 254b285 b51440d 254b285 86256b2 1c864d4 254b285 34ed87a e664e7d b51440d 34ed87a b51440d 34ed87a b51440d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
import streamlit as st
import PyPDF2
import tempfile
import os
def extract_text_from_pdf(uploaded_file):
text = ""
with tempfile.NamedTemporaryFile(delete=False) as tmp_file:
tmp_file.write(uploaded_file.read())
tmp_file.seek(0)
with open(tmp_file.name, "rb") as f:
reader = PyPDF2.PdfReader(f)
num_pages = len(reader.pages)
for page_num in range(num_pages):
page = reader.pages[page_num]
text += page.extract_text()
return text
def main():
st.title("PDF Text Extractor")
st.write("Upload your pdf:")
uploaded_file = st.file_uploader("Select PDF file", type=['pdf'])
if uploaded_file is not None:
st.write("PDF file Upload:", uploaded_file.name)
st.write("File size:", uploaded_file.size)
if st.button("Extract Text"):
text = extract_text_from_pdf(uploaded_file)
st.write("Extracted Text:")
st.write(text)
if __name__ == "__main__":
main()
|