File size: 1,410 Bytes
93b784c
 
615fc49
7cedb75
 
 
615fc49
7cedb75
c485eb1
 
93b784c
c485eb1
93b784c
c485eb1
93b784c
c485eb1
 
 
 
37746c7
7cedb75
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
37746c7
 
7cedb75
 
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
42
43
# app.py

import gradio as gr
from ALNISF import process_pdf as process_alnisf
from federal_electric import process_pdf as process_federal_electric
from bhel import process_pdf as process_bhel

def process_file(pdf_file, extractor):
    try:
        if extractor == "ALNISF":
            return process_alnisf(pdf_file)
        elif extractor == "Federal Electric":
            return process_federal_electric(pdf_file)
        elif extractor == "BHEL":
            return process_bhel(pdf_file)
        else:
            return None, "Invalid extractor selected."
    except Exception as e:
        return None, f"An error occurred: {str(e)}"

def create_main_interface():
    return gr.Interface(
        fn=process_file,
        inputs=[
            gr.File(label="Upload PDF", file_types=[".pdf"]),
            gr.Radio(
                ["ALNISF", "Federal Electric", "BHEL"],
                label="Select Extractor",
                value="ALNISF"
            ),
        ],
        outputs=[
            gr.File(label="Download Extracted Data"),
            gr.Textbox(label="Status"),
        ],
        title="Unified PO Data Extraction App",
        description="Upload a Purchase Order PDF and select the extractor (ALNISF, Federal Electric, BHEL) to process the file and download the extracted data.",
    )

if __name__ == "__main__":
    interface = create_main_interface()
    interface.launch()