Spaces:
Sleeping
Sleeping
Commit
·
022be5b
1
Parent(s):
46396b6
Update app.py
Browse files
app.py
CHANGED
|
@@ -38,17 +38,16 @@ class_labels = {
|
|
| 38 |
9: "mitm"
|
| 39 |
}
|
| 40 |
|
| 41 |
-
def detect_intrusion(
|
| 42 |
-
#
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
return f"Missing feature: {feature_name}"
|
| 52 |
|
| 53 |
# Choose the model based on user selection
|
| 54 |
if model_choice == "Random Forest":
|
|
@@ -72,18 +71,20 @@ def detect_intrusion(feature_string, model_choice="Random Forest"):
|
|
| 72 |
else:
|
| 73 |
return f"Intrusion Detected: {class_labels.get(predicted_class, 'Unknown Attack')}"
|
| 74 |
|
| 75 |
-
# Create
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
|
|
|
|
|
|
| 87 |
|
| 88 |
# Launch the interface locally for testing
|
| 89 |
iface.launch()
|
|
|
|
| 38 |
9: "mitm"
|
| 39 |
}
|
| 40 |
|
| 41 |
+
def detect_intrusion(feature_values, model_choice="Random Forest"):
|
| 42 |
+
# Ensure the length of feature_values matches feature_names
|
| 43 |
+
if len(feature_values) != len(feature_names):
|
| 44 |
+
return "Please fill in all the required feature values."
|
| 45 |
+
|
| 46 |
+
# Convert the input values to floats and match them with feature names
|
| 47 |
+
try:
|
| 48 |
+
feature_values = [float(value) for value in feature_values]
|
| 49 |
+
except ValueError:
|
| 50 |
+
return "Please enter valid numerical values for all fields."
|
|
|
|
| 51 |
|
| 52 |
# Choose the model based on user selection
|
| 53 |
if model_choice == "Random Forest":
|
|
|
|
| 71 |
else:
|
| 72 |
return f"Intrusion Detected: {class_labels.get(predicted_class, 'Unknown Attack')}"
|
| 73 |
|
| 74 |
+
# Create Gradio input fields for each feature
|
| 75 |
+
inputs = [gr.Textbox(label=feature_name) for feature_name in feature_names[:-1]] # Exclude "label" field from inputs
|
| 76 |
+
|
| 77 |
+
# Add model choice dropdown
|
| 78 |
+
inputs.append(gr.Dropdown(choices=["Random Forest", "Decision Tree", "Bagging Classifier", "AdaBoost Classifier"], label="Select Model"))
|
| 79 |
+
|
| 80 |
+
# Create the Gradio interface
|
| 81 |
+
iface = gr.Interface(
|
| 82 |
+
fn=detect_intrusion,
|
| 83 |
+
inputs=inputs,
|
| 84 |
+
outputs="text",
|
| 85 |
+
title="Intrusion Detection System",
|
| 86 |
+
description="Fill in the blank fields for the network traffic features, and choose the model to detect intrusions."
|
| 87 |
+
)
|
| 88 |
|
| 89 |
# Launch the interface locally for testing
|
| 90 |
iface.launch()
|