Spaces:
Sleeping
Sleeping
dylanebert commited on
Commit ·
b116f4c
1
Parent(s): df342e6
add license
Browse files- viewer/src/routes/+page.svelte +18 -0
- viewer/src/routes/bridge.ts +37 -0
viewer/src/routes/+page.svelte
CHANGED
|
@@ -195,6 +195,24 @@
|
|
| 195 |
},
|
| 196 |
parseHTML: true,
|
| 197 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 198 |
{
|
| 199 |
key: "Space",
|
| 200 |
title: "Space",
|
|
|
|
| 195 |
},
|
| 196 |
parseHTML: true,
|
| 197 |
},
|
| 198 |
+
{
|
| 199 |
+
key: "License",
|
| 200 |
+
title: "License",
|
| 201 |
+
value: (v: Row) => v.License || "",
|
| 202 |
+
sortable: true,
|
| 203 |
+
searchValue: (v: Row) => v.License || "",
|
| 204 |
+
renderValue: (v: Row) => {
|
| 205 |
+
if (!v.License) return "";
|
| 206 |
+
|
| 207 |
+
let displayLicense = v.License;
|
| 208 |
+
if (v.License.length > 24) {
|
| 209 |
+
displayLicense = v.License.slice(0, 20) + "...";
|
| 210 |
+
}
|
| 211 |
+
|
| 212 |
+
return `<span title="${v.License}">${displayLicense}</span>`;
|
| 213 |
+
},
|
| 214 |
+
parseHTML: true,
|
| 215 |
+
},
|
| 216 |
{
|
| 217 |
key: "Space",
|
| 218 |
title: "Space",
|
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 |
if (paper) {
|
| 149 |
row.Paper = paper;
|
| 150 |
}
|
|
@@ -166,6 +167,9 @@ export const inferFields = async (row: Row): Promise<Row | null> => {
|
|
| 166 |
if (dataset) {
|
| 167 |
row.Dataset = dataset;
|
| 168 |
}
|
|
|
|
|
|
|
|
|
|
| 169 |
statusMessage.append(`<br><span style="color: green;">Finished inferring fields for <b>${row.Name}</b></span>`);
|
| 170 |
return row;
|
| 171 |
};
|
|
@@ -461,3 +465,36 @@ const inferDataset = async (row: Row) => {
|
|
| 461 |
statusMessage.append(`<br><span style="color: green;">Inferred dataset: ${data.dataset}</span>`);
|
| 462 |
return data.dataset;
|
| 463 |
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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;
|
| 151 |
}
|
|
|
|
| 167 |
if (dataset) {
|
| 168 |
row.Dataset = dataset;
|
| 169 |
}
|
| 170 |
+
if (license) {
|
| 171 |
+
row.License = license;
|
| 172 |
+
}
|
| 173 |
statusMessage.append(`<br><span style="color: green;">Finished inferring fields for <b>${row.Name}</b></span>`);
|
| 174 |
return row;
|
| 175 |
};
|
|
|
|
| 465 |
statusMessage.append(`<br><span style="color: green;">Inferred dataset: ${data.dataset}</span>`);
|
| 466 |
return data.dataset;
|
| 467 |
};
|
| 468 |
+
|
| 469 |
+
const inferLicense = async (row: Row) => {
|
| 470 |
+
statusMessage.append(`<br><span>Inferring license...</span>`);
|
| 471 |
+
let data;
|
| 472 |
+
try {
|
| 473 |
+
const response = await fetch(baseURL + "/infer-license", {
|
| 474 |
+
method: "POST",
|
| 475 |
+
headers: {
|
| 476 |
+
"Content-Type": "application/json",
|
| 477 |
+
Authorization: "Bearer " + import.meta.env.VITE_HF_TOKEN,
|
| 478 |
+
},
|
| 479 |
+
body: JSON.stringify(row),
|
| 480 |
+
});
|
| 481 |
+
data = await response.json();
|
| 482 |
+
} catch (e) {
|
| 483 |
+
statusMessage.remove("<br><span>Inferring license...</span>");
|
| 484 |
+
statusMessage.append(`<br><span style="color: red;">Error: Failed to infer license</span>`);
|
| 485 |
+
return null;
|
| 486 |
+
}
|
| 487 |
+
statusMessage.remove("<br><span>Inferring license...</span>");
|
| 488 |
+
if (data.error || !data.license) {
|
| 489 |
+
if (data.error) {
|
| 490 |
+
statusMessage.append(`<br><span style="color: red;">Error: ${data.error}</span>`);
|
| 491 |
+
} else if (data.message) {
|
| 492 |
+
statusMessage.append(`<br><span>${data.message}</span>`);
|
| 493 |
+
} else {
|
| 494 |
+
statusMessage.append(`<br><span style="color: red;">Error: Failed to infer license</span>`);
|
| 495 |
+
}
|
| 496 |
+
return null;
|
| 497 |
+
}
|
| 498 |
+
statusMessage.append(`<br><span style="color: green;">Inferred license: ${data.license}</span>`);
|
| 499 |
+
return data.license;
|
| 500 |
+
};
|