-
Notifications
You must be signed in to change notification settings - Fork 2
/
malware_app.py
44 lines (34 loc) · 1.32 KB
/
malware_app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import streamlit as st
import numpy as np
from tensorflow.keras.models import load_model
# Load the trained model
@st.cache_resource
def load_trained_model():
model = load_model("phi3_model.h5")
return model
# Function to preprocess the input
def preprocess_input(timestamp, severity):
severity_mapping = {"Low": 0, "Medium": 1, "High": 2}
severity_encoded = severity_mapping.get(severity, 0)
# Prepare the input data as a numpy array
input_data = np.array([[timestamp, severity_encoded]])
return input_data
# Main function to run the Streamlit app
def main():
st.title("Malware Event Prediction")
# Input fields
timestamp = st.slider("Timestamp (Hour)", min_value=0, max_value=23, value=12)
severity = st.selectbox("Severity", ["Low", "Medium", "High"])
# Predict button
if st.button("Predict"):
# Load the model
model = load_trained_model()
# Preprocess the input
input_data = preprocess_input(timestamp, severity
# Make prediction
prediction = model.predict(input_data)[0][0]
prediction_label = "Unusual" if prediction > 0.5 else "Normal"
# Display the result
st.write(f"Prediction: {prediction_label}")
if __name__ == "__main__":
main()