SoumyaJ commited on
Commit
98c4f66
·
verified ·
1 Parent(s): f6ae6ed

Update api_handler.py

Browse files
Files changed (1) hide show
  1. api_handler.py +32 -32
api_handler.py CHANGED
@@ -1,33 +1,33 @@
1
- from fastapi import FastAPI, UploadFile,File
2
- from fastapi.responses import JSONResponse
3
- from fastapi.middleware.cors import CORSMiddleware
4
- from app_forapi import extract_fields_from_pdf
5
- from contractapp_forapi import extract_data
6
- import uvicorn
7
-
8
-
9
- app = FastAPI()
10
-
11
-
12
- # CORS middleware to allow requests from any origin
13
- app.add_middleware(
14
- CORSMiddleware,
15
- allow_origins=["*"],
16
- allow_credentials=True,
17
- allow_methods=["*"],
18
- allow_headers=["*"],
19
- )
20
-
21
- @app.post("/extract-agent-info/")
22
- async def extract_details(file: UploadFile = File(...)):
23
- try:
24
- if "163900" in file.filename:
25
- result = extract_fields_from_pdf(file)
26
- else:
27
- result = extract_data(file)
28
- return result
29
- except Exception as e:
30
- return JSONResponse(status_code=500, content={"error": str(e)})
31
-
32
- if __name__ == "__main__":
33
  uvicorn.run(app, host="0.0.0.0", port=8000)
 
1
+ from fastapi import FastAPI, UploadFile,File
2
+ from fastapi.responses import JSONResponse
3
+ from fastapi.middleware.cors import CORSMiddleware
4
+ from app_forapi import extract_fields_from_pdf
5
+ from contractapp_forapi import extract_data
6
+ import uvicorn
7
+
8
+
9
+ app = FastAPI()
10
+
11
+
12
+ # CORS middleware to allow requests from any origin
13
+ app.add_middleware(
14
+ CORSMiddleware,
15
+ allow_origins=["*"],
16
+ allow_credentials=True,
17
+ allow_methods=["*"],
18
+ allow_headers=["*"],
19
+ )
20
+
21
+ @app.post("/api/v1/extract-agent-info")
22
+ async def extract_details(file: UploadFile = File(...)):
23
+ try:
24
+ if "163900" in file.filename:
25
+ result = extract_fields_from_pdf(file)
26
+ else:
27
+ result = extract_data(file)
28
+ return result
29
+ except Exception as e:
30
+ return JSONResponse(status_code=500, content={"error": str(e)})
31
+
32
+ if __name__ == "__main__":
33
  uvicorn.run(app, host="0.0.0.0", port=8000)