Skip to content

Instantly share code, notes, and snippets.

@bitchwhocodes
Created January 22, 2018 06:51
Show Gist options
  • Save bitchwhocodes/2b0197a8c7ef261eaf503fef2fd60f0e to your computer and use it in GitHub Desktop.
Save bitchwhocodes/2b0197a8c7ef261eaf503fef2fd60f0e to your computer and use it in GitHub Desktop.
Custom Vision API Prediction - PYthon
import requests
import json
url="YOUR_PREDICTION_ENDPOINT _ AVAIL customvision.ai"
headers={'content-type':'application/octet-stream','Prediction-Key':'YOUR_PREDICTION_KEY'}
r =requests.post(url,data=open("YOUR_LOCAL_IMAGE.jpg","rb"),headers=headers)
print(r.content)
@bw984
Copy link

bw984 commented Aug 28, 2021

Thank you for this gist! The Microsoft documentation for using the API with a local file is lacking when using Python and the standard requests library. I tried many different ways to loading the image to bytes and sending with different requests keywords that did not work, your method works perfectly.

@shahad11
Copy link

Thank you, this code worked for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment