Infinitode Pty Ltd commited on
Commit
b784405
·
verified ·
1 Parent(s): fee25ce

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -25
app.py CHANGED
@@ -3,41 +3,52 @@ import joblib
3
  from sklearn.feature_extraction.text import TfidfVectorizer
4
  from sklearn.calibration import CalibratedClassifierCV
5
 
6
- # Attempt to load the model and vectorizer
7
  try:
8
  model = joblib.load("helix-psa.pkl")
9
- print("Model loaded successfully:", type(model))
10
- except Exception as e:
11
- print("Error loading model:", e)
12
-
13
- try:
14
  vectorizer = joblib.load("helix-psa-vectorizer.pkl")
15
- print("Vectorizer loaded successfully:", type(vectorizer))
16
  except Exception as e:
17
- print("Error loading vectorizer:", e)
 
18
 
19
  def predictPasswordStrength(password_input):
20
- password_tfidf = vectorizer.transform([password_input])
21
-
22
- # Make predictions
23
- predicted_proba = model.predict_proba(password_tfidf)
24
- predicted_class = int(model.predict(password_tfidf)[0]) # Convert to Python integer
25
- output = ''
26
- if predicted_class == 0:
27
- output = "The password is very weak..."
28
- elif predicted_class == 1:
29
- output = "The password is average."
30
- else:
31
- output = "The password is strong. But alas, it is not unbreakable."
32
-
33
- confidence = float(predicted_proba.max())
34
-
35
- return password_input, output, confidence
 
 
 
 
 
 
 
 
36
 
37
  demo = gr.Interface(
38
  fn=predictPasswordStrength,
39
  inputs=[gr.Textbox('Hello123', label='Password', info='The password to check the strength of', max_lines=1)],
40
- outputs=[gr.Dataframe(row_count = (2, "dynamic"), col_count=(3, "fixed"), label="Generated Names", headers=["Password", "Prediction", "Confidence"])],
 
 
 
 
 
 
 
41
  title='Helix - Password Strength Analyzer',
42
  description='A password strength analyzer, trained on over 10 million different passwords.'
43
  )
 
3
  from sklearn.feature_extraction.text import TfidfVectorizer
4
  from sklearn.calibration import CalibratedClassifierCV
5
 
6
+ # Load model and vectorizer
7
  try:
8
  model = joblib.load("helix-psa.pkl")
 
 
 
 
 
9
  vectorizer = joblib.load("helix-psa-vectorizer.pkl")
10
+ print("Model and vectorizer loaded successfully.")
11
  except Exception as e:
12
+ print("Error loading model or vectorizer:", e)
13
+ model, vectorizer = None, None # Assign None so we can check later
14
 
15
  def predictPasswordStrength(password_input):
16
+ if model is None or vectorizer is None:
17
+ return [["Error: Model or vectorizer not loaded correctly.", "", ""]]
18
+
19
+ try:
20
+ password_tfidf = vectorizer.transform([password_input])
21
+
22
+ # Make predictions
23
+ predicted_proba = model.predict_proba(password_tfidf)
24
+ predicted_class = int(model.predict(password_tfidf)[0]) # Convert to Python integer
25
+ output = ''
26
+ if predicted_class == 0:
27
+ output = "The password is very weak..."
28
+ elif predicted_class == 1:
29
+ output = "The password is average."
30
+ else:
31
+ output = "The password is strong. But alas, it is not unbreakable."
32
+
33
+ confidence = float(predicted_proba.max())
34
+
35
+ # Return as a list of lists for DataFrame
36
+ return [[password_input, output, confidence]]
37
+
38
+ except Exception as e:
39
+ return [[f"Error during prediction: {e}", "", ""]]
40
 
41
  demo = gr.Interface(
42
  fn=predictPasswordStrength,
43
  inputs=[gr.Textbox('Hello123', label='Password', info='The password to check the strength of', max_lines=1)],
44
+ outputs=[
45
+ gr.Dataframe(
46
+ row_count=(1, "fixed"),
47
+ col_count=(3, "fixed"),
48
+ headers=["Password", "Prediction", "Confidence"],
49
+ label="Password Strength Analysis"
50
+ )
51
+ ],
52
  title='Helix - Password Strength Analyzer',
53
  description='A password strength analyzer, trained on over 10 million different passwords.'
54
  )