from fastapi import FastAPI, HTTPException,Query,Request import json from authenticate import get_access_token import os import requests app = FastAPI() @app.post("/process_document") async def process_document_base64(request: Request): project_id = os.getenv('PROJECT_ID') processor_id = os.getenv('PROCESSOR_ID') request_data = await request.json() # print(request_data) if request_data.get('base64_content') is None: return {"error":"base64 data not present"} message_id = request_data.get('message_id') filename = request_data.get('filename') payload = { "skipHumanReview": True, "rawDocument": { "mimeType": "application/pdf", "content": request_data.get('base64_content') } } access_token = get_access_token() print("printing access_token") print(access_token) headers = { 'Authorization': f'Bearer {access_token}', 'Content-Type': 'application/json; charset=utf-8' } response = requests.post( f'https://us-documentai.googleapis.com/v1/projects/{project_id}/locations/us/processors/{processor_id}:process', headers=headers, json=payload ) print(response.json()) return {"message_id":message_id , "filename":filename , "entities_data":response.json()}