theguywhosucks commited on
Commit
a7a3116
·
verified ·
1 Parent(s): 149db23

Upload 16 files

Browse files
Files changed (3) hide show
  1. Dockerfile +9 -4
  2. package.json +8 -5
  3. server.js +15 -2
Dockerfile CHANGED
@@ -1,11 +1,16 @@
1
- FROM node:20
2
 
 
3
  WORKDIR /app
4
 
5
- COPY . .
 
6
 
 
7
  RUN npm install
8
 
9
- EXPOSE 7860
 
10
 
11
- CMD ["node", "server.js"]
 
 
1
+ FROM node:20-alpine
2
 
3
+ # Set the working directory inside the container
4
  WORKDIR /app
5
 
6
+ # Copy package files first (better for Docker caching)
7
+ COPY package*.json ./
8
 
9
+ # Install dependencies
10
  RUN npm install
11
 
12
+ # Copy the rest of your code (server.js, etc.)
13
+ COPY . .
14
 
15
+ # Run the app
16
+ CMD ["npm", "start"]
package.json CHANGED
@@ -1,10 +1,13 @@
1
  {
2
- "name": "hf-web",
3
  "version": "1.0.0",
 
 
 
 
 
 
4
  "dependencies": {
5
- "@gradio/client": "^1.9.0",
6
- "express": "^4.18.2",
7
- "dotenv": "^16.4.5",
8
- "node-fetch": "^3.3.2"
9
  }
10
  }
 
1
  {
2
+ "name": "hf-gradio-docker-app",
3
  "version": "1.0.0",
4
+ "description": "Connecting to Gradio with HF token",
5
+ "main": "server.js",
6
+ "type": "module",
7
+ "scripts": {
8
+ "start": "node server.js"
9
+ },
10
  "dependencies": {
11
+ "@gradio/client": "^1.0.0"
 
 
 
12
  }
13
  }
server.js CHANGED
@@ -18,12 +18,22 @@ if (!HF_TOKEN) {
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) {
@@ -42,11 +52,14 @@ app.get("/api/download", async (req, res) => {
42
  const response = await fetch(url, {
43
  headers: { Authorization: `Bearer ${HF_TOKEN}` },
44
  });
 
45
  if (!response.ok) {
46
  return res.status(response.status).json({ error: "File fetch failed" });
47
  }
 
48
  res.setHeader("Content-Disposition", `attachment; filename=\"${file.split("/").pop()}\"`);
49
  res.setHeader("Content-Type", response.headers.get("content-type") || "application/octet-stream");
 
50
  response.body.pipe(res);
51
  } catch (err) {
52
  console.error("Download error:", err);
 
18
  app.use(express.json({ limit: "10mb" }));
19
 
20
  app.post("/api/proxy", async (req, res) => {
21
+ let { fn, args } = req.body;
22
+
23
  if (!fn) return res.status(400).json({ error: "Missing 'fn' in request body" });
24
 
25
+ // THE FIX: Scrub the 'args' object clean before passing it to Gradio.
26
+ // If your frontend accidentally sent 'read_token' in the payload, this deletes it.
27
+ if (args && typeof args === 'object' && !Array.isArray(args)) {
28
+ delete args.read_token;
29
+ delete args.hf_token;
30
+ }
31
+
32
  try {
33
+ // Auth is handled cleanly right here
34
  const client = await Client.connect("pockit-cloud/main", { hf_token: HF_TOKEN });
35
+
36
+ // Now 'args' only contains the actual model inputs
37
  const result = await client.predict(fn, args);
38
  res.json({ data: result.data });
39
  } catch (err) {
 
52
  const response = await fetch(url, {
53
  headers: { Authorization: `Bearer ${HF_TOKEN}` },
54
  });
55
+
56
  if (!response.ok) {
57
  return res.status(response.status).json({ error: "File fetch failed" });
58
  }
59
+
60
  res.setHeader("Content-Disposition", `attachment; filename=\"${file.split("/").pop()}\"`);
61
  res.setHeader("Content-Type", response.headers.get("content-type") || "application/octet-stream");
62
+
63
  response.body.pipe(res);
64
  } catch (err) {
65
  console.error("Download error:", err);