Skip to content

Instantly share code, notes, and snippets.

@amrrs
Created October 12, 2022 15:16
Show Gist options
  • Save amrrs/0c6114896c66df20760a8727c3f6aadc to your computer and use it in GitHub Desktop.
Save amrrs/0c6114896c66df20760a8727c3f6aadc to your computer and use it in GitHub Desktop.
import requests
model_id = "nvidia/segformer-b0-finetuned-ade-512-512"
api_token = # get yours at hf.co/settings/tokens
headers = {"Authorization": f"Bearer {api_token}"}
API_URL = f"https://api-inference.huggingface.co/models/{model_id}"
def query(data, model_id, api_token):
with open(filename, "rb") as f:
data = f.read()
response = requests.post(API_URL, headers=headers, data=data)
return response.json()
filename = 'SCR-tfa.jpeg'
data = query(filename, model_id, api_token)
print(data)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment