Agile_Lab / app.py
jonels1988's picture
Update app.py
da4a4d2 verified
Raw History Blame Contribute Delete
2.3 kB
import gradio as gr
import pandas as pd
from transformers import (
normalize_open_invoices,
normalize_payment_notification,
)
from invoice_schema import invoice_pipeline_schema
from validator import ColumnValidator
def process_files(open_invoices_file, payment_notification_file):
results = {}
if open_invoices_file is not None:
# HF uploads are temp files with a .name attribute
df_open = pd.read_excel(open_invoices_file.name)
df_open_norm = normalize_open_invoices(
df_open,
schema=invoice_pipeline_schema,
dataset_name="Open Invoices",
)
ColumnValidator(invoice_pipeline_schema).validate(
df_open_norm, dataset_name="Open Invoices (normalized)"
)
results["Open Invoices (normalized) head"] = df_open_norm.head().to_markdown()
if payment_notification_file is not None:
df_pay = pd.read_excel(payment_notification_file.name)
df_pay_norm = normalize_payment_notification(
df_pay,
schema=invoice_pipeline_schema,
dataset_name="Payment Notification",
)
ColumnValidator(invoice_pipeline_schema).validate(
df_pay_norm, dataset_name="Payment Notification (normalized)"
)
results["Payment Notification (normalized) head"] = (
df_pay_norm.head().to_markdown()
)
if not results:
return "Upload at least one Excel file to see normalized output."
parts = []
for title, md in results.items():
parts.append(f"## {title}\n\n{md}")
return "\n\n".join(parts)
with gr.Blocks() as demo:
gr.Markdown("# Column Matching & Normalization Demo")
gr.Markdown(
"Upload your **Open Invoices** and/or **Payment Notification** Excel files.\n"
"The app will normalize them into the canonical schema and show the first few rows."
)
with gr.Row():
open_file = gr.File(label="Open Invoices (.xlsx)", file_types=[".xlsx"])
pay_file = gr.File(label="Payment Notification (.xlsx)", file_types=[".xlsx"])
output = gr.Markdown()
run_btn = gr.Button("Normalize & Validate")
run_btn.click(process_files, inputs=[open_file, pay_file], outputs=output)
if __name__ == "__main__":
demo.launch()