Spaces:
Sleeping
Sleeping
| import streamlit as st | |
| from joblib import load | |
| import numpy as np | |
| # App Title | |
| st.title("Malware Detection") | |
| # Load Model and Encoder | |
| model = load('dbscan_model.joblib') | |
| encoder = load("LabelEncoder.joblib") | |
| # Input Fields | |
| anomaly_score = st.number_input("Anomaly Score", min_value=0, max_value=100, step=1, help="Score indicating the level of anomaly (0-100).") | |
| anomaly_score = anomaly_score / 100 # Normalize | |
| suspicious_ip_count = st.number_input("Suspicious IP Count", min_value=0, max_value=9, help="Number of suspicious IPs detected.") | |
| malicious_payload_indicator = st.selectbox("Malicious Payload Indicator", options=["Yes", "No"]) | |
| malicious_payload_indicator = 1 if malicious_payload_indicator == "Yes" else 0 | |
| reputation_score = st.number_input("Reputation Score", min_value=0, max_value=100, help="Reputation score of the source (0-100).") | |
| behavioral_score = st.number_input("Behavioral Score", min_value=0, max_value=100, help="Behavioral score based on activity patterns (0-100).") | |
| attack_type = st.selectbox("Attack Type", options=encoder["attack_type"].classes_, help="Type of attack detected.") | |
| attack_type = encoder["attack_type"].transform([attack_type])[0] | |
| signature_match = st.selectbox("Signature Match", options=["Yes", "No"], help="Does the payload match any known signatures?") | |
| signature_match = 1 if signature_match == "Yes" else 0 | |
| sandbox_result = st.selectbox("Sandbox Result", options=encoder["sandbox_result"].classes_, help="Result from sandbox testing.") | |
| sandbox_result = encoder["sandbox_result"].transform([sandbox_result])[0] | |
| heuristic_score = st.number_input("Heuristic Score", min_value=0, max_value=100, help="Score based on heuristic analysis (0-100).") | |
| traffic_pattern = st.selectbox("Traffic Pattern", options=encoder["traffic_pattern"].classes_, help="Detected traffic pattern.") | |
| traffic_pattern = encoder["traffic_pattern"].transform([traffic_pattern])[0] | |
| # Combine Features | |
| values = [ | |
| anomaly_score, suspicious_ip_count, malicious_payload_indicator, | |
| reputation_score, behavioral_score, attack_type, signature_match, | |
| sandbox_result, heuristic_score, traffic_pattern | |
| ] | |
| # Prediction | |
| if st.button("Detect Malware"): | |
| try: | |
| label = model.fit_predict([values])[0] | |
| if label == -1: | |
| st.success("Malware Detected") | |
| else: | |
| st.success("No Malware Detected") | |
| except Exception as e: | |
| st.error(f"Error: {e}") |