SilverDragon9 commited on
Commit
68ebb5b
·
1 Parent(s): 140eb40

initial commit

Browse files
Files changed (3) hide show
  1. .gitignore +7 -0
  2. Sniffer_AI.py +64 -0
  3. requirements.txt +29 -0
.gitignore ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ flagged/
2
+ *.pt
3
+ *.png
4
+ *.jpg
5
+ *.mkv
6
+ *.mp4
7
+ gradio_cached examples/
Sniffer_AI.py ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import joblib
3
+ import requests
4
+ import os
5
+
6
+ from sklearn.ensemble import RandomForestClassifier, BaggingClassifier, AdaBoostClassifier
7
+ from sklearn.tree import DecisionTreeClassifier
8
+
9
+
10
+ # Load the saved models
11
+ rf_model = joblib.load('rf_model.pkl')
12
+ dt_model = joblib.load('dt_model.pkl')
13
+ bagging_model = joblib.load('bagging_model.pkl')
14
+ ada_model = joblib.load('ada_model.pkl')
15
+
16
+ class_labels = {
17
+ 0: "normal",
18
+ 1: "backdoor",
19
+ 2: "ddos",
20
+ 3: "dos",
21
+ 4: "injection",
22
+ 5: "password",
23
+ 6: "ransomware",
24
+ 7: "scanning",
25
+ 8: "xss",
26
+ 9: "mitm"
27
+ }
28
+
29
+ def detect_intrusion(features, model_choice="Random Forest"):
30
+ # Convert the input string (comma-separated values) into a list of floats
31
+ features = [list(map(float, features.split(",")))]
32
+
33
+ # Choose the model based on user selection
34
+ if model_choice == "Random Forest":
35
+ model = rf_model
36
+ elif model_choice == "Decision Tree":
37
+ model = dt_model
38
+ elif model_choice == "Bagging Classifier":
39
+ model = bagging_model
40
+ elif model_choice == "AdaBoost Classifier":
41
+ model = ada_model
42
+ else:
43
+ return "Invalid model choice!"
44
+
45
+ # Predict the class (multi-class classification)
46
+ prediction = model.predict(features)
47
+ predicted_class = prediction[0] # Get the predicted class (an integer between 0-8)
48
+
49
+ # Return the human-readable class description
50
+ if predicted_class == 0:
51
+ return "No Intrusion Detected"
52
+ else:
53
+ return f"Intrusion Detected: {class_labels.get(predicted_class, 'Unknown Attack')}"
54
+
55
+ # Create a Gradio interface
56
+ iface = gr.Interface(fn=detect_intrusion,
57
+ inputs=[gr.Textbox(label="Input Features (comma-separated)"),
58
+ gr.Dropdown(choices=["Random Forest", "Decision Tree", "Bagging Classifier", "AdaBoost Classifier"], label="Select Model")],
59
+ outputs="text",
60
+ title="Intrusion Detection System",
61
+ description="Enter features in the format: feature1, feature2, feature3...")
62
+
63
+ # Launch the interface locally for testing
64
+ iface.launch()
requirements.txt ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Core Libraries for Machine Learning
2
+ scikit-learn==1.2.0 # Essential library for machine learning models (Random Forest, Decision Trees, etc.)
3
+ numpy==1.23.0 # Numerical operations (required for model input/output processing)
4
+ pandas==1.5.2 # Data manipulation and preprocessing
5
+
6
+ # Plotting and Visualization Tools
7
+ matplotlib==3.7.0 # Visualization library (used for plotting confusion matrices)
8
+ seaborn==0.12.1 # Advanced data visualization, helpful for heatmaps (confusion matrix)
9
+
10
+ # Saving and Loading Models
11
+ joblib==1.2.0 # For saving and loading machine learning models (used for Random Forest, Decision Trees, etc.)
12
+
13
+ # Reporting and Metrics
14
+ scikit-learn==1.2.0 # For generating classification reports, confusion matrices, and model evaluation metrics
15
+
16
+ # Hugging Face Hub Integration
17
+ huggingface_hub==0.16.0 # Integration with Hugging Face Hub (for model uploading, downloading, sharing)
18
+ transformers==4.26.1 # Hugging Face Transformers library (for model usage on the Hub)
19
+
20
+ # Optional - Jupyter Notebooks for Model Development and Experimentation
21
+ notebook==7.0.0 # For running Jupyter Notebooks in your project
22
+
23
+ # Optional - TensorBoard for Visualizing Training Process (if applicable to larger models)
24
+ tensorboard==2.10.1 # For tracking and visualizing model training
25
+
26
+ # Extras for performance and speedups
27
+ xgboost==1.6.2 # Gradient boosting library (optional, if you want to use advanced tree-based models)
28
+ lightgbm==3.3.5 # LightGBM for fast gradient boosting (optional, for high performance)
29
+