File size: 1,349 Bytes
fd238c0
df6525b
77fbfd7
9c28f03
06baaec
 
df6525b
 
d8cffed
fd238c0
2f6db8c
 
d2f7dce
ba400dd
2f6db8c
 
d2f7dce
 
df6525b
 
 
 
2f6db8c
df6525b
 
 
956f6b8
ba400dd
bb3be13
df6525b
 
 
 
 
 
 
2f6db8c
df6525b
 
 
2f6db8c
d2f7dce
53f56c0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
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_v1()
    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()}