Omkar008's picture
Update app.py
53f56c0 verified
raw
history blame
1.04 kB
from fastapi import FastAPI, HTTPException,Query
import json
from authenticate import get_access_token
app = FastAPI()
@app.post("/process-document-base64")
async def process_document_base64(request_data: dict):
project_id = os.getenv('PROJECT_ID')
processor_id = os.getenv('PROCESSOR_ID')
if request_data.get('base64_content') is None:
return {"error":"base64 data not present"}
payload = {
"skipHumanReview": True,
"rawDocument": {
"mimeType": "application/pdf",
"content": request_data.get('base64_content')
}
}
access_token = get_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 response.json()