Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"recommendations": [
"ms-azuretools.vscode-azurefunctions",
"ms-python.python"
]
}
15 changes: 15 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "Attach to Python Functions",
"type": "debugpy",
"request": "attach",
"connect": {
"host": "localhost",
"port": 9091
},
"preLaunchTask": "func: host start"
}
]
}
8 changes: 8 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"azureFunctions.deploySubpath": "Deployment\\Code",
"azureFunctions.scmDoBuildDuringDeployment": true,
"azureFunctions.pythonVenv": ".venv",
"azureFunctions.projectLanguage": "Python",
"azureFunctions.projectRuntime": "~4",
"debug.internalConsoleOptions": "neverOpen"
}
33 changes: 33 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"version": "2.0.0",
"tasks": [
{
"type": "func",
"label": "func: host start",
"command": "host start",
"problemMatcher": "$func-python-watch",
"isBackground": true,
"dependsOn": "pip install (functions)",
"options": {
"cwd": "${workspaceFolder}/Deployment\\Code"
}
},
{
"label": "pip install (functions)",
"type": "shell",
"osx": {
"command": "${config:azureFunctions.pythonVenv}/bin/python -m pip install -r requirements.txt"
},
"windows": {
"command": "${config:azureFunctions.pythonVenv}\\Scripts\\python -m pip install -r requirements.txt"
},
"linux": {
"command": "${config:azureFunctions.pythonVenv}/bin/python -m pip install -r requirements.txt"
},
"problemMatcher": [],
"options": {
"cwd": "${workspaceFolder}/Deployment\\Code"
}
}
]
}
1 change: 1 addition & 0 deletions Deployment/Code/.funcignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.venv
23 changes: 13 additions & 10 deletions Deployment/Code/RecognizeFile/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,36 +52,39 @@ def main(req: func.HttpRequest) -> func.HttpResponse:
and date_time and year_number and month_number and day_number:
logging.info(f"All required fields are received: {msg}")
else:
http_body_msg = f"Not all required fields are present in requet: {msg} "
return func.HttpResponse(body=http_body_msg, status_code=100)
http_body_msg = f"Not all required fields are present in request: {msg} "
return func.HttpResponse(body=http_body_msg, status_code=400)

my_account_url = f"https://{storage_account}.blob.core.windows.net"
input_blob_url = f"{my_account_url}" + f"{file_path}" # preferred method
input_blob_url = f"{my_account_url}{file_path}" # preferred method

##################################################################
# Establish Security Model
# Use Managed Identity
# RG_MID_CLIENT_ID is the Azure Client ID of the Resource Group Managed Identity. Set in Fuctions App Settings
# RG_MID_CLIENT_ID is the Azure Client ID of the Resource Group Managed Identity. Set in Functions App Settings
client_id = os.getenv("RG_MID_CLIENT_ID")
my_credential = DefaultAzureCredential(managed_identity_client_id=client_id)

##################################################################
# Start working with form recognizer
##################################################################

# All set as environment varibales in Fuctions App Settings
# All set as environment variables in Functions App Settings
fr_endpoint = os.getenv("AZURE_FORM_RECOGNIZER_ENDPOINT")
apim_key = os.getenv("AZURE_FORM_RECOGNIZER_KEY")
model_id = os.getenv("CUSTOM_BUILT_MODEL_ID")

if not (fr_endpoint and apim_key and model_id):
raise ValueError("Form Recognizer endpoint, key, or model ID not found in environment variables.")

document_analysis_client = DocumentAnalysisClient(
endpoint=fr_endpoint, credential=AzureKeyCredential(apim_key))
endpoint=fr_endpoint, credential=AzureKeyCredential(apim_key))

poller = document_analysis_client.begin_analyze_document_from_url(
model=model_id, document_url=input_blob_url)
model_id=model_id, document_url=input_blob_url)
analyzedResult = poller.result() # analyzedResult -AnalyzeResult Class

logging.info(f"form recognizer analyzed successfully.")
logging.info(f"Form recognizer analyzed successfully.")

##################################################################
# End working with form recognizer
Expand Down Expand Up @@ -159,6 +162,7 @@ def main(req: func.HttpRequest) -> func.HttpResponse:

except Exception as ex_main:
logging.error(f"Exception occurred: {ex_main}. ")
return func.HttpResponse(body=f"Error: {str(ex_main)}", status_code=500)
else:
logging.info(f"Processing Successful. Ready save data to Azure Data Lake Storage and then to send response to sender.")
output_data_json = json.dumps(output_data)
Expand All @@ -168,5 +172,4 @@ def main(req: func.HttpRequest) -> func.HttpResponse:
output_blob_client = BlobClient(account_url=my_account_url,container_name=output_container, blob_name=output_file_path_no_container, credential=my_credential)
output_blob_client.upload_blob(output_data_json, overwrite=True, blob_type="BlockBlob")
# return output data to caller as http body
return func.HttpResponse(body=output_data_json, status_code=200)

return func.HttpResponse(body=output_data_json, status_code=200)
2 changes: 1 addition & 1 deletion Deployment/Code/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ azure-storage-blob
azure-identity
requests
#azure-ai-formrecognizer
azure-ai-formrecognizer==3.2.0b3
azure-ai-formrecognizer==3.3.0
PyPDF2==2.5.0