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 # Wrapper function to handle multiple 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()