File size: 1,698 Bytes
615fc49
7cedb75
 
 
615fc49
83a4f63
7cedb75
615fc49
7cedb75
 
 
 
 
 
615fc49
7cedb75
 
 
615fc49
7cedb75
 
615fc49
7cedb75
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
44
45
46
47
48
49
50
51
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

# Unified function to handle extractors
def process_file(pdf_file, extractor):
    """
    Processes the uploaded PDF using the selected extractor.
    Args:
        pdf_file: Uploaded PDF file.
        extractor: The selected extractor script (ALNISF, Federal Electric, BHEL).
    Returns:
        The extracted file and status message.
    """
    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."

# Gradio interface setup
def create_main_interface():
    """
    Creates the main Gradio interface that integrates all extractors.
    """
    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()