Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,53 +1,32 @@
|
|
| 1 |
import streamlit as st
|
|
|
|
|
|
|
| 2 |
import os
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
with
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
#
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
st.
|
| 31 |
-
|
| 32 |
-
uploaded_file = st.file_uploader("Upload a PDF file", type=["pdf"])
|
| 33 |
-
if uploaded_file:
|
| 34 |
-
with tempfile.NamedTemporaryFile(delete=False, suffix=".pdf") as tmp_pdf:
|
| 35 |
-
tmp_pdf.write(uploaded_file.read())
|
| 36 |
-
tmp_pdf_path = tmp_pdf.name
|
| 37 |
-
|
| 38 |
-
images = convert_from_path(tmp_pdf_path)
|
| 39 |
-
|
| 40 |
-
for i, img in enumerate(images):
|
| 41 |
-
st.subheader(f"Page {i + 1}")
|
| 42 |
-
st.image(img, caption="Original Page", use_column_width=True)
|
| 43 |
-
|
| 44 |
-
# Step 4: Run Table Recognizer
|
| 45 |
-
with st.spinner("Extracting tables..."):
|
| 46 |
-
table_results = table_model(img) # This assumes model takes a PIL image and returns result
|
| 47 |
-
|
| 48 |
-
if table_results:
|
| 49 |
-
for idx, table in enumerate(table_results):
|
| 50 |
-
st.markdown(f"#### Table {idx + 1}")
|
| 51 |
-
st.dataframe(table["data"]) # Assuming table["data"] is a 2D list or pandas DataFrame
|
| 52 |
-
else:
|
| 53 |
-
st.info("No tables detected on this page.")
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
from pdf_extract_kit.tasks.ocr import OCRTask
|
| 3 |
+
from pdf_extract_kit.utils.config_loader import load_config
|
| 4 |
import os
|
| 5 |
+
|
| 6 |
+
# Streamlit app title
|
| 7 |
+
st.title("PDF Table Extraction")
|
| 8 |
+
|
| 9 |
+
# File uploader to upload PDF
|
| 10 |
+
uploaded_file = st.file_uploader("Choose a PDF file", type="pdf")
|
| 11 |
+
|
| 12 |
+
if uploaded_file is not None:
|
| 13 |
+
# Save the uploaded file to a temporary location
|
| 14 |
+
with open("temp.pdf", "wb") as f:
|
| 15 |
+
f.write(uploaded_file.read())
|
| 16 |
+
|
| 17 |
+
# Configuration path for OCR task
|
| 18 |
+
config_path = "PDF-Extract-Kit/configs/ocr.yaml" # Updated config path
|
| 19 |
+
config = load_config(config_path)
|
| 20 |
+
|
| 21 |
+
# Initialize the OCR task
|
| 22 |
+
task = OCRTask(config)
|
| 23 |
+
|
| 24 |
+
# Perform OCR task on the uploaded PDF
|
| 25 |
+
extracted_data = task.process("temp.pdf", save_dir="outputs", visualize=True)
|
| 26 |
+
|
| 27 |
+
# Display the extracted values
|
| 28 |
+
st.write("Extracted Data:")
|
| 29 |
+
st.write(extracted_data)
|
| 30 |
+
|
| 31 |
+
# Optional: Visualize the result (depending on how the output is generated)
|
| 32 |
+
# st.image('path_to_visualization_image', caption='Extracted Table', use_column_width=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|