MrUtakata commited on
Commit
f686213
·
verified ·
1 Parent(s): b2a603e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -2
app.py CHANGED
@@ -9,6 +9,24 @@ model = joblib.load("ensemble_model.pkl")
9
  with open("features_to_drop.pkl", "rb") as f:
10
  features_to_drop = pickle.load(f)
11
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
  # Column names from the raw 49-column dataset (before feature engineering)
13
  raw_columns = [
14
  'srcip', 'sport', 'dstip', 'dsport', 'proto', 'state', 'dur', 'sbytes', 'dbytes',
@@ -56,8 +74,12 @@ if st.button("Predict"):
56
  processed_df = preprocess_input(values)
57
 
58
  # Predict using the preprocessed data
59
- prediction = model.predict(processed_df)[0]
60
- st.success(f"✅ Predicted Attack Category: **{prediction}**")
 
 
 
 
61
 
62
  except Exception as e:
63
  st.error(f"❌ Error processing input: {e}")
 
9
  with open("features_to_drop.pkl", "rb") as f:
10
  features_to_drop = pickle.load(f)
11
 
12
+ # Map of numerical predictions to attack category strings
13
+ label_map = {
14
+ 0: 'Fuzzers',
15
+ 1: 'Fuzzers',
16
+ 2: 'Reconnaissance',
17
+ 3: 'Shellcode',
18
+ 4: 'Analysis',
19
+ 5: 'Backdoor',
20
+ 6: 'Backdoors',
21
+ 7: 'DoS',
22
+ 8: 'Exploits',
23
+ 9: 'Generic',
24
+ 10: 'Reconnaissance',
25
+ 11: 'Shellcode',
26
+ 12: 'Worms',
27
+ 13: 'normal'
28
+ }
29
+
30
  # Column names from the raw 49-column dataset (before feature engineering)
31
  raw_columns = [
32
  'srcip', 'sport', 'dstip', 'dsport', 'proto', 'state', 'dur', 'sbytes', 'dbytes',
 
74
  processed_df = preprocess_input(values)
75
 
76
  # Predict using the preprocessed data
77
+ predicted_label = model.predict(processed_df)[0]
78
+
79
+ # Map the prediction to string label
80
+ predicted_category = label_map.get(predicted_label, "Unknown")
81
+
82
+ st.success(f"✅ Predicted Attack Category: **{predicted_category}**")
83
 
84
  except Exception as e:
85
  st.error(f"❌ Error processing input: {e}")