Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -26,7 +26,7 @@ MODELS = {
|
|
| 26 |
"api_url": "https://api.openai.com/v1/chat/completions",
|
| 27 |
"model": "gpt-4-1106-preview",
|
| 28 |
"key_env": "OPENAI_API_KEY",
|
| 29 |
-
"response_format": None,
|
| 30 |
"extra_headers": {},
|
| 31 |
},
|
| 32 |
"Mistral Small": {
|
|
@@ -143,7 +143,16 @@ def extract_invoice_info(model_choice, text):
|
|
| 143 |
if not data:
|
| 144 |
return None
|
| 145 |
|
| 146 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 147 |
hdr = data.setdefault("invoice_header", {})
|
| 148 |
for k in ("invoice_number","invoice_date","po_number","invoice_value","supplier_name","customer_name"):
|
| 149 |
hdr.setdefault(k, None)
|
|
@@ -179,12 +188,25 @@ with tab2:
|
|
| 179 |
info = extract_invoice_info(mdl, txt)
|
| 180 |
if info:
|
| 181 |
st.success("Extraction Complete")
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
|
| 187 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 188 |
|
| 189 |
if "last_api" in st.session_state:
|
| 190 |
with st.expander("Debug"):
|
|
|
|
| 26 |
"api_url": "https://api.openai.com/v1/chat/completions",
|
| 27 |
"model": "gpt-4-1106-preview",
|
| 28 |
"key_env": "OPENAI_API_KEY",
|
| 29 |
+
"response_format": None,
|
| 30 |
"extra_headers": {},
|
| 31 |
},
|
| 32 |
"Mistral Small": {
|
|
|
|
| 143 |
if not data:
|
| 144 |
return None
|
| 145 |
|
| 146 |
+
# DeepSeek models: flat format
|
| 147 |
+
if model_choice.startswith("DeepSeek"):
|
| 148 |
+
for k in ("invoice_number","invoice_date","po_number","invoice_value"):
|
| 149 |
+
data.setdefault(k, None)
|
| 150 |
+
items = data.setdefault("line_items", [])
|
| 151 |
+
for itm in items:
|
| 152 |
+
for k in ("description","quantity","unit_price","total_price"):
|
| 153 |
+
itm.setdefault(k, None)
|
| 154 |
+
return data
|
| 155 |
+
# Other models (OpenAI GPT-4.1, Mistral): nested format
|
| 156 |
hdr = data.setdefault("invoice_header", {})
|
| 157 |
for k in ("invoice_number","invoice_date","po_number","invoice_value","supplier_name","customer_name"):
|
| 158 |
hdr.setdefault(k, None)
|
|
|
|
| 188 |
info = extract_invoice_info(mdl, txt)
|
| 189 |
if info:
|
| 190 |
st.success("Extraction Complete")
|
| 191 |
+
if mdl.startswith("DeepSeek"):
|
| 192 |
+
c1, c2 = st.columns(2)
|
| 193 |
+
c1.metric("Invoice #", info["invoice_number"])
|
| 194 |
+
c1.metric("PO #", info["po_number"])
|
| 195 |
+
c2.metric("Date", info["invoice_date"])
|
| 196 |
+
c2.metric("Value", info["invoice_value"])
|
| 197 |
+
st.subheader("Line Items")
|
| 198 |
+
st.table(info["line_items"])
|
| 199 |
+
else:
|
| 200 |
+
h = info["invoice_header"]
|
| 201 |
+
c1, c2, c3 = st.columns(3)
|
| 202 |
+
c1.metric("Invoice #", h["invoice_number"])
|
| 203 |
+
c1.metric("Supplier", h["supplier_name"])
|
| 204 |
+
c2.metric("Date", h["invoice_date"])
|
| 205 |
+
c2.metric("Customer", h["customer_name"])
|
| 206 |
+
c3.metric("PO #", h["po_number"])
|
| 207 |
+
c3.metric("Total", h["invoice_value"])
|
| 208 |
+
st.subheader("Line Items")
|
| 209 |
+
st.table(info["line_items"])
|
| 210 |
|
| 211 |
if "last_api" in st.session_state:
|
| 212 |
with st.expander("Debug"):
|