Spaces:
Runtime error
Runtime error
Upload 16 files
Browse files- dashboardlogic.js +3 -3
- server.js +3 -6
dashboardlogic.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
| 1 |
-
|
| 2 |
// import { Client } from "https://cdn.jsdelivr.net/npm/@gradio/client@1.9.0/dist/index.min.js";
|
| 3 |
|
| 4 |
// Read/write tokens from sessionStorage
|
|
@@ -282,6 +281,8 @@ function openPreview(id) {
|
|
| 282 |
selected.clear();
|
| 283 |
selected.add(id);
|
| 284 |
render(files);
|
|
|
|
|
|
|
| 285 |
// Load preview content for a file using /handle_preview_secure and /get_preview_text_action
|
| 286 |
async function loadPreviewContent(file) {
|
| 287 |
if (!file || !file.name) return;
|
|
@@ -335,7 +336,6 @@ function escapeHtml(str) {
|
|
| 335 |
.replace(/"/g, '"')
|
| 336 |
.replace(/'/g, ''');
|
| 337 |
}
|
| 338 |
-
}
|
| 339 |
|
| 340 |
// Delete single file
|
| 341 |
async function deleteFile(id) {
|
|
@@ -560,4 +560,4 @@ window.logoutUser = logoutUser;
|
|
| 560 |
window.openModal = openModal;
|
| 561 |
window.closeModal = closeModal;
|
| 562 |
window.loading = loading;
|
| 563 |
-
window.showToast = showToast;
|
|
|
|
|
|
|
| 1 |
// import { Client } from "https://cdn.jsdelivr.net/npm/@gradio/client@1.9.0/dist/index.min.js";
|
| 2 |
|
| 3 |
// Read/write tokens from sessionStorage
|
|
|
|
| 281 |
selected.clear();
|
| 282 |
selected.add(id);
|
| 283 |
render(files);
|
| 284 |
+
}
|
| 285 |
+
|
| 286 |
// Load preview content for a file using /handle_preview_secure and /get_preview_text_action
|
| 287 |
async function loadPreviewContent(file) {
|
| 288 |
if (!file || !file.name) return;
|
|
|
|
| 336 |
.replace(/"/g, '"')
|
| 337 |
.replace(/'/g, ''');
|
| 338 |
}
|
|
|
|
| 339 |
|
| 340 |
// Delete single file
|
| 341 |
async function deleteFile(id) {
|
|
|
|
| 560 |
window.openModal = openModal;
|
| 561 |
window.closeModal = closeModal;
|
| 562 |
window.loading = loading;
|
| 563 |
+
window.showToast = showToast;
|
server.js
CHANGED
|
@@ -4,7 +4,6 @@ import { Client } from "@gradio/client";
|
|
| 4 |
import dotenv from "dotenv";
|
| 5 |
import fetch from "node-fetch";
|
| 6 |
|
| 7 |
-
// Load environment variables (HF_TOKEN)
|
| 8 |
dotenv.config();
|
| 9 |
|
| 10 |
const app = express();
|
|
@@ -18,13 +17,13 @@ if (!HF_TOKEN) {
|
|
| 18 |
|
| 19 |
app.use(express.json({ limit: "10mb" }));
|
| 20 |
|
| 21 |
-
// Secure proxy endpoint for Gradio API
|
| 22 |
app.post("/api/proxy", async (req, res) => {
|
| 23 |
const { fn, args } = req.body;
|
| 24 |
if (!fn) return res.status(400).json({ error: "Missing 'fn' in request body" });
|
| 25 |
|
| 26 |
try {
|
| 27 |
const client = await Client.connect("pockit-cloud/main", { hf_token: HF_TOKEN });
|
|
|
|
| 28 |
const result = await client.predict(fn, args);
|
| 29 |
res.json({ data: result.data });
|
| 30 |
} catch (err) {
|
|
@@ -33,12 +32,11 @@ app.post("/api/proxy", async (req, res) => {
|
|
| 33 |
}
|
| 34 |
});
|
| 35 |
|
| 36 |
-
// Download endpoint
|
| 37 |
app.get("/api/download", async (req, res) => {
|
| 38 |
const { file } = req.query;
|
| 39 |
if (!file) return res.status(400).json({ error: "Missing 'file' query param" });
|
| 40 |
|
| 41 |
-
// Example: file = "username/dataset/blob/main/path/to/file.txt"
|
| 42 |
const url = `https://huggingface.co/datasets/${file}`;
|
| 43 |
try {
|
| 44 |
const response = await fetch(url, {
|
|
@@ -56,9 +54,8 @@ app.get("/api/download", async (req, res) => {
|
|
| 56 |
}
|
| 57 |
});
|
| 58 |
|
| 59 |
-
// Serve static files (frontend)
|
| 60 |
app.use(express.static("."));
|
| 61 |
|
| 62 |
app.listen(PORT, () => {
|
| 63 |
console.log(`Server running on port ${PORT}`);
|
| 64 |
-
});
|
|
|
|
| 4 |
import dotenv from "dotenv";
|
| 5 |
import fetch from "node-fetch";
|
| 6 |
|
|
|
|
| 7 |
dotenv.config();
|
| 8 |
|
| 9 |
const app = express();
|
|
|
|
| 17 |
|
| 18 |
app.use(express.json({ limit: "10mb" }));
|
| 19 |
|
|
|
|
| 20 |
app.post("/api/proxy", async (req, res) => {
|
| 21 |
const { fn, args } = req.body;
|
| 22 |
if (!fn) return res.status(400).json({ error: "Missing 'fn' in request body" });
|
| 23 |
|
| 24 |
try {
|
| 25 |
const client = await Client.connect("pockit-cloud/main", { hf_token: HF_TOKEN });
|
| 26 |
+
// Pass args directly to predict
|
| 27 |
const result = await client.predict(fn, args);
|
| 28 |
res.json({ data: result.data });
|
| 29 |
} catch (err) {
|
|
|
|
| 32 |
}
|
| 33 |
});
|
| 34 |
|
| 35 |
+
// Download endpoint
|
| 36 |
app.get("/api/download", async (req, res) => {
|
| 37 |
const { file } = req.query;
|
| 38 |
if (!file) return res.status(400).json({ error: "Missing 'file' query param" });
|
| 39 |
|
|
|
|
| 40 |
const url = `https://huggingface.co/datasets/${file}`;
|
| 41 |
try {
|
| 42 |
const response = await fetch(url, {
|
|
|
|
| 54 |
}
|
| 55 |
});
|
| 56 |
|
|
|
|
| 57 |
app.use(express.static("."));
|
| 58 |
|
| 59 |
app.listen(PORT, () => {
|
| 60 |
console.log(`Server running on port ${PORT}`);
|
| 61 |
+
});
|