Spaces:
Sleeping
Sleeping
Upload 17 files
Browse files- TODO.md +4 -3
- dashboardlogic.js +28 -1
- package-lock.json +171 -0
- package.json +1 -1
- server.js +28 -0
TODO.md
CHANGED
|
@@ -5,7 +5,8 @@
|
|
| 5 |
- [x] 2. Update package.json to add express, dotenv, node-fetch dependencies
|
| 6 |
- [x] 3. Run `npm install` locally to verify and create/update node_modules/package-lock.json
|
| 7 |
- [x] 4. Test local server: `npm start` (check http://localhost:7860)
|
| 8 |
-
- [
|
| 9 |
-
- [ ]
|
| 10 |
-
- [
|
|
|
|
| 11 |
|
|
|
|
| 5 |
- [x] 2. Update package.json to add express, dotenv, node-fetch dependencies
|
| 6 |
- [x] 3. Run `npm install` locally to verify and create/update node_modules/package-lock.json
|
| 7 |
- [x] 4. Test local server: `npm start` (check http://localhost:7860)
|
| 8 |
+
- [x] 5. Implement file upload (/api/upload + frontend)
|
| 9 |
+
- [ ] Rebuild Docker: `docker build -t hf-gradio-docker-app .`
|
| 10 |
+
- [ ] Run: `docker run -p 7860:7860 -e HF_TOKEN=your_token hf-gradio-docker-app`
|
| 11 |
+
- [x] Task complete
|
| 12 |
|
dashboardlogic.js
CHANGED
|
@@ -426,7 +426,34 @@ async function downloadPreviewFile() {
|
|
| 426 |
async function handleUpload(input) {
|
| 427 |
if (!input.files || !input.files[0]) return;
|
| 428 |
const file = input.files[0];
|
| 429 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 430 |
}
|
| 431 |
|
| 432 |
function handleDrop(e) {
|
|
|
|
| 426 |
async function handleUpload(input) {
|
| 427 |
if (!input.files || !input.files[0]) return;
|
| 428 |
const file = input.files[0];
|
| 429 |
+
loading(true);
|
| 430 |
+
const formData = new FormData();
|
| 431 |
+
formData.append('file', file);
|
| 432 |
+
formData.append('user_id', currentUser);
|
| 433 |
+
formData.append('password', currentPassword);
|
| 434 |
+
// custom_name optional - use file.name
|
| 435 |
+
formData.append('custom_name', file.name);
|
| 436 |
+
try {
|
| 437 |
+
const resp = await fetch('/api/upload', {
|
| 438 |
+
method: 'POST',
|
| 439 |
+
body: formData
|
| 440 |
+
});
|
| 441 |
+
if (!resp.ok) {
|
| 442 |
+
const err = await resp.json();
|
| 443 |
+
throw new Error(err.error || 'Upload failed');
|
| 444 |
+
}
|
| 445 |
+
const result = await resp.json();
|
| 446 |
+
showToast(`Uploaded: ${file.name}`);
|
| 447 |
+
input.value = '';
|
| 448 |
+
// Refresh files
|
| 449 |
+
await loadFiles();
|
| 450 |
+
await loadUserData();
|
| 451 |
+
} catch (err) {
|
| 452 |
+
showToast('Upload failed: ' + err.message);
|
| 453 |
+
console.error(err);
|
| 454 |
+
} finally {
|
| 455 |
+
loading(false);
|
| 456 |
+
}
|
| 457 |
}
|
| 458 |
|
| 459 |
function handleDrop(e) {
|
package-lock.json
CHANGED
|
@@ -11,6 +11,7 @@
|
|
| 11 |
"@gradio/client": "^1.0.0",
|
| 12 |
"dotenv": "^16.4.7",
|
| 13 |
"express": "^4.21.1",
|
|
|
|
| 14 |
"node-fetch": "^3.3.2"
|
| 15 |
}
|
| 16 |
},
|
|
@@ -205,6 +206,12 @@
|
|
| 205 |
"url": "https://github.com/chalk/ansi-styles?sponsor=1"
|
| 206 |
}
|
| 207 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 208 |
"node_modules/array-flatten": {
|
| 209 |
"version": "1.1.1",
|
| 210 |
"resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz",
|
|
@@ -235,6 +242,12 @@
|
|
| 235 |
"npm": "1.2.8000 || >= 1.4.16"
|
| 236 |
}
|
| 237 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 238 |
"node_modules/bufferutil": {
|
| 239 |
"version": "4.1.0",
|
| 240 |
"resolved": "https://registry.npmjs.org/bufferutil/-/bufferutil-4.1.0.tgz",
|
|
@@ -248,6 +261,17 @@
|
|
| 248 |
"node": ">=6.14.2"
|
| 249 |
}
|
| 250 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 251 |
"node_modules/bytes": {
|
| 252 |
"version": "3.1.2",
|
| 253 |
"resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.2.tgz",
|
|
@@ -344,6 +368,21 @@
|
|
| 344 |
"integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==",
|
| 345 |
"license": "MIT"
|
| 346 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 347 |
"node_modules/content-disposition": {
|
| 348 |
"version": "0.5.4",
|
| 349 |
"resolved": "https://registry.npmjs.org/content-disposition/-/content-disposition-0.5.4.tgz",
|
|
@@ -380,6 +419,12 @@
|
|
| 380 |
"integrity": "sha512-NXdYc3dLr47pBkpUCHtKSwIOQXLVn8dZEuywboCOJY/osA0wFSLlSawr3KN8qXJEyX66FcONTH8EIlVuK0yyFA==",
|
| 381 |
"license": "MIT"
|
| 382 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 383 |
"node_modules/data-uri-to-buffer": {
|
| 384 |
"version": "4.0.1",
|
| 385 |
"resolved": "https://registry.npmjs.org/data-uri-to-buffer/-/data-uri-to-buffer-4.0.1.tgz",
|
|
@@ -818,6 +863,12 @@
|
|
| 818 |
"integrity": "sha512-Vg4o6/fqPxIjtxgUH5QLJhwZ7gW5diGCVlXpuUfELC62CuxM1iHcRe51f2W1FDy04Ai4KJkagKjx3XaqyfRKXw==",
|
| 819 |
"license": "MIT"
|
| 820 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 821 |
"node_modules/math-intrinsics": {
|
| 822 |
"version": "1.1.0",
|
| 823 |
"resolved": "https://registry.npmjs.org/math-intrinsics/-/math-intrinsics-1.1.0.tgz",
|
|
@@ -887,6 +938,27 @@
|
|
| 887 |
"node": ">= 0.6"
|
| 888 |
}
|
| 889 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 890 |
"node_modules/ms": {
|
| 891 |
"version": "2.0.0",
|
| 892 |
"resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
|
|
@@ -956,6 +1028,25 @@
|
|
| 956 |
"integrity": "sha512-Yhpw4T9C6hPpgPeA28us07OJeqZ5EzQTkbfwuhsUg0c237RomFoETJgmp2sa3F/41gfLE6G5cqcYwznmeEeOlQ==",
|
| 957 |
"license": "MIT"
|
| 958 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 959 |
"node_modules/mute-stream": {
|
| 960 |
"version": "2.0.0",
|
| 961 |
"resolved": "https://registry.npmjs.org/mute-stream/-/mute-stream-2.0.0.tgz",
|
|
@@ -1023,6 +1114,15 @@
|
|
| 1023 |
"node-gyp-build-test": "build-test.js"
|
| 1024 |
}
|
| 1025 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1026 |
"node_modules/object-inspect": {
|
| 1027 |
"version": "1.13.4",
|
| 1028 |
"resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.13.4.tgz",
|
|
@@ -1074,6 +1174,12 @@
|
|
| 1074 |
"integrity": "sha512-xceH2snhtb5M9liqDsmEw56le376mTZkEX/jEb/RxNFyegNul7eNslCXP9FDj/Lcu0X8KEyMceP2ntpaHrDEVA==",
|
| 1075 |
"license": "ISC"
|
| 1076 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1077 |
"node_modules/proxy-addr": {
|
| 1078 |
"version": "2.0.7",
|
| 1079 |
"resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.7.tgz",
|
|
@@ -1126,6 +1232,27 @@
|
|
| 1126 |
"node": ">= 0.8"
|
| 1127 |
}
|
| 1128 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1129 |
"node_modules/require-directory": {
|
| 1130 |
"version": "2.1.1",
|
| 1131 |
"resolved": "https://registry.npmjs.org/require-directory/-/require-directory-2.1.1.tgz",
|
|
@@ -1320,12 +1447,35 @@
|
|
| 1320 |
"node": ">= 0.8"
|
| 1321 |
}
|
| 1322 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1323 |
"node_modules/strict-event-emitter": {
|
| 1324 |
"version": "0.5.1",
|
| 1325 |
"resolved": "https://registry.npmjs.org/strict-event-emitter/-/strict-event-emitter-0.5.1.tgz",
|
| 1326 |
"integrity": "sha512-vMgjE/GGEPEFnhFub6pa4FmJBRBVOLpIII2hvCZ8Kzb7K0hlHo7mQv6xYrBvCL2LtAIBwFUK8wvuJgTVSQ5MFQ==",
|
| 1327 |
"license": "MIT"
|
| 1328 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1329 |
"node_modules/string-width": {
|
| 1330 |
"version": "4.2.3",
|
| 1331 |
"resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz",
|
|
@@ -1437,6 +1587,12 @@
|
|
| 1437 |
"node": ">= 0.6"
|
| 1438 |
}
|
| 1439 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1440 |
"node_modules/typescript": {
|
| 1441 |
"version": "5.9.3",
|
| 1442 |
"resolved": "https://registry.npmjs.org/typescript/-/typescript-5.9.3.tgz",
|
|
@@ -1468,6 +1624,12 @@
|
|
| 1468 |
"url": "https://github.com/sponsors/kettanaito"
|
| 1469 |
}
|
| 1470 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1471 |
"node_modules/utils-merge": {
|
| 1472 |
"version": "1.0.1",
|
| 1473 |
"resolved": "https://registry.npmjs.org/utils-merge/-/utils-merge-1.0.1.tgz",
|
|
@@ -1530,6 +1692,15 @@
|
|
| 1530 |
}
|
| 1531 |
}
|
| 1532 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1533 |
"node_modules/y18n": {
|
| 1534 |
"version": "5.0.8",
|
| 1535 |
"resolved": "https://registry.npmjs.org/y18n/-/y18n-5.0.8.tgz",
|
|
|
|
| 11 |
"@gradio/client": "^1.0.0",
|
| 12 |
"dotenv": "^16.4.7",
|
| 13 |
"express": "^4.21.1",
|
| 14 |
+
"multer": "^1.4.5-lts.1",
|
| 15 |
"node-fetch": "^3.3.2"
|
| 16 |
}
|
| 17 |
},
|
|
|
|
| 206 |
"url": "https://github.com/chalk/ansi-styles?sponsor=1"
|
| 207 |
}
|
| 208 |
},
|
| 209 |
+
"node_modules/append-field": {
|
| 210 |
+
"version": "1.0.0",
|
| 211 |
+
"resolved": "https://registry.npmjs.org/append-field/-/append-field-1.0.0.tgz",
|
| 212 |
+
"integrity": "sha512-klpgFSWLW1ZEs8svjfb7g4qWY0YS5imI82dTg+QahUvJ8YqAY0P10Uk8tTyh9ZGuYEZEMaeJYCF5BFuX552hsw==",
|
| 213 |
+
"license": "MIT"
|
| 214 |
+
},
|
| 215 |
"node_modules/array-flatten": {
|
| 216 |
"version": "1.1.1",
|
| 217 |
"resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz",
|
|
|
|
| 242 |
"npm": "1.2.8000 || >= 1.4.16"
|
| 243 |
}
|
| 244 |
},
|
| 245 |
+
"node_modules/buffer-from": {
|
| 246 |
+
"version": "1.1.2",
|
| 247 |
+
"resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.2.tgz",
|
| 248 |
+
"integrity": "sha512-E+XQCRwSbaaiChtv6k6Dwgc+bx+Bs6vuKJHHl5kox/BaKbhiXzqQOwK4cO22yElGp2OCmjwVhT3HmxgyPGnJfQ==",
|
| 249 |
+
"license": "MIT"
|
| 250 |
+
},
|
| 251 |
"node_modules/bufferutil": {
|
| 252 |
"version": "4.1.0",
|
| 253 |
"resolved": "https://registry.npmjs.org/bufferutil/-/bufferutil-4.1.0.tgz",
|
|
|
|
| 261 |
"node": ">=6.14.2"
|
| 262 |
}
|
| 263 |
},
|
| 264 |
+
"node_modules/busboy": {
|
| 265 |
+
"version": "1.6.0",
|
| 266 |
+
"resolved": "https://registry.npmjs.org/busboy/-/busboy-1.6.0.tgz",
|
| 267 |
+
"integrity": "sha512-8SFQbg/0hQ9xy3UNTB0YEnsNBbWfhf7RtnzpL7TkBiTBRfrQ9Fxcnz7VJsleJpyp6rVLvXiuORqjlHi5q+PYuA==",
|
| 268 |
+
"dependencies": {
|
| 269 |
+
"streamsearch": "^1.1.0"
|
| 270 |
+
},
|
| 271 |
+
"engines": {
|
| 272 |
+
"node": ">=10.16.0"
|
| 273 |
+
}
|
| 274 |
+
},
|
| 275 |
"node_modules/bytes": {
|
| 276 |
"version": "3.1.2",
|
| 277 |
"resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.2.tgz",
|
|
|
|
| 368 |
"integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==",
|
| 369 |
"license": "MIT"
|
| 370 |
},
|
| 371 |
+
"node_modules/concat-stream": {
|
| 372 |
+
"version": "1.6.2",
|
| 373 |
+
"resolved": "https://registry.npmjs.org/concat-stream/-/concat-stream-1.6.2.tgz",
|
| 374 |
+
"integrity": "sha512-27HBghJxjiZtIk3Ycvn/4kbJk/1uZuJFfuPEns6LaEvpvG1f0hTea8lilrouyo9mVc2GWdcEZ8OLoGmSADlrCw==",
|
| 375 |
+
"engines": [
|
| 376 |
+
"node >= 0.8"
|
| 377 |
+
],
|
| 378 |
+
"license": "MIT",
|
| 379 |
+
"dependencies": {
|
| 380 |
+
"buffer-from": "^1.0.0",
|
| 381 |
+
"inherits": "^2.0.3",
|
| 382 |
+
"readable-stream": "^2.2.2",
|
| 383 |
+
"typedarray": "^0.0.6"
|
| 384 |
+
}
|
| 385 |
+
},
|
| 386 |
"node_modules/content-disposition": {
|
| 387 |
"version": "0.5.4",
|
| 388 |
"resolved": "https://registry.npmjs.org/content-disposition/-/content-disposition-0.5.4.tgz",
|
|
|
|
| 419 |
"integrity": "sha512-NXdYc3dLr47pBkpUCHtKSwIOQXLVn8dZEuywboCOJY/osA0wFSLlSawr3KN8qXJEyX66FcONTH8EIlVuK0yyFA==",
|
| 420 |
"license": "MIT"
|
| 421 |
},
|
| 422 |
+
"node_modules/core-util-is": {
|
| 423 |
+
"version": "1.0.3",
|
| 424 |
+
"resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.3.tgz",
|
| 425 |
+
"integrity": "sha512-ZQBvi1DcpJ4GDqanjucZ2Hj3wEO5pZDS89BWbkcrvdxksJorwUDDZamX9ldFkp9aw2lmBDLgkObEA4DWNJ9FYQ==",
|
| 426 |
+
"license": "MIT"
|
| 427 |
+
},
|
| 428 |
"node_modules/data-uri-to-buffer": {
|
| 429 |
"version": "4.0.1",
|
| 430 |
"resolved": "https://registry.npmjs.org/data-uri-to-buffer/-/data-uri-to-buffer-4.0.1.tgz",
|
|
|
|
| 863 |
"integrity": "sha512-Vg4o6/fqPxIjtxgUH5QLJhwZ7gW5diGCVlXpuUfELC62CuxM1iHcRe51f2W1FDy04Ai4KJkagKjx3XaqyfRKXw==",
|
| 864 |
"license": "MIT"
|
| 865 |
},
|
| 866 |
+
"node_modules/isarray": {
|
| 867 |
+
"version": "1.0.0",
|
| 868 |
+
"resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz",
|
| 869 |
+
"integrity": "sha512-VLghIWNM6ELQzo7zwmcg0NmTVyWKYjvIeM83yjp0wRDTmUnrM678fQbcKBo6n2CJEF0szoG//ytg+TKla89ALQ==",
|
| 870 |
+
"license": "MIT"
|
| 871 |
+
},
|
| 872 |
"node_modules/math-intrinsics": {
|
| 873 |
"version": "1.1.0",
|
| 874 |
"resolved": "https://registry.npmjs.org/math-intrinsics/-/math-intrinsics-1.1.0.tgz",
|
|
|
|
| 938 |
"node": ">= 0.6"
|
| 939 |
}
|
| 940 |
},
|
| 941 |
+
"node_modules/minimist": {
|
| 942 |
+
"version": "1.2.8",
|
| 943 |
+
"resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.8.tgz",
|
| 944 |
+
"integrity": "sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA==",
|
| 945 |
+
"license": "MIT",
|
| 946 |
+
"funding": {
|
| 947 |
+
"url": "https://github.com/sponsors/ljharb"
|
| 948 |
+
}
|
| 949 |
+
},
|
| 950 |
+
"node_modules/mkdirp": {
|
| 951 |
+
"version": "0.5.6",
|
| 952 |
+
"resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.6.tgz",
|
| 953 |
+
"integrity": "sha512-FP+p8RB8OWpF3YZBCrP5gtADmtXApB5AMLn+vdyA+PyxCjrCs00mjyUozssO33cwDeT3wNGdLxJ5M//YqtHAJw==",
|
| 954 |
+
"license": "MIT",
|
| 955 |
+
"dependencies": {
|
| 956 |
+
"minimist": "^1.2.6"
|
| 957 |
+
},
|
| 958 |
+
"bin": {
|
| 959 |
+
"mkdirp": "bin/cmd.js"
|
| 960 |
+
}
|
| 961 |
+
},
|
| 962 |
"node_modules/ms": {
|
| 963 |
"version": "2.0.0",
|
| 964 |
"resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
|
|
|
|
| 1028 |
"integrity": "sha512-Yhpw4T9C6hPpgPeA28us07OJeqZ5EzQTkbfwuhsUg0c237RomFoETJgmp2sa3F/41gfLE6G5cqcYwznmeEeOlQ==",
|
| 1029 |
"license": "MIT"
|
| 1030 |
},
|
| 1031 |
+
"node_modules/multer": {
|
| 1032 |
+
"version": "1.4.5-lts.2",
|
| 1033 |
+
"resolved": "https://registry.npmjs.org/multer/-/multer-1.4.5-lts.2.tgz",
|
| 1034 |
+
"integrity": "sha512-VzGiVigcG9zUAoCNU+xShztrlr1auZOlurXynNvO9GiWD1/mTBbUljOKY+qMeazBqXgRnjzeEgJI/wyjJUHg9A==",
|
| 1035 |
+
"deprecated": "Multer 1.x is impacted by a number of vulnerabilities, which have been patched in 2.x. You should upgrade to the latest 2.x version.",
|
| 1036 |
+
"license": "MIT",
|
| 1037 |
+
"dependencies": {
|
| 1038 |
+
"append-field": "^1.0.0",
|
| 1039 |
+
"busboy": "^1.0.0",
|
| 1040 |
+
"concat-stream": "^1.5.2",
|
| 1041 |
+
"mkdirp": "^0.5.4",
|
| 1042 |
+
"object-assign": "^4.1.1",
|
| 1043 |
+
"type-is": "^1.6.4",
|
| 1044 |
+
"xtend": "^4.0.0"
|
| 1045 |
+
},
|
| 1046 |
+
"engines": {
|
| 1047 |
+
"node": ">= 6.0.0"
|
| 1048 |
+
}
|
| 1049 |
+
},
|
| 1050 |
"node_modules/mute-stream": {
|
| 1051 |
"version": "2.0.0",
|
| 1052 |
"resolved": "https://registry.npmjs.org/mute-stream/-/mute-stream-2.0.0.tgz",
|
|
|
|
| 1114 |
"node-gyp-build-test": "build-test.js"
|
| 1115 |
}
|
| 1116 |
},
|
| 1117 |
+
"node_modules/object-assign": {
|
| 1118 |
+
"version": "4.1.1",
|
| 1119 |
+
"resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz",
|
| 1120 |
+
"integrity": "sha512-rJgTQnkUnH1sFw8yT6VSU3zD3sWmu6sZhIseY8VX+GRu3P6F7Fu+JNDoXfklElbLJSnc3FUQHVe4cU5hj+BcUg==",
|
| 1121 |
+
"license": "MIT",
|
| 1122 |
+
"engines": {
|
| 1123 |
+
"node": ">=0.10.0"
|
| 1124 |
+
}
|
| 1125 |
+
},
|
| 1126 |
"node_modules/object-inspect": {
|
| 1127 |
"version": "1.13.4",
|
| 1128 |
"resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.13.4.tgz",
|
|
|
|
| 1174 |
"integrity": "sha512-xceH2snhtb5M9liqDsmEw56le376mTZkEX/jEb/RxNFyegNul7eNslCXP9FDj/Lcu0X8KEyMceP2ntpaHrDEVA==",
|
| 1175 |
"license": "ISC"
|
| 1176 |
},
|
| 1177 |
+
"node_modules/process-nextick-args": {
|
| 1178 |
+
"version": "2.0.1",
|
| 1179 |
+
"resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-2.0.1.tgz",
|
| 1180 |
+
"integrity": "sha512-3ouUOpQhtgrbOa17J7+uxOTpITYWaGP7/AhoR3+A+/1e9skrzelGi/dXzEYyvbxubEF6Wn2ypscTKiKJFFn1ag==",
|
| 1181 |
+
"license": "MIT"
|
| 1182 |
+
},
|
| 1183 |
"node_modules/proxy-addr": {
|
| 1184 |
"version": "2.0.7",
|
| 1185 |
"resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.7.tgz",
|
|
|
|
| 1232 |
"node": ">= 0.8"
|
| 1233 |
}
|
| 1234 |
},
|
| 1235 |
+
"node_modules/readable-stream": {
|
| 1236 |
+
"version": "2.3.8",
|
| 1237 |
+
"resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.8.tgz",
|
| 1238 |
+
"integrity": "sha512-8p0AUk4XODgIewSi0l8Epjs+EVnWiK7NoDIEGU0HhE7+ZyY8D1IMY7odu5lRrFXGg71L15KG8QrPmum45RTtdA==",
|
| 1239 |
+
"license": "MIT",
|
| 1240 |
+
"dependencies": {
|
| 1241 |
+
"core-util-is": "~1.0.0",
|
| 1242 |
+
"inherits": "~2.0.3",
|
| 1243 |
+
"isarray": "~1.0.0",
|
| 1244 |
+
"process-nextick-args": "~2.0.0",
|
| 1245 |
+
"safe-buffer": "~5.1.1",
|
| 1246 |
+
"string_decoder": "~1.1.1",
|
| 1247 |
+
"util-deprecate": "~1.0.1"
|
| 1248 |
+
}
|
| 1249 |
+
},
|
| 1250 |
+
"node_modules/readable-stream/node_modules/safe-buffer": {
|
| 1251 |
+
"version": "5.1.2",
|
| 1252 |
+
"resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz",
|
| 1253 |
+
"integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==",
|
| 1254 |
+
"license": "MIT"
|
| 1255 |
+
},
|
| 1256 |
"node_modules/require-directory": {
|
| 1257 |
"version": "2.1.1",
|
| 1258 |
"resolved": "https://registry.npmjs.org/require-directory/-/require-directory-2.1.1.tgz",
|
|
|
|
| 1447 |
"node": ">= 0.8"
|
| 1448 |
}
|
| 1449 |
},
|
| 1450 |
+
"node_modules/streamsearch": {
|
| 1451 |
+
"version": "1.1.0",
|
| 1452 |
+
"resolved": "https://registry.npmjs.org/streamsearch/-/streamsearch-1.1.0.tgz",
|
| 1453 |
+
"integrity": "sha512-Mcc5wHehp9aXz1ax6bZUyY5afg9u2rv5cqQI3mRrYkGC8rW2hM02jWuwjtL++LS5qinSyhj2QfLyNsuc+VsExg==",
|
| 1454 |
+
"engines": {
|
| 1455 |
+
"node": ">=10.0.0"
|
| 1456 |
+
}
|
| 1457 |
+
},
|
| 1458 |
"node_modules/strict-event-emitter": {
|
| 1459 |
"version": "0.5.1",
|
| 1460 |
"resolved": "https://registry.npmjs.org/strict-event-emitter/-/strict-event-emitter-0.5.1.tgz",
|
| 1461 |
"integrity": "sha512-vMgjE/GGEPEFnhFub6pa4FmJBRBVOLpIII2hvCZ8Kzb7K0hlHo7mQv6xYrBvCL2LtAIBwFUK8wvuJgTVSQ5MFQ==",
|
| 1462 |
"license": "MIT"
|
| 1463 |
},
|
| 1464 |
+
"node_modules/string_decoder": {
|
| 1465 |
+
"version": "1.1.1",
|
| 1466 |
+
"resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz",
|
| 1467 |
+
"integrity": "sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==",
|
| 1468 |
+
"license": "MIT",
|
| 1469 |
+
"dependencies": {
|
| 1470 |
+
"safe-buffer": "~5.1.0"
|
| 1471 |
+
}
|
| 1472 |
+
},
|
| 1473 |
+
"node_modules/string_decoder/node_modules/safe-buffer": {
|
| 1474 |
+
"version": "5.1.2",
|
| 1475 |
+
"resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz",
|
| 1476 |
+
"integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==",
|
| 1477 |
+
"license": "MIT"
|
| 1478 |
+
},
|
| 1479 |
"node_modules/string-width": {
|
| 1480 |
"version": "4.2.3",
|
| 1481 |
"resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz",
|
|
|
|
| 1587 |
"node": ">= 0.6"
|
| 1588 |
}
|
| 1589 |
},
|
| 1590 |
+
"node_modules/typedarray": {
|
| 1591 |
+
"version": "0.0.6",
|
| 1592 |
+
"resolved": "https://registry.npmjs.org/typedarray/-/typedarray-0.0.6.tgz",
|
| 1593 |
+
"integrity": "sha512-/aCDEGatGvZ2BIk+HmLf4ifCJFwvKFNb9/JeZPMulfgFracn9QFcAf5GO8B/mweUjSoblS5In0cWhqpfs/5PQA==",
|
| 1594 |
+
"license": "MIT"
|
| 1595 |
+
},
|
| 1596 |
"node_modules/typescript": {
|
| 1597 |
"version": "5.9.3",
|
| 1598 |
"resolved": "https://registry.npmjs.org/typescript/-/typescript-5.9.3.tgz",
|
|
|
|
| 1624 |
"url": "https://github.com/sponsors/kettanaito"
|
| 1625 |
}
|
| 1626 |
},
|
| 1627 |
+
"node_modules/util-deprecate": {
|
| 1628 |
+
"version": "1.0.2",
|
| 1629 |
+
"resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz",
|
| 1630 |
+
"integrity": "sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==",
|
| 1631 |
+
"license": "MIT"
|
| 1632 |
+
},
|
| 1633 |
"node_modules/utils-merge": {
|
| 1634 |
"version": "1.0.1",
|
| 1635 |
"resolved": "https://registry.npmjs.org/utils-merge/-/utils-merge-1.0.1.tgz",
|
|
|
|
| 1692 |
}
|
| 1693 |
}
|
| 1694 |
},
|
| 1695 |
+
"node_modules/xtend": {
|
| 1696 |
+
"version": "4.0.2",
|
| 1697 |
+
"resolved": "https://registry.npmjs.org/xtend/-/xtend-4.0.2.tgz",
|
| 1698 |
+
"integrity": "sha512-LKYU1iAXJXUgAXn9URjiu+MWhyUXHsvfp7mcuYm9dSUKK0/CjtrUwFAxD82/mCWbtLsGjFIad0wIsod4zrTAEQ==",
|
| 1699 |
+
"license": "MIT",
|
| 1700 |
+
"engines": {
|
| 1701 |
+
"node": ">=0.4"
|
| 1702 |
+
}
|
| 1703 |
+
},
|
| 1704 |
"node_modules/y18n": {
|
| 1705 |
"version": "5.0.8",
|
| 1706 |
"resolved": "https://registry.npmjs.org/y18n/-/y18n-5.0.8.tgz",
|
package.json
CHANGED
|
@@ -1 +1 @@
|
|
| 1 |
-
{"name":"hf-gradio-docker-app","version":"1.0.0","description":"Connecting to Gradio with HF token","main":"server.js","type":"module","scripts":{"start":"node server.js"},"dependencies":{"@gradio/client":"^1.0.0","express":"^4.21.1","dotenv":"^16.4.7","node-fetch":"^3.3.2"}}
|
|
|
|
| 1 |
+
{"name":"hf-gradio-docker-app","version":"1.0.0","description":"Connecting to Gradio with HF token","main":"server.js","type":"module","scripts":{"start":"node server.js"},"dependencies":{"@gradio/client":"^1.0.0","express":"^4.21.1","dotenv":"^16.4.7","node-fetch":"^3.3.2","multer":"^1.4.5-lts.1"}}
|
server.js
CHANGED
|
@@ -3,6 +3,8 @@ import express from "express";
|
|
| 3 |
import { Client } from "@gradio/client";
|
| 4 |
import dotenv from "dotenv";
|
| 5 |
import fetch from "node-fetch";
|
|
|
|
|
|
|
| 6 |
|
| 7 |
dotenv.config();
|
| 8 |
|
|
@@ -68,6 +70,32 @@ app.get("/api/download", async (req, res) => {
|
|
| 68 |
}
|
| 69 |
});
|
| 70 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
app.use(express.static("."));
|
| 72 |
|
| 73 |
app.listen(PORT, () => {
|
|
|
|
| 3 |
import { Client } from "@gradio/client";
|
| 4 |
import dotenv from "dotenv";
|
| 5 |
import fetch from "node-fetch";
|
| 6 |
+
import multer from "multer";
|
| 7 |
+
const upload = multer();
|
| 8 |
|
| 9 |
dotenv.config();
|
| 10 |
|
|
|
|
| 70 |
}
|
| 71 |
});
|
| 72 |
|
| 73 |
+
app.post("/api/upload", upload.single("file"), async (req, res) => {
|
| 74 |
+
const { user_id, password, custom_name } = req.body;
|
| 75 |
+
if (!req.file || !user_id || !password) {
|
| 76 |
+
return res.status(400).json({ error: "Missing file, user_id, or password" });
|
| 77 |
+
}
|
| 78 |
+
const fileData = {
|
| 79 |
+
data: new Uint8Array(req.file.buffer),
|
| 80 |
+
name: custom_name || req.file.originalname,
|
| 81 |
+
size: req.file.size,
|
| 82 |
+
mime_type: req.file.mimetype
|
| 83 |
+
};
|
| 84 |
+
try {
|
| 85 |
+
const client = await Client.connect("pockit-cloud/main", { hf_token: HF_TOKEN });
|
| 86 |
+
const result = await client.predict("/upload_file_secure", {
|
| 87 |
+
user_id,
|
| 88 |
+
password,
|
| 89 |
+
filepath: fileData,
|
| 90 |
+
custom_name: custom_name || req.file.originalname
|
| 91 |
+
});
|
| 92 |
+
res.json({ data: result.data });
|
| 93 |
+
} catch (err) {
|
| 94 |
+
console.error("Upload error:", err);
|
| 95 |
+
res.status(500).json({ error: "Upload failed", details: err.message });
|
| 96 |
+
}
|
| 97 |
+
});
|
| 98 |
+
|
| 99 |
app.use(express.static("."));
|
| 100 |
|
| 101 |
app.listen(PORT, () => {
|