ATMOrdersExtraction / api_handler.py
SoumyaJ's picture
Update api_handler.py
98c4f66 verified
raw
history blame contribute delete
915 Bytes
from fastapi import FastAPI, UploadFile,File
from fastapi.responses import JSONResponse
from fastapi.middleware.cors import CORSMiddleware
from app_forapi import extract_fields_from_pdf
from contractapp_forapi import extract_data
import uvicorn
app = FastAPI()
# CORS middleware to allow requests from any origin
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
@app.post("/api/v1/extract-agent-info")
async def extract_details(file: UploadFile = File(...)):
try:
if "163900" in file.filename:
result = extract_fields_from_pdf(file)
else:
result = extract_data(file)
return result
except Exception as e:
return JSONResponse(status_code=500, content={"error": str(e)})
if __name__ == "__main__":
uvicorn.run(app, host="0.0.0.0", port=8000)