Spaces:
Running
Running
Update app.py
Browse files
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 |
-
#
|
11 |
-
|
|
|
|
|
12 |
|
13 |
-
#
|
|
|
|
|
|
|
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
|