Spaces:
Running
Running
File size: 3,289 Bytes
edf3081 11e6e78 edf3081 11e6e78 edf3081 11e6e78 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 | const API_URL = '/api/v1';
export async function checkHealth() {
try {
const response = await fetch(`${API_URL}/health`);
if (!response.ok) throw new Error('API unavailable');
return await response.json();
} catch (error) {
return { status: 'offline', loaded_models: [] };
}
}
export async function analyzeSentiment(text, model = null) {
try {
const response = await fetch(`${API_URL}/predict`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ text, model }),
});
if (!response.ok) {
const errorData = await response.json();
throw new Error(errorData.detail || 'Inference pipeline failed');
}
return await response.json();
} catch (error) {
throw new Error(error.message || 'Failed to connect to inference engine');
}
}
export async function getExplanation(text, model = 'DistilBERT') {
try {
const response = await fetch(`${API_URL}/explain`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ text, model }),
});
if (!response.ok) {
const err = await response.json();
throw new Error(err.detail || 'Explainability failed');
}
return await response.json();
} catch (error) {
throw new Error(error.message || 'Explainability service error');
}
}
export async function getRobustnessBenchmark(refresh = false) {
try {
const response = await fetch(`${API_URL}/robustness/benchmark?refresh=${refresh}`);
if (!response.ok) {
const err = await response.json();
throw new Error(err.detail || 'Benchmark failed');
}
return await response.json();
} catch (error) {
throw new Error(error.message || 'Robustness service error');
}
}
export async function runStressTest(text) {
try {
const response = await fetch(`${API_URL}/robustness/stress-test`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ text }),
});
if (!response.ok) {
const err = await response.json();
throw new Error(err.detail || 'Stress-test failed');
}
return await response.json();
} catch (error) {
throw new Error(error.message || 'Stress-test service error');
}
}
export async function uploadBatchCSV(file, primaryModel = 'DistilBERT') {
try {
const formData = new FormData();
formData.append('file', file);
formData.append('primary_model', primaryModel);
const response = await fetch(`${API_URL}/batch/upload`, {
method: 'POST',
body: formData,
});
if (!response.ok) {
const err = await response.json();
throw new Error(err.detail || 'Batch upload failed');
}
return await response.json();
} catch (error) {
throw new Error(error.message || 'Batch upload error');
}
}
export async function getSampleBatch() {
try {
const response = await fetch(`${API_URL}/batch/sample`);
if (!response.ok) {
const err = await response.json();
throw new Error(err.detail || 'Sample batch failed');
}
return await response.json();
} catch (error) {
throw new Error(error.message || 'Sample batch service error');
}
}
|