Spaces:
Build error
Build error
Commit ·
611e56a
1
Parent(s): 4e8c878
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import PyPDF2
|
| 3 |
+
from io import BytesIO
|
| 4 |
+
|
| 5 |
+
# Function to extract text from PDF
|
| 6 |
+
def extract_text_from_pdf(file):
|
| 7 |
+
pdfReader = PyPDF2.PdfReader(file)
|
| 8 |
+
text = ""
|
| 9 |
+
for page in pdfReader.pages:
|
| 10 |
+
text += page.extract_text()
|
| 11 |
+
return text
|
| 12 |
+
|
| 13 |
+
# Streamlit interface
|
| 14 |
+
st.title("PDF Text Extractor by FSA")
|
| 15 |
+
|
| 16 |
+
# File uploader
|
| 17 |
+
uploaded_file = st.file_uploader("Upload your PDF file", type="pdf")
|
| 18 |
+
|
| 19 |
+
if uploaded_file is not None:
|
| 20 |
+
# To read file as bytes:
|
| 21 |
+
bytes_data = BytesIO(uploaded_file.getvalue())
|
| 22 |
+
# Extracting text from the PDF
|
| 23 |
+
extracted_text = extract_text_from_pdf(bytes_data)
|
| 24 |
+
# Displaying the extracted text
|
| 25 |
+
st.write("Extracted Text:")
|
| 26 |
+
st.text_area("Text", extracted_text, height=300)
|