Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -9,7 +9,6 @@ import joblib
|
|
9 |
import os
|
10 |
|
11 |
# Step 1: Load Hugging Face model for anomaly detection
|
12 |
-
# Using the "huggingface-course/distilbert-base-uncased-finetuned-imdb" model
|
13 |
tokenizer = AutoTokenizer.from_pretrained("huggingface-course/distilbert-base-uncased-finetuned-imdb")
|
14 |
model = AutoModelForSequenceClassification.from_pretrained("huggingface-course/distilbert-base-uncased-finetuned-imdb")
|
15 |
anomaly_detection = pipeline("text-classification", model=model, tokenizer=tokenizer)
|
@@ -55,6 +54,12 @@ def detect_anomaly(logs):
|
|
55 |
|
56 |
# Step 5: Function to predict failures based on device metrics
|
57 |
def predict_failure(device_metrics):
|
|
|
|
|
|
|
|
|
|
|
|
|
58 |
# Convert device metrics into a numpy array for prediction
|
59 |
metrics_array = np.array([device_metrics['cpu_usage'], device_metrics['memory_usage'], device_metrics['error_rate']]).reshape(1, -1)
|
60 |
failure_prediction = failure_prediction_model.predict(metrics_array) # Use the Random Forest model for failure prediction
|
|
|
9 |
import os
|
10 |
|
11 |
# Step 1: Load Hugging Face model for anomaly detection
|
|
|
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 |
anomaly_detection = pipeline("text-classification", model=model, tokenizer=tokenizer)
|
|
|
54 |
|
55 |
# Step 5: Function to predict failures based on device metrics
|
56 |
def predict_failure(device_metrics):
|
57 |
+
# Check if metrics are None or missing required fields
|
58 |
+
if device_metrics is None:
|
59 |
+
return "Device metrics are missing."
|
60 |
+
if 'cpu_usage' not in device_metrics or 'memory_usage' not in device_metrics or 'error_rate' not in device_metrics:
|
61 |
+
return "Invalid metrics format. Please provide 'cpu_usage', 'memory_usage', and 'error_rate'."
|
62 |
+
|
63 |
# Convert device metrics into a numpy array for prediction
|
64 |
metrics_array = np.array([device_metrics['cpu_usage'], device_metrics['memory_usage'], device_metrics['error_rate']]).reshape(1, -1)
|
65 |
failure_prediction = failure_prediction_model.predict(metrics_array) # Use the Random Forest model for failure prediction
|