freealise commited on
Commit
d854861
·
verified ·
1 Parent(s): 31d6614

Update index.js

Browse files
Files changed (1) hide show
  1. index.js +6 -6
index.js CHANGED
@@ -1,5 +1,3 @@
1
- import { pipeline, env } from '@huggingface/transformers';
2
-
3
  class MyClassificationPipeline {
4
  static task = 'text-classification';
5
  static model = 'Xenova/distilbert-base-uncased-finetuned-sst-2-english';
@@ -8,6 +6,8 @@ class MyClassificationPipeline {
8
  static async getInstance(progress_callback = null) {
9
  if (this.instance === null) {
10
 
 
 
11
  // NOTE: Uncomment this to change the cache directory
12
  env.cacheDir = './.cache';
13
 
@@ -17,11 +17,11 @@ class MyClassificationPipeline {
17
  return this.instance;
18
  }
19
  }
20
- MyClassificationPipeline.getInstance();
21
 
22
 
23
- import http from 'http';
24
- import url from 'url';
25
 
26
  http.createServer(async (req, res) => {
27
  res.writeHead(200, {'Content-Type': 'text/html'});
@@ -29,7 +29,7 @@ http.createServer(async (req, res) => {
29
 
30
  if (u.query.q) {
31
  const classifier = await MyClassificationPipeline.getInstance();
32
- response = await classifier(u.query.q);
33
  res.end(JSON.stringify(response));
34
  } else {
35
  res.end("Empty query string");
 
 
 
1
  class MyClassificationPipeline {
2
  static task = 'text-classification';
3
  static model = 'Xenova/distilbert-base-uncased-finetuned-sst-2-english';
 
6
  static async getInstance(progress_callback = null) {
7
  if (this.instance === null) {
8
 
9
+ let { pipeline, env } = await import('@huggingface/transformers');
10
+
11
  // NOTE: Uncomment this to change the cache directory
12
  env.cacheDir = './.cache';
13
 
 
17
  return this.instance;
18
  }
19
  }
20
+ //MyClassificationPipeline.getInstance();
21
 
22
 
23
+ const http = require('http');
24
+ const url = require('url');
25
 
26
  http.createServer(async (req, res) => {
27
  res.writeHead(200, {'Content-Type': 'text/html'});
 
29
 
30
  if (u.query.q) {
31
  const classifier = await MyClassificationPipeline.getInstance();
32
+ const response = await classifier(u.query.q);
33
  res.end(JSON.stringify(response));
34
  } else {
35
  res.end("Empty query string");