Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -8,36 +8,45 @@ def predict(duration, src_bytes, dst_bytes, failed_logins,
|
|
| 8 |
count, error_rate, same_srv_rate, diff_srv_rate,
|
| 9 |
host_count, login_attempts):
|
| 10 |
|
| 11 |
-
# Convert input into array
|
| 12 |
data = np.array([
|
| 13 |
duration, src_bytes, dst_bytes, failed_logins,
|
| 14 |
count, error_rate, same_srv_rate, diff_srv_rate,
|
| 15 |
host_count, login_attempts
|
| 16 |
])
|
| 17 |
|
| 18 |
-
# Simple logic (for demo)
|
| 19 |
score = np.sum(data)
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
"- Multiple login attempts\n"
|
| 31 |
-
"- Unusual connection patterns\n\n"
|
| 32 |
-
"π Recommended Action: Monitor or block this activity."
|
| 33 |
-
)
|
| 34 |
else:
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
|
| 42 |
|
| 43 |
# =========================
|
|
|
|
| 8 |
count, error_rate, same_srv_rate, diff_srv_rate,
|
| 9 |
host_count, login_attempts):
|
| 10 |
|
|
|
|
| 11 |
data = np.array([
|
| 12 |
duration, src_bytes, dst_bytes, failed_logins,
|
| 13 |
count, error_rate, same_srv_rate, diff_srv_rate,
|
| 14 |
host_count, login_attempts
|
| 15 |
])
|
| 16 |
|
|
|
|
| 17 |
score = np.sum(data)
|
| 18 |
+
|
| 19 |
+
# Define ranges
|
| 20 |
+
if score < 30:
|
| 21 |
+
status = "β
Normal Traffic"
|
| 22 |
+
explanation = "Low activity and safe behavior detected."
|
| 23 |
+
risk_level = "Low"
|
| 24 |
+
elif score < 60:
|
| 25 |
+
status = "β οΈ Suspicious Activity"
|
| 26 |
+
explanation = "Moderate anomaly detected. Could indicate unusual behavior."
|
| 27 |
+
risk_level = "Medium"
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
else:
|
| 29 |
+
status = "π¨ Attack Detected!"
|
| 30 |
+
explanation = "High anomaly detected. Strong indication of malicious activity."
|
| 31 |
+
risk_level = "High"
|
| 32 |
+
|
| 33 |
+
return f"""
|
| 34 |
+
{status}
|
| 35 |
+
|
| 36 |
+
### π’ Risk Score: {score:.2f}
|
| 37 |
+
The risk score represents the overall intensity of network activity based on input features.
|
| 38 |
+
|
| 39 |
+
### π Interpretation:
|
| 40 |
+
- **0 β 30 β Normal Traffic (Low Risk)**
|
| 41 |
+
- **30 β 60 β Suspicious Activity (Medium Risk)**
|
| 42 |
+
- **60+ β Attack (High Risk)**
|
| 43 |
+
|
| 44 |
+
### π§ Analysis:
|
| 45 |
+
{explanation}
|
| 46 |
+
|
| 47 |
+
### π‘οΈ Recommendation:
|
| 48 |
+
{"No action needed." if score < 30 else "Monitor the system." if score < 60 else "Immediate action required! Block or investigate."}
|
| 49 |
+
"""
|
| 50 |
|
| 51 |
|
| 52 |
# =========================
|