Spaces:
Sleeping
Sleeping
Update checks/endpoint_check.py
Browse files- checks/endpoint_check.py +33 -0
checks/endpoint_check.py
CHANGED
|
@@ -1,6 +1,39 @@
|
|
| 1 |
import requests
|
| 2 |
import sys
|
| 3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
def is_huggingface_endpoint(endpoint: str):
|
| 5 |
try:
|
| 6 |
headers = {"Authorization": "Bearer YOUR_HUGGINGFACE_API_KEY"}
|
|
|
|
| 1 |
import requests
|
| 2 |
import sys
|
| 3 |
|
| 4 |
+
import requests
|
| 5 |
+
|
| 6 |
+
def is_huggingface_public_endpoint(endpoint: str):
|
| 7 |
+
try:
|
| 8 |
+
# No Authorization header required for public models
|
| 9 |
+
response = requests.get(endpoint)
|
| 10 |
+
|
| 11 |
+
# Check if the response status code is 200 and it returns inference data
|
| 12 |
+
if response.status_code == 200:
|
| 13 |
+
# Public models will return inference data without needing an API key
|
| 14 |
+
if "model" in response.json() or "error" in response.json():
|
| 15 |
+
return True
|
| 16 |
+
else:
|
| 17 |
+
print("The response does not contain inference-related data.")
|
| 18 |
+
return False
|
| 19 |
+
else:
|
| 20 |
+
print(f"Failed to reach the endpoint, status code: {response.status_code}")
|
| 21 |
+
return False
|
| 22 |
+
except requests.exceptions.RequestException as e:
|
| 23 |
+
print(f"Request failed: {e}")
|
| 24 |
+
return False
|
| 25 |
+
|
| 26 |
+
# Example usage:
|
| 27 |
+
# Replace with your public Hugging Face model's endpoint URL
|
| 28 |
+
endpoint = "https://api-inference.huggingface.co/models/gpt2" # Example public model URL
|
| 29 |
+
|
| 30 |
+
if is_huggingface_public_endpoint(endpoint):
|
| 31 |
+
print("This is a valid Hugging Face Inference Endpoint.")
|
| 32 |
+
else:
|
| 33 |
+
print("This is NOT a Hugging Face Inference Endpoint.")
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
|
| 37 |
def is_huggingface_endpoint(endpoint: str):
|
| 38 |
try:
|
| 39 |
headers = {"Authorization": "Bearer YOUR_HUGGINGFACE_API_KEY"}
|