Khrisna commited on
Commit
e30d518
·
1 Parent(s): 87c3c2a

Update index.js

Browse files
Files changed (1) hide show
  1. index.js +15 -6
index.js CHANGED
@@ -167,10 +167,16 @@ app.post('/api/nsfw-check', async (req, res) => {
167
  responseType: "arraybuffer"
168
  })
169
  const response = await check_nsfw(data_img.data)
170
- res.json(response)
 
 
 
171
  } else if (images && typeof images == 'string' && isBase64(images)) {
172
  const response = await check_nsfw(Buffer.from(images, "base64"))
173
- res.json(response)
 
 
 
174
  } else {
175
  res.json({
176
  success: false, message: 'No url or base64 detected!!'
@@ -336,9 +342,12 @@ async function check_nsfw(buffer) {
336
  const image = await tfjs.node.decodeImage(buffer,3)
337
  const predictions = await model.classify(image)
338
  image.dispose() // Tensor memory must be managed explicitly (it is not sufficient to let a tf.Tensor go out of scope for its memory to be released).
339
- return prediction.map(v => {
340
- class_name: v.className,
341
- probability: v.probability,
342
- probability_percent: (v.probability * 100).toFixed(2)
 
 
343
  })
 
344
  }
 
167
  responseType: "arraybuffer"
168
  })
169
  const response = await check_nsfw(data_img.data)
170
+ res.json({
171
+ status: "ok",
172
+ result: response
173
+ })
174
  } else if (images && typeof images == 'string' && isBase64(images)) {
175
  const response = await check_nsfw(Buffer.from(images, "base64"))
176
+ res.json({
177
+ status: "ok",
178
+ result: response
179
+ })
180
  } else {
181
  res.json({
182
  success: false, message: 'No url or base64 detected!!'
 
342
  const image = await tfjs.node.decodeImage(buffer,3)
343
  const predictions = await model.classify(image)
344
  image.dispose() // Tensor memory must be managed explicitly (it is not sufficient to let a tf.Tensor go out of scope for its memory to be released).
345
+ cosnt results = prediction.map(v => {
346
+ return {
347
+ class_name: v.className,
348
+ probability: v.probability,
349
+ probability_percent: (v.probability * 100).toFixed(2)
350
+ }
351
  })
352
+ return results
353
  }