gcp_document_ai / app.py
Omkar008's picture
Update app.py
7c24b00 verified
from fastapi import FastAPI, HTTPException,Query,Request,BackgroundTasks
import json
from authenticate import get_access_token,get_access_token_v1
import os
import requests
from extract_and_store_supabase import extract_structure_store_message
app = FastAPI()
@app.post("/process_document")
async def process_document_base64(request: Request,background_tasks: BackgroundTasks):
request_data = await request.json()
# print(request_data)
if request_data.get('user_id') and request_data.get('message_id') and request_data.get('attachment_id') is None:
return {"error":"attachment not present"}
user_id = request_data.get('user_id')
message_id = request_data.get('message_id')
attachment_id = request_data.get('attachment_id')
attachment_extension = request_data.get('attachment_extension')
email = request_data.get('email')
background_tasks.add_task(extract_structure_store_message,user_id,message_id,attachment_id,attachment_extension,email)
return {"status":'Processing and Updating the data to db!'}