PMPUC3 / app.py
SuriRaja's picture
Update app.py
17ec044 verified
import gradio as gr
import os
from PO_parse import bhel # Assuming bhel.py is in a folder named PO_parse
def process_po(customer_name, file):
if customer_name == "BHEL":
# Use the normalized extraction function from bhel.py
extracted_data = bhel.extract_normalized_po_data(file.name)
# Ensure output directory exists and save CSV file
output_dir = "./output"
os.makedirs(output_dir, exist_ok=True) # Create the directory if it doesn't exist
csv_file_path = os.path.join(output_dir, "extracted_po_data.csv")
# Save DataFrame to CSV
extracted_data.to_csv(csv_file_path, index=False)
# Display the extracted data and provide the CSV download link
return extracted_data, "PO data saved to CSV.", csv_file_path
else:
return None, "Currently unsupported customer format.", None
# Gradio Interface setup
customer_dropdown = gr.Dropdown(choices=["BHEL", "Others"], label="Customer Name")
file_input = gr.File(label="Upload PO File (PDF)")
# Define Gradio interface with function, inputs, and outputs
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()