Spaces:
Sleeping
Sleeping
ausername-12345 commited on
Commit ·
66a8b59
1
Parent(s): 10c67f5
Test direct model inference on huggingface.co
Browse files
server.js
CHANGED
|
@@ -50,26 +50,39 @@ app.post("/api/hf", async (req, res) => {
|
|
| 50 |
|
| 51 |
app.get("/api/test-lib", async (_, res) => {
|
| 52 |
const results = {};
|
|
|
|
| 53 |
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
|
|
|
|
|
|
|
|
|
| 70 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
} catch (e) {
|
| 72 |
-
results["
|
| 73 |
}
|
| 74 |
|
| 75 |
res.json(results);
|
|
|
|
| 50 |
|
| 51 |
app.get("/api/test-lib", async (_, res) => {
|
| 52 |
const results = {};
|
| 53 |
+
const token = process.env.HF_TOKEN;
|
| 54 |
|
| 55 |
+
// Try direct model inference on huggingface.co
|
| 56 |
+
const models = ["google/gemma-2-2b-it", "gpt2", "Qwen/Qwen2.5-7B-Instruct-1M"];
|
| 57 |
+
for (const model of models) {
|
| 58 |
+
try {
|
| 59 |
+
const r = await fetch(`https://huggingface.co/${model}`, {
|
| 60 |
+
method: "POST",
|
| 61 |
+
headers: {
|
| 62 |
+
"Content-Type": "application/json",
|
| 63 |
+
Authorization: `Bearer ${token}`,
|
| 64 |
+
},
|
| 65 |
+
body: JSON.stringify({
|
| 66 |
+
inputs: "What is a jar opener? Answer in one sentence.",
|
| 67 |
+
parameters: { max_new_tokens: 50 },
|
| 68 |
+
}),
|
| 69 |
+
});
|
| 70 |
+
const text = await r.text();
|
| 71 |
+
results[`model_${model}`] = { status: r.status, body: text.slice(0, 300) };
|
| 72 |
+
} catch (e) {
|
| 73 |
+
results[`model_${model}`] = { error: e.message };
|
| 74 |
}
|
| 75 |
+
}
|
| 76 |
+
|
| 77 |
+
// Also try the /api/models/{model} endpoint
|
| 78 |
+
try {
|
| 79 |
+
const r = await fetch("https://huggingface.co/api/models/google/gemma-2-2b-it", {
|
| 80 |
+
headers: { Authorization: `Bearer ${token}` },
|
| 81 |
+
});
|
| 82 |
+
const d = await r.json();
|
| 83 |
+
results["model_info"] = { pipeline_tag: d.pipeline_tag, inference: d.inference, cardData: d.cardData ? "present" : "none" };
|
| 84 |
} catch (e) {
|
| 85 |
+
results["model_info_error"] = e.message;
|
| 86 |
}
|
| 87 |
|
| 88 |
res.json(results);
|