Omkar008 commited on
Commit
df6525b
·
verified ·
1 Parent(s): 0c2ac5a

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -0
app.py ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI, HTTPException,Query
2
+ import json
3
+
4
+ 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
+
17
+ access_token = get_access_token()
18
+
19
+ headers = {
20
+ 'Authorization': f'Bearer {access_token}',
21
+ 'Content-Type': 'application/json; charset=utf-8'
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()