Spaces:
Sleeping
Sleeping
Upload app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import pandas as pd
|
| 3 |
+
|
| 4 |
+
from column_matching.transformers import (
|
| 5 |
+
normalize_open_invoices,
|
| 6 |
+
normalize_payment_notification,
|
| 7 |
+
)
|
| 8 |
+
from column_matching.invoice_schema import invoice_pipeline_schema
|
| 9 |
+
from column_matching.validator import ColumnValidator
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
def process_files(open_invoices_file, payment_notification_file):
|
| 13 |
+
results = {}
|
| 14 |
+
|
| 15 |
+
if open_invoices_file is not None:
|
| 16 |
+
df_open = pd.read_excel(open_invoices_file.name)
|
| 17 |
+
df_open_norm = normalize_open_invoices(df_open, schema=invoice_pipeline_schema)
|
| 18 |
+
ColumnValidator(invoice_pipeline_schema).validate(
|
| 19 |
+
df_open_norm, dataset_name="Open Invoices (normalized)"
|
| 20 |
+
)
|
| 21 |
+
results["Open Invoices (normalized) head"] = df_open_norm.head().to_markdown()
|
| 22 |
+
|
| 23 |
+
if payment_notification_file is not None:
|
| 24 |
+
df_pay = pd.read_excel(payment_notification_file.name)
|
| 25 |
+
df_pay_norm = normalize_payment_notification(df_pay, schema=invoice_pipeline_schema)
|
| 26 |
+
ColumnValidator(invoice_pipeline_schema).validate(
|
| 27 |
+
df_pay_norm, dataset_name="Payment Notification (normalized)"
|
| 28 |
+
)
|
| 29 |
+
results["Payment Notification (normalized) head"] = df_pay_norm.head().to_markdown()
|
| 30 |
+
|
| 31 |
+
if not results:
|
| 32 |
+
return "Upload at least one Excel file to see normalized output."
|
| 33 |
+
|
| 34 |
+
parts = []
|
| 35 |
+
for title, md in results.items():
|
| 36 |
+
parts.append(f"## {title}\n\n{md}")
|
| 37 |
+
return "\n\n".join(parts)
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
with gr.Blocks() as demo:
|
| 41 |
+
gr.Markdown("# Column Matching & Normalization Demo")
|
| 42 |
+
gr.Markdown(
|
| 43 |
+
"""Upload your **Open Invoices** and/or **Payment Notification** Excel files.
|
| 44 |
+
The app will normalize them into the canonical schema and show the first few rows."""
|
| 45 |
+
)
|
| 46 |
+
|
| 47 |
+
with gr.Row():
|
| 48 |
+
open_file = gr.File(label="Open Invoices (.xlsx)", file_types=[".xlsx"])
|
| 49 |
+
pay_file = gr.File(label="Payment Notification (.xlsx)", file_types=[".xlsx"])
|
| 50 |
+
|
| 51 |
+
output = gr.Markdown()
|
| 52 |
+
|
| 53 |
+
run_btn = gr.Button("Normalize & Validate")
|
| 54 |
+
run_btn.click(process_files, inputs=[open_file, pay_file], outputs=output)
|
| 55 |
+
|
| 56 |
+
if __name__ == "__main__":
|
| 57 |
+
demo.launch()
|