Spaces:
Sleeping
Sleeping
Download main.py from satvaSolutions/invoice-ocr-api: direct link, hf CLI and curl.
- Browser
- Download file 765 Bytes
-
https://huggingface.co/spaces/satvaSolutions/invoice-ocr-api/resolve/main/main.py
- Command line
-
hf download hf://spaces/satvaSolutions/invoice-ocr-api/main.py
-
curl -L -o main.py https://huggingface.co/spaces/satvaSolutions/invoice-ocr-api/resolve/main/main.py
765 Bytes
| from fastapi import FastAPI, File, UploadFile | |
| from fastapi.responses import JSONResponse | |
| import shutil | |
| import os | |
| from model_utils import extract_invoice_data_from_image | |
| app = FastAPI() | |
| UPLOAD_DIR = "uploads" | |
| os.makedirs(UPLOAD_DIR, exist_ok=True) | |
| async def extract_invoice(file: UploadFile = File(...)): | |
| # Save the uploaded image temporarily | |
| file_location = os.path.join(UPLOAD_DIR, file.filename) | |
| with open(file_location, "wb") as f: | |
| shutil.copyfileobj(file.file, f) | |
| # Run OCR + detection | |
| extracted_data = extract_invoice_data_from_image(file_location) | |
| # Optionally, clean up the uploaded file | |
| os.remove(file_location) | |
| return JSONResponse(content=extracted_data) | |