InvoiceBot / app.py
Balaprime's picture
Update app.py
b1ba1ed verified
import gradio as gr
import pandas as pd
from utils import create_docs
def process_invoices(file_list):
if not file_list:
return "No files uploaded. Please upload at least one PDF invoice.", None
try:
df = create_docs(file_list)
if not isinstance(df, pd.DataFrame):
return "Error: The extracted data is not in the expected format.", None
if df.empty:
return "No data extracted from the PDFs.", None
return "Data extraction completed! 🎉", df
except Exception as e:
return f"Error processing PDFs: {str(e)}", None
demo = gr.Interface(
fn=process_invoices,
inputs=gr.File(
file_types=[".pdf"],
file_count="multiple",
label="Upload PDF invoices"
),
outputs=[
gr.Textbox(label="Status"),
gr.Dataframe(label="Extracted Invoice Data")
],
title="Invoice Extraction Bot 🤖",
description="Upload your PDF invoices to extract key information like invoice number, date, items, totals, and contact info.",
allow_flagging="never"
)
if __name__ == "__main__":
demo.launch(
server_name="0.0.0.0", # Bind to all interfaces for local deployment
server_port=7860, # Default Gradio port
show_error=True # Show detailed errors in the UI
)