DSatishchandra commited on
Commit
bba5199
1 Parent(s): 5fc1666

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -3
app.py CHANGED
@@ -7,7 +7,6 @@ from transformers import pipeline, AutoTokenizer, AutoModelForSequenceClassifica
7
  from sklearn.ensemble import RandomForestClassifier
8
  import joblib
9
  import os
10
- import json
11
 
12
  # Load Hugging Face model for anomaly detection
13
  tokenizer = AutoTokenizer.from_pretrained("huggingface-course/distilbert-base-uncased-finetuned-imdb")
@@ -36,13 +35,18 @@ def preprocess_logs(logs):
36
  logs['log_message'] = logs['log_message'].str.lower()
37
  return logs
38
 
39
- # Detect anomalies in logs
40
  def detect_anomaly(logs):
41
  preprocessed_logs = preprocess_logs(logs)
 
 
 
 
42
  results = []
43
  for log in preprocessed_logs['log_message']:
44
  anomaly_result = anomaly_detection(log)
45
- results.append(anomaly_result[0]['label'])
 
46
  return results
47
 
48
  # Predict failures based on device metrics
 
7
  from sklearn.ensemble import RandomForestClassifier
8
  import joblib
9
  import os
 
10
 
11
  # Load Hugging Face model for anomaly detection
12
  tokenizer = AutoTokenizer.from_pretrained("huggingface-course/distilbert-base-uncased-finetuned-imdb")
 
35
  logs['log_message'] = logs['log_message'].str.lower()
36
  return logs
37
 
38
+ # Detect anomalies in logs with label mapping
39
  def detect_anomaly(logs):
40
  preprocessed_logs = preprocess_logs(logs)
41
+ label_map = { # Map Hugging Face output labels to meaningful labels
42
+ "LABEL_0": "Normal",
43
+ "LABEL_1": "Anomaly"
44
+ }
45
  results = []
46
  for log in preprocessed_logs['log_message']:
47
  anomaly_result = anomaly_detection(log)
48
+ label = anomaly_result[0]['label']
49
+ results.append(label_map.get(label, label)) # Map the label or return the original label
50
  return results
51
 
52
  # Predict failures based on device metrics