DSatishchandra commited on
Commit
7fa8ebf
·
verified ·
1 Parent(s): 71ea7dd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -5
app.py CHANGED
@@ -3,14 +3,19 @@
3
  import gradio as gr
4
  import pandas as pd
5
  import numpy as np
6
- from transformers import pipeline
7
  from sklearn.ensemble import RandomForestClassifier
8
  import joblib
9
 
10
- # Load fine-tuned Hugging Face model for anomaly detection
11
- anomaly_detection = pipeline("text-classification", model="./fine_tuned_anomaly_model")
 
 
12
 
13
- # Load the Random Forest model for failure prediction
 
 
 
14
  failure_prediction_model = joblib.load('failure_prediction_model.pkl')
15
 
16
  # Function to preprocess logs for anomaly detection
@@ -25,7 +30,7 @@ def detect_anomaly(logs):
25
  results = []
26
  for log in preprocessed_logs['log_message']:
27
  anomaly_result = anomaly_detection(log)
28
- results.append(anomaly_result[0]['label'])
29
  return results
30
 
31
  # Function to predict failures based on historical data and metrics
 
3
  import gradio as gr
4
  import pandas as pd
5
  import numpy as np
6
+ from transformers import pipeline, AutoTokenizer, AutoModelForSequenceClassification
7
  from sklearn.ensemble import RandomForestClassifier
8
  import joblib
9
 
10
+ # Using the Hugging Face model "huggingface-course/distilbert-base-uncased-finetuned-imdb"
11
+ # Load the tokenizer and model separately
12
+ tokenizer = AutoTokenizer.from_pretrained("huggingface-course/distilbert-base-uncased-finetuned-imdb")
13
+ model = AutoModelForSequenceClassification.from_pretrained("huggingface-course/distilbert-base-uncased-finetuned-imdb")
14
 
15
+ # Define pipeline for anomaly detection using the loaded model and tokenizer
16
+ anomaly_detection = pipeline("text-classification", model=model, tokenizer=tokenizer)
17
+
18
+ # Load the Random Forest model for failure prediction (this should be trained and saved as failure_prediction_model.pkl)
19
  failure_prediction_model = joblib.load('failure_prediction_model.pkl')
20
 
21
  # Function to preprocess logs for anomaly detection
 
30
  results = []
31
  for log in preprocessed_logs['log_message']:
32
  anomaly_result = anomaly_detection(log)
33
+ results.append(anomaly_result[0]['label']) # Assuming the Hugging Face model outputs label as result
34
  return results
35
 
36
  # Function to predict failures based on historical data and metrics