Spaces:
Running
Running
Commit
•
d4eadcb
1
Parent(s):
1f38739
infer space
Browse files- viewer/src/routes/bridge.ts +37 -0
viewer/src/routes/bridge.ts
CHANGED
@@ -145,6 +145,7 @@ export const inferFields = async (row: Row): Promise<Row | null> => {
|
|
145 |
const date = row.Date || (await inferDate(row));
|
146 |
const model = row.Model || (await inferModel(row));
|
147 |
const dataset = row.Dataset || (await inferDataset(row));
|
|
|
148 |
const license = row.License || (await inferLicense(row));
|
149 |
if (paper) {
|
150 |
row.Paper = paper;
|
@@ -167,6 +168,9 @@ export const inferFields = async (row: Row): Promise<Row | null> => {
|
|
167 |
if (dataset) {
|
168 |
row.Dataset = dataset;
|
169 |
}
|
|
|
|
|
|
|
170 |
if (license) {
|
171 |
row.License = license;
|
172 |
}
|
@@ -466,6 +470,39 @@ const inferDataset = async (row: Row) => {
|
|
466 |
return data.dataset;
|
467 |
};
|
468 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
469 |
const inferLicense = async (row: Row) => {
|
470 |
statusMessage.append(`<br><span>Inferring license...</span>`);
|
471 |
let data;
|
|
|
145 |
const date = row.Date || (await inferDate(row));
|
146 |
const model = row.Model || (await inferModel(row));
|
147 |
const dataset = row.Dataset || (await inferDataset(row));
|
148 |
+
const space = row.Space || (await inferSpace(row));
|
149 |
const license = row.License || (await inferLicense(row));
|
150 |
if (paper) {
|
151 |
row.Paper = paper;
|
|
|
168 |
if (dataset) {
|
169 |
row.Dataset = dataset;
|
170 |
}
|
171 |
+
if (space) {
|
172 |
+
row.Space = space;
|
173 |
+
}
|
174 |
if (license) {
|
175 |
row.License = license;
|
176 |
}
|
|
|
470 |
return data.dataset;
|
471 |
};
|
472 |
|
473 |
+
const inferSpace = async (row: Row) => {
|
474 |
+
statusMessage.append(`<br><span>Inferring space...</span>`);
|
475 |
+
let data;
|
476 |
+
try {
|
477 |
+
const response = await fetch(baseURL + "/infer-space", {
|
478 |
+
method: "POST",
|
479 |
+
headers: {
|
480 |
+
"Content-Type": "application/json",
|
481 |
+
Authorization: "Bearer " + import.meta.env.VITE_HF_TOKEN,
|
482 |
+
},
|
483 |
+
body: JSON.stringify(row),
|
484 |
+
});
|
485 |
+
data = await response.json();
|
486 |
+
} catch (e) {
|
487 |
+
statusMessage.remove("<br><span>Inferring space...</span>");
|
488 |
+
statusMessage.append(`<br><span style="color: red;">Error: Failed to infer space</span>`);
|
489 |
+
return null;
|
490 |
+
}
|
491 |
+
statusMessage.remove("<br><span>Inferring space...</span>");
|
492 |
+
if (data.error || !data.space) {
|
493 |
+
if (data.error) {
|
494 |
+
statusMessage.append(`<br><span style="color: red;">Error: ${data.error}</span>`);
|
495 |
+
} else if (data.message) {
|
496 |
+
statusMessage.append(`<br><span>${data.message}</span>`);
|
497 |
+
} else {
|
498 |
+
statusMessage.append(`<br><span style="color: red;">Error: Failed to infer space</span>`);
|
499 |
+
}
|
500 |
+
return null;
|
501 |
+
}
|
502 |
+
statusMessage.append(`<br><span style="color: green;">Inferred space: ${data.space}</span>`);
|
503 |
+
return data.space;
|
504 |
+
};
|
505 |
+
|
506 |
const inferLicense = async (row: Row) => {
|
507 |
statusMessage.append(`<br><span>Inferring license...</span>`);
|
508 |
let data;
|