import time import base64 import sendfile import json from fastapi import FastAPI from pydantic import BaseModel from pydantic_core import from_json from fastapi.encoders import jsonable_encoder from fastapi.responses import JSONResponse app = FastAPI() from fastapi import FastAPI from fastapi.middleware.cors import CORSMiddleware app = FastAPI() # You can add additional URLs to this list, for example, the frontend's production domain, or other frontends. allowed_origins = [ "https://ai-idrocap.wgscloudlab.it", "https://localhost", "https://delta.webgenesys.it" ] app.add_middleware( CORSMiddleware, allow_origins=allowed_origins, allow_credentials=True, allow_methods=["GET", "POST", "PUT", "DELETE"], allow_headers=["X-Requested-With", "Content-Type"], ) class ResponseJson(BaseModel): authority_identification_code_civil_engineering_office: str applicants_0_tax_code: str applicants_0_vat_number: str concession_decree_number: str release_date: str expiration_date: str class FileInfo(BaseModel): type: str documentHash: str fileContent: str @app.post("/extract_info/") async def extract_info(user_data: FileInfo): filestr = user_data.documentHash filedata = base64.b64decode(user_data.fileContent) filename = '%s.pdf' % filestr with open(filename, 'wb') as f: f.write(filedata) resp=ResponseJson(authority_identification_code_civil_engineering_office="AA0000",applicants_0_tax_code="ABCDEF12G34H567I",applicants_0_vat_number="01234567890",concession_decree_number="12345",release_date="2024-10-23",expiration_date="2026-10-23") jresp =jsonable_encoder(resp) response= json.loads(sendfile.sendFile(filename,filestr)) return response if __name__ == "__main__": import uvicorn uvicorn.run(app, host="0.0.0.0", port=443,ssl_keyfile="./SSL/wgscloudlab.key",ssl_certfile="./SSL/wgscloudlab.crt")