Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -6,19 +6,18 @@ import numpy as np
|
|
6 |
from transformers import pipeline
|
7 |
from sklearn.ensemble import RandomForestClassifier
|
8 |
import joblib
|
|
|
9 |
|
10 |
# Load pre-trained models for Anomaly Detection and Failure Prediction
|
11 |
-
#
|
12 |
-
|
13 |
-
|
14 |
-
anomaly_detection = pipeline("text-classification", model="your-huggingface-model-path")
|
15 |
|
16 |
# Load the Random Forest model for failure prediction (pre-trained model)
|
17 |
failure_prediction_model = joblib.load('failure_prediction_model.pkl')
|
18 |
|
19 |
# Function to preprocess logs for anomaly detection
|
20 |
def preprocess_logs(logs):
|
21 |
-
# Assume logs come in as JSON and require some basic parsing and cleaning
|
22 |
logs['timestamp'] = pd.to_datetime(logs['timestamp'])
|
23 |
logs['log_message'] = logs['log_message'].str.lower()
|
24 |
return logs
|
@@ -34,8 +33,7 @@ def detect_anomaly(logs):
|
|
34 |
|
35 |
# Function to predict failures based on historical data and metrics
|
36 |
def predict_failure(device_metrics):
|
37 |
-
|
38 |
-
metrics_array = np.array([device_metrics['cpu_usage'], device_metrics['memory_usage'], device_metrics['error_rate']]).reshape(1, -3)
|
39 |
failure_prediction = failure_prediction_model.predict(metrics_array)
|
40 |
return failure_prediction
|
41 |
|
|
|
6 |
from transformers import pipeline
|
7 |
from sklearn.ensemble import RandomForestClassifier
|
8 |
import joblib
|
9 |
+
import torch # Import PyTorch for using the Hugging Face model
|
10 |
|
11 |
# Load pre-trained models for Anomaly Detection and Failure Prediction
|
12 |
+
# Using a public Hugging Face model as an example for anomaly detection
|
13 |
+
# Replace 'distilbert-base-uncased' with your model path
|
14 |
+
anomaly_detection = pipeline("text-classification", model="distilbert-base-uncased")
|
|
|
15 |
|
16 |
# Load the Random Forest model for failure prediction (pre-trained model)
|
17 |
failure_prediction_model = joblib.load('failure_prediction_model.pkl')
|
18 |
|
19 |
# Function to preprocess logs for anomaly detection
|
20 |
def preprocess_logs(logs):
|
|
|
21 |
logs['timestamp'] = pd.to_datetime(logs['timestamp'])
|
22 |
logs['log_message'] = logs['log_message'].str.lower()
|
23 |
return logs
|
|
|
33 |
|
34 |
# Function to predict failures based on historical data and metrics
|
35 |
def predict_failure(device_metrics):
|
36 |
+
metrics_array = np.array([device_metrics['cpu_usage'], device_metrics['memory_usage'], device_metrics['error_rate']]).reshape(1, -1)
|
|
|
37 |
failure_prediction = failure_prediction_model.predict(metrics_array)
|
38 |
return failure_prediction
|
39 |
|