MrUtakata commited on
Commit
25d2c15
Β·
verified Β·
1 Parent(s): d80f6d5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -12
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.cache(allow_output_mutation=True)
10
  def load_preprocessor(path="preprocessor.pkl"):
11
  return joblib.load(path)
12
 
13
- @st.cache(allow_output_mutation=True)
14
  def load_label_encoder(path="label_encoder.pkl"):
15
  return joblib.load(path)
16
 
17
- @st.cache(allow_output_mutation=True)
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). "