| import gradio as gr |
| import os |
| from PO_parse import bhel |
|
|
| def process_po(customer_name, file): |
| if customer_name == "BHEL": |
| |
| extracted_data = bhel.extract_normalized_po_data(file.name) |
| |
| |
| output_dir = "./output" |
| os.makedirs(output_dir, exist_ok=True) |
| csv_file_path = os.path.join(output_dir, "extracted_po_data.csv") |
| |
| |
| extracted_data.to_csv(csv_file_path, index=False) |
| |
| |
| return extracted_data, "PO data saved to CSV.", csv_file_path |
| else: |
| return None, "Currently unsupported customer format.", None |
|
|
| |
| customer_dropdown = gr.Dropdown(choices=["BHEL", "Others"], label="Customer Name") |
| file_input = gr.File(label="Upload PO File (PDF)") |
|
|
| |
| interface = gr.Interface( |
| fn=process_po, |
| inputs=[customer_dropdown, file_input], |
| outputs=[ |
| gr.Dataframe(label="Extracted PO Details"), |
| gr.Textbox(label="Summary"), |
| gr.File(label="Download CSV") |
| ], |
| title="Purchase Order Parsing Tool", |
| description="Select a customer and upload a PO file to extract details." |
| ) |
|
|
| if __name__ == "__main__": |
| interface.launch() |
|
|