Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -18,10 +18,14 @@ HF_API_URL = "https://api-inference.huggingface.co/models/facebook/detr-resnet-5
|
|
| 18 |
|
| 19 |
def query_hugging_face(image_data):
|
| 20 |
if not HF_API_TOKEN:
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
|
| 26 |
@app.route('/')
|
| 27 |
def index():
|
|
|
|
| 18 |
|
| 19 |
def query_hugging_face(image_data):
|
| 20 |
if not HF_API_TOKEN:
|
| 21 |
+
return {"error": "Hugging Face API token not set. Please set the HF_API_TOKEN environment variable."}
|
| 22 |
+
try:
|
| 23 |
+
headers = {"Authorization": f"Bearer {HF_API_TOKEN}"}
|
| 24 |
+
response = requests.post(HF_API_URL, headers=headers, data=image_data, timeout=10)
|
| 25 |
+
response.raise_for_status() # Raise an error for bad status codes
|
| 26 |
+
return response.json()
|
| 27 |
+
except requests.exceptions.RequestException as e:
|
| 28 |
+
return {"error": f"Failed to connect to Hugging Face API: {str(e)}"}
|
| 29 |
|
| 30 |
@app.route('/')
|
| 31 |
def index():
|