Handle no-model 503 as online
This commit is contained in:
parent
07064fbf40
commit
508d267078
2 changed files with 39 additions and 7 deletions
|
|
@ -455,19 +455,46 @@ export default function Home() {
|
||||||
const fetchModelInfo = useCallback(async () => {
|
const fetchModelInfo = useCallback(async () => {
|
||||||
try {
|
try {
|
||||||
const response = await fetch('/api/model/info');
|
const response = await fetch('/api/model/info');
|
||||||
if (!response.ok) {
|
let data: any = null;
|
||||||
setIsModelOnline(false);
|
try {
|
||||||
throw new Error('Model info unavailable');
|
data = await response.json();
|
||||||
|
} catch {
|
||||||
|
data = null;
|
||||||
}
|
}
|
||||||
const data: ModelInfoResponse = await response.json();
|
|
||||||
|
if (!response.ok) {
|
||||||
|
const message = data?.error || data?.detail || 'Model info unavailable';
|
||||||
|
|
||||||
|
// Treat "no model" as online-but-unloaded so the selector still works.
|
||||||
|
if (response.status === 503 && /no model/i.test(message)) {
|
||||||
|
setIsModelOnline(true);
|
||||||
|
setPredictionState((prev) => ({
|
||||||
|
...prev,
|
||||||
|
modelInfo: null,
|
||||||
|
selectedLabels: new Set(),
|
||||||
|
error: null,
|
||||||
|
}));
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
setIsModelOnline(false);
|
||||||
|
setPredictionState((prev) => ({
|
||||||
|
...prev,
|
||||||
|
modelInfo: null,
|
||||||
|
error: message,
|
||||||
|
}));
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const modelInfo: ModelInfoResponse = data;
|
||||||
setIsModelOnline(true);
|
setIsModelOnline(true);
|
||||||
setPredictionState((prev) => ({
|
setPredictionState((prev) => ({
|
||||||
...prev,
|
...prev,
|
||||||
modelInfo: data,
|
modelInfo,
|
||||||
selectedLabels: new Set(data.labels),
|
selectedLabels: new Set(modelInfo.labels),
|
||||||
error: null,
|
error: null,
|
||||||
}));
|
}));
|
||||||
return data;
|
return modelInfo;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Failed to fetch model info:', error);
|
console.error('Failed to fetch model info:', error);
|
||||||
setIsModelOnline(false);
|
setIsModelOnline(false);
|
||||||
|
|
|
||||||
|
|
@ -116,6 +116,11 @@ export default function PredictionPanel({
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
{!modelInfo && (
|
||||||
|
<p className="text-[10px] text-muted-foreground">
|
||||||
|
No model loaded. Select a model to enable predictions.
|
||||||
|
</p>
|
||||||
|
)}
|
||||||
|
|
||||||
{/* Action Buttons */}
|
{/* Action Buttons */}
|
||||||
<div className="flex gap-1">
|
<div className="flex gap-1">
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue