Omkar008 commited on
Commit
2f6db8c
·
verified ·
1 Parent(s): 77fbfd7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -4
app.py CHANGED
@@ -5,12 +5,15 @@ app = FastAPI()
5
 
6
  @app.post("/process-document-base64")
7
  async def process_document_base64(request_data: dict):
8
- # If receiving base64 string directly
 
 
 
9
  payload = {
10
  "skipHumanReview": True,
11
  "rawDocument": {
12
  "mimeType": "application/pdf",
13
- "content": request_data['base64_content']
14
  }
15
  }
16
 
@@ -22,9 +25,9 @@ async def process_document_base64(request_data: dict):
22
  }
23
 
24
  response = requests.post(
25
- 'https://us-documentai.googleapis.com/v1/projects/YOUR_PROJECT_ID/locations/us/processors/YOUR_PROCESSOR_ID:process',
26
  headers=headers,
27
  json=payload
28
  )
29
-
30
  return response.json()
 
5
 
6
  @app.post("/process-document-base64")
7
  async def process_document_base64(request_data: dict):
8
+ project_id = os.getenv('PROJECT_ID')
9
+ processor_id = os.getenv('PROCESSOR_ID')
10
+ if request_data.get('base64_content') is None:
11
+ return {"error":"base64 data not present"}
12
  payload = {
13
  "skipHumanReview": True,
14
  "rawDocument": {
15
  "mimeType": "application/pdf",
16
+ "content": request_data.get('base64_content')
17
  }
18
  }
19
 
 
25
  }
26
 
27
  response = requests.post(
28
+ f'https://us-documentai.googleapis.com/v1/projects/{project_id}/locations/us/processors/{processor_id}:process',
29
  headers=headers,
30
  json=payload
31
  )
32
+ print(response.json())
33
  return response.json()