I ended up using custom python code to use my classification model:
def _post_to_classification_model(pdf_bytes: bytes) -> dict:
"""
Using configured form recognizer key and model specifications from config,
post the pdf to the and azure ai classification model for prediction.
Returns the post response.
"""
FORM_RECOGNIZER_KEY = os.getenv("FORM_RECOGNIZER_KEY")
post_url = (
ENDPOINT
+ f"/formrecognizer/{API_TYPE}/{FACEPAGE_CLASSIFICATION_MODEL_ID}:analyze?api-version={API_VERSION}"
)
params = {"includeTextDetails": True}
headers = {
# Request headers
"Content-Type": "application/pdf",
"Ocp-Apim-Subscription-Key": FORM_RECOGNIZER_KEY,
}
logger.debug(f"FORM REC KEY IS: {FORM_RECOGNIZER_KEY}")
try:
resp = post(
url=post_url, data=pdf_bytes, headers=headers, params=params
)
if resp.status_code != 202:
logger.warning(
"POST analyze failed:\n%s" % json.dumps(resp.json())
)
quit()
logger.info("POST analyze succeeded:\n%s" % resp.headers)
except Exception as e:
logger.warning("POST analyze failed:\n%s" % str(e))
return resp
def _get_classification_results(post_response: dict) -> dict:
"""
Given our response from our post request for classification,
retrieve the classificaiton results. Returns the get response.
"""
get_url = post_response.headers["operation-location"]
n_tries = 15
n_try = 0
wait_sec = 5
max_wait_sec = 60
resp_json = None
while n_try < n_tries:
try:
resp = get(
url=get_url,
headers={
"Ocp-Apim-Subscription-Key": os.getenv(
"FORM_RECOGNIZER_KEY"
)
},
)
resp_json = resp.json()
if resp.status_code != 200:
logger.warning(
"GET analyze results failed:\n%s" % json.dumps(resp_json)
)
break
status = resp_json["status"]
if status == "succeeded":
logger.info("Analysis succeeded:\n%s" % json.dumps(resp_json))
break
if status == "failed":
logger.warning("Analysis failed:\n%s" % json.dumps(resp_json))
break
# Analysis still running. Wait and retry.
time.sleep(wait_sec)
n_try += 1
wait_sec = min(2 * wait_sec, max_wait_sec)
except Exception as e:
msg = "GET analyze results failed:\n%s" % str(e)
logger.warning(msg)
break
return resp_json