-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
27 lines (21 loc) · 902 Bytes
/
Copy pathmain.py
File metadata and controls
27 lines (21 loc) · 902 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
from fastapi import FastAPI, UploadFile, File
from api.model_loader import classify_document
from api.invoice_extractor import extract_invoice_details
app = FastAPI()
@app.get("/")
def home():
return {"message": "Document Classification & Invoice Extraction API is Running!"}
@app.post("/classify_and_extract")
async def classify_and_extract(file: UploadFile = File(...)): # expects file
content = await file.read()
text = content.decode("utf-8") # Assuming the file is a text file
# Classify the document
category = classify_document(text)
# If it's an invoice, extract the details
if category == "invoice":
extracted_data = extract_invoice_details(text)
return {
"category": category,
"extracted_data": extracted_data
}
return {"category": category, "message": "No extraction needed"}