Spaces:
Runtime error
Runtime error
Update src/app.py
Browse files- src/app.py +12 -26
src/app.py
CHANGED
|
@@ -1,50 +1,36 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
import pandas as pd
|
| 3 |
-
import
|
|
|
|
| 4 |
|
| 5 |
-
from cleaner import clean_image
|
| 6 |
from ocr_engine import extract_text
|
| 7 |
from classifier import classify_invoice
|
| 8 |
from extractor import extract_fields
|
| 9 |
from formatter import format_for_ca
|
| 10 |
from validator import validate
|
| 11 |
|
| 12 |
-
st.set_page_config(page_title="
|
| 13 |
|
| 14 |
-
st.title("
|
| 15 |
|
| 16 |
-
uploaded_file = st.file_uploader("Upload Invoice
|
| 17 |
|
| 18 |
if uploaded_file:
|
| 19 |
|
| 20 |
-
|
|
|
|
| 21 |
|
| 22 |
-
with
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
with st.spinner("Processing invoice..."):
|
| 26 |
-
|
| 27 |
-
cleaned = clean_image(temp_path)
|
| 28 |
-
text = extract_text(cleaned)
|
| 29 |
invoice_type = classify_invoice(text)
|
| 30 |
extracted = extract_fields(text)
|
| 31 |
formatted = format_for_ca(extracted, invoice_type)
|
| 32 |
validated = validate(formatted)
|
| 33 |
|
| 34 |
df = pd.DataFrame([validated])
|
| 35 |
-
|
| 36 |
-
st.success("Processing Complete")
|
| 37 |
st.dataframe(df)
|
| 38 |
|
| 39 |
-
|
| 40 |
-
df.to_excel(excel_path, index=False)
|
| 41 |
-
|
| 42 |
-
with open(excel_path, "rb") as f:
|
| 43 |
-
st.download_button(
|
| 44 |
-
"📥 Download Excel",
|
| 45 |
-
f,
|
| 46 |
-
"invoice.xlsx",
|
| 47 |
-
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
|
| 48 |
-
)
|
| 49 |
|
| 50 |
-
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
import pandas as pd
|
| 3 |
+
import numpy as np
|
| 4 |
+
from PIL import Image
|
| 5 |
|
|
|
|
| 6 |
from ocr_engine import extract_text
|
| 7 |
from classifier import classify_invoice
|
| 8 |
from extractor import extract_fields
|
| 9 |
from formatter import format_for_ca
|
| 10 |
from validator import validate
|
| 11 |
|
| 12 |
+
st.set_page_config(page_title="Invoice AI")
|
| 13 |
|
| 14 |
+
st.title("AI Invoice Automation for CA Firms")
|
| 15 |
|
| 16 |
+
uploaded_file = st.file_uploader("Upload Invoice", type=["jpg","png","jpeg"])
|
| 17 |
|
| 18 |
if uploaded_file:
|
| 19 |
|
| 20 |
+
image = Image.open(uploaded_file).convert("RGB")
|
| 21 |
+
image_np = np.array(image)
|
| 22 |
|
| 23 |
+
with st.spinner("Running OCR..."):
|
| 24 |
+
text = extract_text(image_np)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
invoice_type = classify_invoice(text)
|
| 26 |
extracted = extract_fields(text)
|
| 27 |
formatted = format_for_ca(extracted, invoice_type)
|
| 28 |
validated = validate(formatted)
|
| 29 |
|
| 30 |
df = pd.DataFrame([validated])
|
|
|
|
|
|
|
| 31 |
st.dataframe(df)
|
| 32 |
|
| 33 |
+
df.to_excel("output.xlsx", index=False)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
|
| 35 |
+
with open("output.xlsx", "rb") as f:
|
| 36 |
+
st.download_button("Download Excel", f, "invoice.xlsx")
|