yetessam commited on
Commit
b7098e7
·
verified ·
1 Parent(s): 3335de4

Create check_endpoint.py

Browse files
Files changed (1) hide show
  1. check_endpoint.py +34 -0
check_endpoint.py ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import requests
3
+
4
+ my_id = os.getenv("QWEN_URI")
5
+
6
+ def is_huggingface_endpoint(endpoint):
7
+ if not endpoint:
8
+ return False
9
+
10
+ try:
11
+ # Send a simple GET or POST request to the endpoint
12
+ headers = {"Authorization": "Bearer YOUR_HUGGINGFACE_API_KEY"} # Replace with your Hugging Face API key if needed
13
+ response = requests.get(endpoint, headers=headers)
14
+
15
+ if response.status_code == 200:
16
+ # Check if the response contains Hugging Face-specific data
17
+ if "model" in response.json():
18
+ return True
19
+ elif response.status_code == 404:
20
+ print("Endpoint not found, make sure the endpoint is correct.")
21
+ else:
22
+ print(f"Error: Received status code {response.status_code}")
23
+
24
+ return False
25
+
26
+ except requests.exceptions.RequestException as e:
27
+ print(f"Request failed: {e}")
28
+ return False
29
+
30
+ # Test the endpoint
31
+ if is_huggingface_endpoint(my_id):
32
+ print("This is a Hugging Face Inference Endpoint.")
33
+ else:
34
+ print("This is NOT a Hugging Face Inference Endpoint.")