MrUtakata commited on
Commit
43f36c5
·
verified ·
1 Parent(s): abdbdd0

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +42 -0
app.py ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import joblib
3
+ import numpy as np
4
+ import string
5
+
6
+ # Load the pipeline and label mapping
7
+ pipeline = joblib.load("ensemble_pipeline.joblib")
8
+ label_map = joblib.load("label_map.joblib")
9
+ # Create a reverse mapping for nice output
10
+ reverse_label_map = {v: k for k, v in label_map.items()}
11
+
12
+ # App title and description
13
+ st.title("Password Strength Predictor")
14
+ st.write("""
15
+ Enter a password below to see its predicted strength (Weak, Medium, or Strong)
16
+ using a pre-trained ensemble classifier.
17
+ """)
18
+
19
+ # Text input for the password
20
+ password = st.text_input("Enter a Password:")
21
+
22
+ # Optional: Define the same numerical feature function if needed
23
+ def generate_numerical_features(pwd):
24
+ return np.array([
25
+ len(pwd),
26
+ sum(1 for char in pwd if char.islower()) / max(1, len(pwd)),
27
+ sum(1 for char in pwd if char.isupper()) / max(1, len(pwd)),
28
+ sum(1 for char in pwd if char.isdigit()) / max(1, len(pwd)),
29
+ sum(1 for char in pwd if not char.isalnum()) / max(1, len(pwd)),
30
+ int(any(char in string.punctuation for char in pwd))
31
+ ])
32
+
33
+ # Prediction action
34
+ if st.button("Predict Strength"):
35
+ if password:
36
+ # Use the pipeline to predict directly from the raw password
37
+ pred_numeric = pipeline.predict([password])
38
+ # Convert numeric output to a human-readable label using the reverse mapping
39
+ pred_label = reverse_label_map.get(pred_numeric[0], "Unknown")
40
+ st.success(f"Predicted Password Strength: **{pred_label}**")
41
+ else:
42
+ st.warning("Please enter a password to get a prediction.")