minar09's picture
Upload 2 files
c6743f5 verified
raw
history blame
1.17 kB
import os
import gradio as gr
import main
def predict_from_pdf(pdf_file):
upload_dir = "./catalogue/"
os.makedirs(upload_dir, exist_ok=True)
try:
# Save the uploaded file to a temporary location
dest_path = os.path.join(upload_dir, pdf_file.name)
with open(dest_path, "wb") as f:
with open(pdf_file.name, "rb") as uploaded_file:
f.write(uploaded_file.read())
# Process the PDF
df, response = main.process_pdf_catalog(dest_path)
return df, response
except Exception as e:
return None, f"Error: {str(e)}"
pdf_examples = [
["examples/flexpocket.pdf"],
["examples/ASICS_Catalog.pdf"],
]
demo = gr.Interface(
fn=predict_from_pdf,
inputs=gr.File(label="Upload PDF Catalog"),
outputs=["json", "text"],
examples=pdf_examples,
title="Open Source PDF Catalog Parser",
description="Efficient PDF catalog processing using MinerU and OpenLLM",
article="Uses MinerU for layout analysis and DeepSeek-7B for structured extraction"
)
if __name__ == "__main__":
demo.queue().launch(server_name="0.0.0.0", server_port=7860, share=True)