Khrisna commited on
Commit
211b824
·
1 Parent(s): 7f476e3

Update index.js

Browse files
Files changed (1) hide show
  1. index.js +9 -3
index.js CHANGED
@@ -213,7 +213,10 @@ app.post('/api/nsfw-check', async (req, res) => {
213
  })*/
214
 
215
  const PORT = process.env.PORT || 7860
216
- app.listen(PORT, () => console.log('App running on port', PORT))
 
 
 
217
 
218
  function formatSize(num) {
219
  return bytes(+num || 0, { unitSeparator: ' ' })
@@ -337,7 +340,7 @@ async function waifu2x(image, formats) {
337
  return images.data
338
  }
339
  async function check_nsfw(buffer) {
340
- const model = await nsfwjs.load() // To load a local model, nsfw.load('file://./path/to/model/')
341
  const convert = async (img) => {
342
  // Decoded image in UInt8 Byte array
343
  const image = await jpegjs.decode(img, { useTArray: true })
@@ -353,7 +356,7 @@ async function check_nsfw(buffer) {
353
  return tfjs.tensor3d(values, [image.height, image.width, numChannels], 'int32')
354
  }
355
  const image = await convert(buffer)
356
- const predictions = await model.classify(image)
357
  image.dispose();
358
  const results = predictions.map(v => {
359
  return {
@@ -363,4 +366,7 @@ async function check_nsfw(buffer) {
363
  }
364
  })
365
  return results
 
 
 
366
  }
 
213
  })*/
214
 
215
  const PORT = process.env.PORT || 7860
216
+ app.listen(PORT, () => {
217
+ console.log('App running on port', PORT)
218
+ load_model()
219
+ )}
220
 
221
  function formatSize(num) {
222
  return bytes(+num || 0, { unitSeparator: ' ' })
 
340
  return images.data
341
  }
342
  async function check_nsfw(buffer) {
343
+ let _model
344
  const convert = async (img) => {
345
  // Decoded image in UInt8 Byte array
346
  const image = await jpegjs.decode(img, { useTArray: true })
 
356
  return tfjs.tensor3d(values, [image.height, image.width, numChannels], 'int32')
357
  }
358
  const image = await convert(buffer)
359
+ const predictions = await _model.classify(image)
360
  image.dispose();
361
  const results = predictions.map(v => {
362
  return {
 
366
  }
367
  })
368
  return results
369
+ }
370
+ async function load_model() {
371
+ _model = await nsfwjs.load()
372
  }