Spaces:
Sleeping
Sleeping
Commit
·
42cce6f
1
Parent(s):
b028028
show error
Browse files- hf_api.py +20 -5
- templates/dashboard.html +17 -2
hf_api.py
CHANGED
|
@@ -104,17 +104,32 @@ class HuggingFaceAPI:
|
|
| 104 |
except Exception:
|
| 105 |
return []
|
| 106 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 107 |
def wake_spaces(self, space_ids, progress_callback=None):
|
| 108 |
"""Wake multiple spaces, returning results."""
|
| 109 |
total = len(space_ids)
|
| 110 |
results = []
|
| 111 |
|
| 112 |
for i, space_id in enumerate(space_ids):
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
results.append({"id": space_id, "success": True})
|
| 116 |
-
except Exception as e:
|
| 117 |
-
results.append({"id": space_id, "success": False, "error": str(e)})
|
| 118 |
|
| 119 |
if progress_callback:
|
| 120 |
progress_callback("wake", i + 1, total)
|
|
|
|
| 104 |
except Exception:
|
| 105 |
return []
|
| 106 |
|
| 107 |
+
def restart_space_safe(self, space_id):
|
| 108 |
+
"""Restart a space, returning detailed result."""
|
| 109 |
+
try:
|
| 110 |
+
url = f"{self.BASE_URL}/spaces/{space_id}/restart"
|
| 111 |
+
resp = self.session.post(url, timeout=15)
|
| 112 |
+
if resp.status_code == 200:
|
| 113 |
+
return {"id": space_id, "success": True}
|
| 114 |
+
else:
|
| 115 |
+
# Try to get error message from response
|
| 116 |
+
try:
|
| 117 |
+
error_data = resp.json()
|
| 118 |
+
error_msg = error_data.get("error", resp.text[:200])
|
| 119 |
+
except Exception:
|
| 120 |
+
error_msg = f"HTTP {resp.status_code}: {resp.text[:200]}"
|
| 121 |
+
return {"id": space_id, "success": False, "error": error_msg}
|
| 122 |
+
except Exception as e:
|
| 123 |
+
return {"id": space_id, "success": False, "error": str(e)}
|
| 124 |
+
|
| 125 |
def wake_spaces(self, space_ids, progress_callback=None):
|
| 126 |
"""Wake multiple spaces, returning results."""
|
| 127 |
total = len(space_ids)
|
| 128 |
results = []
|
| 129 |
|
| 130 |
for i, space_id in enumerate(space_ids):
|
| 131 |
+
result = self.restart_space_safe(space_id)
|
| 132 |
+
results.append(result)
|
|
|
|
|
|
|
|
|
|
| 133 |
|
| 134 |
if progress_callback:
|
| 135 |
progress_callback("wake", i + 1, total)
|
templates/dashboard.html
CHANGED
|
@@ -490,9 +490,14 @@
|
|
| 490 |
}
|
| 491 |
.progress-result {
|
| 492 |
font-size: 0.75rem;
|
| 493 |
-
padding: 0.
|
| 494 |
display: flex;
|
| 495 |
justify-content: space-between;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 496 |
}
|
| 497 |
.progress-result.success {
|
| 498 |
color: #22c55e;
|
|
@@ -500,6 +505,14 @@
|
|
| 500 |
.progress-result.error {
|
| 501 |
color: #ef4444;
|
| 502 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 503 |
</style>
|
| 504 |
</head>
|
| 505 |
<body>
|
|
@@ -731,7 +744,9 @@
|
|
| 731 |
result.results.forEach(r => {
|
| 732 |
const div = document.createElement('div');
|
| 733 |
div.className = 'progress-result ' + (r.success ? 'success' : 'error');
|
| 734 |
-
|
|
|
|
|
|
|
| 735 |
wakeResults.appendChild(div);
|
| 736 |
});
|
| 737 |
}
|
|
|
|
| 490 |
}
|
| 491 |
.progress-result {
|
| 492 |
font-size: 0.75rem;
|
| 493 |
+
padding: 0.375rem 0;
|
| 494 |
display: flex;
|
| 495 |
justify-content: space-between;
|
| 496 |
+
gap: 0.5rem;
|
| 497 |
+
border-bottom: 1px solid #1a1a1a;
|
| 498 |
+
}
|
| 499 |
+
.progress-result:last-child {
|
| 500 |
+
border-bottom: none;
|
| 501 |
}
|
| 502 |
.progress-result.success {
|
| 503 |
color: #22c55e;
|
|
|
|
| 505 |
.progress-result.error {
|
| 506 |
color: #ef4444;
|
| 507 |
}
|
| 508 |
+
.progress-result span:first-child {
|
| 509 |
+
flex-shrink: 0;
|
| 510 |
+
}
|
| 511 |
+
.progress-result span:last-child {
|
| 512 |
+
text-align: right;
|
| 513 |
+
word-break: break-word;
|
| 514 |
+
max-width: 200px;
|
| 515 |
+
}
|
| 516 |
</style>
|
| 517 |
</head>
|
| 518 |
<body>
|
|
|
|
| 744 |
result.results.forEach(r => {
|
| 745 |
const div = document.createElement('div');
|
| 746 |
div.className = 'progress-result ' + (r.success ? 'success' : 'error');
|
| 747 |
+
const name = r.id.split('/')[1];
|
| 748 |
+
const status = r.success ? 'OK' : (r.error || 'Failed');
|
| 749 |
+
div.innerHTML = `<span>${name}</span><span title="${r.error || ''}">${status}</span>`;
|
| 750 |
wakeResults.appendChild(div);
|
| 751 |
});
|
| 752 |
}
|