File size: 1,994 Bytes
fb5abe4
 
 
 
 
 
 
 
 
71ea7dd
 
fb5abe4
71ea7dd
fb5abe4
 
 
 
 
 
 
 
 
 
 
 
 
 
71ea7dd
fb5abe4
 
 
 
a1eb974
fb5abe4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# app.py

import gradio as gr
import pandas as pd
import numpy as np
from transformers import pipeline
from sklearn.ensemble import RandomForestClassifier
import joblib

# Load fine-tuned Hugging Face model for anomaly detection
anomaly_detection = pipeline("text-classification", model="./fine_tuned_anomaly_model")

# Load the Random Forest model for failure prediction
failure_prediction_model = joblib.load('failure_prediction_model.pkl')

# Function to preprocess logs for anomaly detection
def preprocess_logs(logs):
    logs['timestamp'] = pd.to_datetime(logs['timestamp'])
    logs['log_message'] = logs['log_message'].str.lower()
    return logs

# Function to detect anomalies
def detect_anomaly(logs):
    preprocessed_logs = preprocess_logs(logs)
    results = []
    for log in preprocessed_logs['log_message']:
        anomaly_result = anomaly_detection(log)
        results.append(anomaly_result[0]['label'])
    return results

# Function to predict failures based on historical data and metrics
def predict_failure(device_metrics):
    metrics_array = np.array([device_metrics['cpu_usage'], device_metrics['memory_usage'], device_metrics['error_rate']]).reshape(1, -1)
    failure_prediction = failure_prediction_model.predict(metrics_array)
    return failure_prediction

# Gradio interface to upload log files and check anomaly detection and failure prediction
def process_logs_and_predict(log_file, metrics):
    logs = pd.read_json(log_file)
    anomalies = detect_anomaly(logs)
    failure_pred = predict_failure(metrics)
    
    return f"Anomalies Detected: {anomalies}, Failure Prediction: {failure_pred}"

# Set up Gradio interface for the dashboard
iface = gr.Interface(fn=process_logs_and_predict, 
                     inputs=["file", "json"], 
                     outputs="text", 
                     title="Cisco Device Monitoring",
                     description="Upload log files to detect anomalies and predict potential device failures.")

iface.launch()