randomshit11 commited on
Commit
254b285
·
verified ·
1 Parent(s): 551c1e4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -7
app.py CHANGED
@@ -1,14 +1,19 @@
1
  import streamlit as st
2
  import PyPDF2
 
 
3
 
4
- def extract_text_from_pdf(pdf_file_path):
5
  text = ""
6
- with open(pdf_file_path, "rb") as f:
7
- reader = PyPDF2.PdfFileReader(f)
8
- num_pages = reader.numPages
9
- for page_num in range(num_pages):
10
- page = reader.getPage(page_num)
11
- text += page.extractText()
 
 
 
12
  return text
13
 
14
  def main():
 
1
  import streamlit as st
2
  import PyPDF2
3
+ import tempfile
4
+ import os
5
 
6
+ def extract_text_from_pdf(uploaded_file):
7
  text = ""
8
+ with tempfile.NamedTemporaryFile(delete=False) as tmp_file:
9
+ tmp_file.write(uploaded_file.read())
10
+ tmp_file.seek(0)
11
+ with open(tmp_file.name, "rb") as f:
12
+ reader = PyPDF2.PdfFileReader(f)
13
+ num_pages = reader.numPages
14
+ for page_num in range(num_pages):
15
+ page = reader.getPage(page_num)
16
+ text += page.extractText()
17
  return text
18
 
19
  def main():