Update app.py
Browse files
app.py
CHANGED
|
@@ -1,31 +1,30 @@
|
|
| 1 |
-
# streamlit_app.py
|
|
|
|
| 2 |
import streamlit as st
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
import pandas as pd
|
| 4 |
import numpy as np
|
| 5 |
import joblib
|
| 6 |
import tensorflow as tf
|
| 7 |
|
| 8 |
-
# βββ Caching loaders so they only run once
|
| 9 |
-
@st.
|
| 10 |
def load_preprocessor(path="preprocessor.pkl"):
|
| 11 |
return joblib.load(path)
|
| 12 |
|
| 13 |
-
@st.
|
| 14 |
def load_label_encoder(path="label_encoder.pkl"):
|
| 15 |
return joblib.load(path)
|
| 16 |
|
| 17 |
-
@st.
|
| 18 |
def load_model(path="keystroke_dnn.h5"):
|
| 19 |
return tf.keras.models.load_model(path)
|
| 20 |
|
| 21 |
# βββ Prediction function ββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 22 |
def predict_subjects(df_raw):
|
| 23 |
-
"""
|
| 24 |
-
Takes a DataFrame of raw keystroke features, drops any
|
| 25 |
-
'subject'/'sessionIndex'/'rep' columns, re-orders to the
|
| 26 |
-
exact list the preprocessor saw at train-time, scales,
|
| 27 |
-
runs the DNN, and returns predicted IDs + probabilities.
|
| 28 |
-
"""
|
| 29 |
preprocessor = load_preprocessor()
|
| 30 |
label_encoder = load_label_encoder()
|
| 31 |
model = load_model()
|
|
@@ -58,7 +57,6 @@ def predict_subjects(df_raw):
|
|
| 58 |
|
| 59 |
# βββ Streamlit UI ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 60 |
def main():
|
| 61 |
-
st.set_page_config(page_title="Keystroke Dynamics Auth", layout="wide")
|
| 62 |
st.title("π Keystroke Dynamics Authentication")
|
| 63 |
st.markdown(
|
| 64 |
"Upload a CSV of raw keystrokeβfeature vectors (one row per sample). "
|
|
|
|
| 1 |
+
# βββ streamlit_app.py ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 2 |
+
|
| 3 |
import streamlit as st
|
| 4 |
+
|
| 5 |
+
# βββ THIS MUST BE FIRST βββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 6 |
+
st.set_page_config(page_title="Keystroke Dynamics Auth", layout="wide")
|
| 7 |
+
|
| 8 |
import pandas as pd
|
| 9 |
import numpy as np
|
| 10 |
import joblib
|
| 11 |
import tensorflow as tf
|
| 12 |
|
| 13 |
+
# βββ Caching loaders so they only run only once per session ββββββββββββββββββ
|
| 14 |
+
@st.cache_resource
|
| 15 |
def load_preprocessor(path="preprocessor.pkl"):
|
| 16 |
return joblib.load(path)
|
| 17 |
|
| 18 |
+
@st.cache_resource
|
| 19 |
def load_label_encoder(path="label_encoder.pkl"):
|
| 20 |
return joblib.load(path)
|
| 21 |
|
| 22 |
+
@st.cache_resource
|
| 23 |
def load_model(path="keystroke_dnn.h5"):
|
| 24 |
return tf.keras.models.load_model(path)
|
| 25 |
|
| 26 |
# βββ Prediction function ββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 27 |
def predict_subjects(df_raw):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
preprocessor = load_preprocessor()
|
| 29 |
label_encoder = load_label_encoder()
|
| 30 |
model = load_model()
|
|
|
|
| 57 |
|
| 58 |
# βββ Streamlit UI ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 59 |
def main():
|
|
|
|
| 60 |
st.title("π Keystroke Dynamics Authentication")
|
| 61 |
st.markdown(
|
| 62 |
"Upload a CSV of raw keystrokeβfeature vectors (one row per sample). "
|