File size: 1,165 Bytes
43355d2
 
ef59284
43355d2
4bc3210
43355d2
 
 
4bc3210
43355d2
4bc3210
43355d2
 
4bc3210
 
 
 
 
43355d2
 
 
 
4bc3210
43355d2
4bc3210
 
43355d2
 
 
 
 
 
 
 
c6743f5
4bc3210
43355d2
 
 
c6743f5
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
38
39
40
41
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)