Spaces:
Sleeping
Sleeping
Commit ·
3979c51
1
Parent(s): e1faf46
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,14 +1,13 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import joblib
|
| 3 |
import pandas as pd
|
| 4 |
-
from sklearn.ensemble import RandomForestClassifier
|
| 5 |
|
| 6 |
# Load the saved Random Forest model
|
| 7 |
rf_model = joblib.load('rf_model.pkl') # Make sure to use the actual path to your saved model
|
| 8 |
|
| 9 |
# Define the feature names (excluding the target column 'type')
|
| 10 |
-
|
| 11 |
-
"
|
| 12 |
]
|
| 13 |
|
| 14 |
class_labels = {
|
|
@@ -29,13 +28,13 @@ def detect_intrusion(file):
|
|
| 29 |
except Exception as e:
|
| 30 |
return f"Error reading file: {str(e)}"
|
| 31 |
|
| 32 |
-
# Check if all required feature columns are in the log file
|
| 33 |
-
missing_features = [feature for feature in
|
| 34 |
if missing_features:
|
| 35 |
return f"Missing features in file: {', '.join(missing_features)}"
|
| 36 |
|
| 37 |
-
# Extract the feature values (
|
| 38 |
-
feature_values = log_data[
|
| 39 |
|
| 40 |
# Predict the class (multi-class classification) for each row in the log file
|
| 41 |
predictions = rf_model.predict(feature_values)
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import joblib
|
| 3 |
import pandas as pd
|
|
|
|
| 4 |
|
| 5 |
# Load the saved Random Forest model
|
| 6 |
rf_model = joblib.load('rf_model.pkl') # Make sure to use the actual path to your saved model
|
| 7 |
|
| 8 |
# Define the feature names (excluding the target column 'type')
|
| 9 |
+
numeric_features = [
|
| 10 |
+
"door_state", "sphone_signal", "label" # Only numeric features
|
| 11 |
]
|
| 12 |
|
| 13 |
class_labels = {
|
|
|
|
| 28 |
except Exception as e:
|
| 29 |
return f"Error reading file: {str(e)}"
|
| 30 |
|
| 31 |
+
# Check if all required numeric feature columns are in the log file
|
| 32 |
+
missing_features = [feature for feature in numeric_features if feature not in log_data.columns]
|
| 33 |
if missing_features:
|
| 34 |
return f"Missing features in file: {', '.join(missing_features)}"
|
| 35 |
|
| 36 |
+
# Extract the numeric feature values (excluding date and time)
|
| 37 |
+
feature_values = log_data[numeric_features].astype(float).values
|
| 38 |
|
| 39 |
# Predict the class (multi-class classification) for each row in the log file
|
| 40 |
predictions = rf_model.predict(feature_values)
|