Jiahuita commited on
Commit
9a2d08e
·
1 Parent(s): 7532efb

Fix deployment issues

Browse files
README.md CHANGED
@@ -3,7 +3,6 @@ language: en
3
  license: mit
4
  tags:
5
  - text-classification
6
- - news-classification
7
  pipeline_tag: text-classification
8
  inference: true
9
  widget:
 
3
  license: mit
4
  tags:
5
  - text-classification
 
6
  pipeline_tag: text-classification
7
  inference: true
8
  widget:
__pycache__/pipeline.cpython-39.pyc CHANGED
Binary files a/__pycache__/pipeline.cpython-39.pyc and b/__pycache__/pipeline.cpython-39.pyc differ
 
pipeline.py CHANGED
@@ -7,23 +7,23 @@ import tensorflow as tf
7
  import json
8
 
9
  class NewsClassifierPipeline(Pipeline):
10
- def __init__(self, model_path="news_classifier.h5", tokenizer_path="tokenizer.json"):
11
  super().__init__()
12
- self.model = load_model(model_path)
13
- with open(tokenizer_path, "r") as f:
14
  tokenizer_data = json.load(f)
15
  self.tokenizer = tokenizer_from_json(tokenizer_data)
16
 
17
- def preprocess(self, inputs):
18
- sequences = self.tokenizer.texts_to_sequences([inputs])
19
- return pad_sequences(sequences, maxlen=128)
 
20
 
21
  def _forward(self, inputs):
22
- preprocessed = self.preprocess(inputs)
23
- predictions = self.model.predict(preprocessed)
24
  scores = tf.nn.softmax(predictions, axis=1).numpy()
25
- label = np.argmax(scores)
26
- return [{"label": "foxnews" if label == 0 else "nbc", "score": float(scores[0, label])}]
27
 
28
  def postprocess(self, model_outputs):
29
  return model_outputs
 
7
  import json
8
 
9
  class NewsClassifierPipeline(Pipeline):
10
+ def __init__(self):
11
  super().__init__()
12
+ self.model = load_model('./news_classifier.h5')
13
+ with open('./tokenizer.json', 'r') as f:
14
  tokenizer_data = json.load(f)
15
  self.tokenizer = tokenizer_from_json(tokenizer_data)
16
 
17
+ def preprocess(self, text):
18
+ sequence = self.tokenizer.texts_to_sequences([text])
19
+ padded = pad_sequences(sequence, maxlen=128)
20
+ return padded
21
 
22
  def _forward(self, inputs):
23
+ predictions = self.model.predict(inputs)
 
24
  scores = tf.nn.softmax(predictions, axis=1).numpy()
25
+ label = np.argmax(scores, axis=1)[0]
26
+ return [{"label": "foxnews" if label == 0 else "nbc", "score": float(scores[0][label])}]
27
 
28
  def postprocess(self, model_outputs):
29
  return model_outputs
requirements.txt CHANGED
@@ -1,9 +1,5 @@
1
- #tensorflow-macos>=2.10.0
2
  tensorflow>=2.10.0
3
  transformers>=4.30.0
4
  torch>=2.0.0
5
  numpy>=1.19.2
6
  scikit-learn>=0.24.2
7
- fastapi==0.68.1
8
- uvicorn==0.15.0
9
- pydantic==1.8.2
 
 
1
  tensorflow>=2.10.0
2
  transformers>=4.30.0
3
  torch>=2.0.0
4
  numpy>=1.19.2
5
  scikit-learn>=0.24.2