TrainThenObtain-ai commited on
Commit
74be0d3
·
1 Parent(s): be74811

Inference API interaction

Browse files
Files changed (1) hide show
  1. inference-api.py +10 -0
inference-api.py ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+ import requests
3
+ headers = {"Authorization": f"Bearer {API_TOKEN}"}
4
+ API_URL = "https://api-inference.huggingface.co/models/google/vit-base-patch16-224"
5
+ def query(filename):
6
+ with open(filename, "rb") as f:
7
+ data = f.read()
8
+ response = requests.request("POST", API_URL, headers=headers, data=data)
9
+ return json.loads(response.content.decode("utf-8"))
10
+ data = query("dust2.jpg")