Create example.py
Browse files- example.py +17 -0
example.py
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import requests
|
| 2 |
+
|
| 3 |
+
API_URL = "https://<use your own Inference Endpoint here>.endpoints.huggingface.cloud"
|
| 4 |
+
headers = {
|
| 5 |
+
"Accept" : "application/json",
|
| 6 |
+
"Authorization": "Bearer hf_XXXXX", # <- use your own Hugging Face token with Inference Endpoints access
|
| 7 |
+
"Content-Type": "application/json"
|
| 8 |
+
}
|
| 9 |
+
|
| 10 |
+
def query(payload):
|
| 11 |
+
response = requests.post(API_URL, headers=headers, json=payload)
|
| 12 |
+
return response.json()
|
| 13 |
+
|
| 14 |
+
output = query({
|
| 15 |
+
"inputs": "Hello world!",
|
| 16 |
+
"parameters": {}
|
| 17 |
+
})
|