from fastapi import FastAPI, UploadFile, File from fastapi.responses import HTMLResponse import shutil from inference import process_document # from json_handling import process_whole_doc from model_loader import get_model app = FastAPI() @app.on_event("startup") def startup_event(): print("Starting application...") print("Loading model before API becomes ready...") get_model() print("Startup complete. API is ready.") @app.get("/", response_class=HTMLResponse) def root(): return """
Use POST /extract to upload file
Go to API Docs """ @app.post("/extract") async def extract(file: UploadFile = File(...)): file_path = f"/tmp/{file.filename}" with open(file_path, "wb") as buffer: shutil.copyfileobj(file.file, buffer) result = process_document(file_path) # result = process_whole_doc(file_path) # return {"result": result} return result