Last active
May 4, 2019 06:13
-
-
Save aribornstein/45df39f21ad9daf4ae9deb49b22911c8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
########### Python Form Recognizer Train ############# | |
from requests import post as http_post | |
# Endpoint URL | |
base_url = r"<Endpoint>" + "/formrecognizer/v1.0-preview/custom" | |
source = r"<SAS URL>" | |
headers = { | |
# Request headers | |
'Content-Type': 'application/json', | |
'Ocp-Apim-Subscription-Key': '<Subscription Key>', | |
} | |
url = base_url + "/train" | |
body = {"source": source} | |
try: | |
resp = http_post(url = url, json = body, headers = headers) | |
print("Response status code: %d" % resp.status_code) | |
print("Response body: %s" % resp.json()) | |
except Exception as e: | |
print(str(e)) | |
########### Python Form Recognizer Analyze ############# | |
from requests import post as http_post | |
# Endpoint URL | |
base_url = r"<Endpoint>" + "/formrecognizer/v1.0-preview/custom" | |
file_path = r"<File Path>" | |
model_id = "<modelID>" | |
headers = { | |
# Request headers | |
'Content-Type': 'application/<file type>', | |
'Ocp-Apim-Subscription-Key': '<subscription key>', | |
} | |
try: | |
url = base_url + "/models/" + model_id + "/analyze" | |
with open(file_path, "rb") as f: | |
data_bytes = f.read() | |
resp = http_post(url = url, data = data_bytes, headers = headers) | |
print("Response status code: %d" % resp.status_code) | |
print("Response body:\n%s" % resp.json()) | |
except Exception as e: | |
print(str(e)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment