Spaces:
Sleeping
Sleeping
File size: 1,994 Bytes
3cad9c7 b784405 9b126c8 b784405 9b126c8 b784405 a3d6b2a fee25ce b784405 3cad9c7 6ece9ae 3cad9c7 b784405 3cad9c7 |
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 45 46 47 48 49 50 51 52 53 54 55 56 |
import gradio as gr
import joblib
from sklearn.feature_extraction.text import TfidfVectorizer
from sklearn.calibration import CalibratedClassifierCV
# Load model and vectorizer
try:
model = joblib.load("helix-psa.pkl")
vectorizer = joblib.load("helix-psa-vectorizer.pkl")
print("Model and vectorizer loaded successfully.")
except Exception as e:
print("Error loading model or vectorizer:", e)
model, vectorizer = None, None # Assign None so we can check later
def predictPasswordStrength(password_input):
if model is None or vectorizer is None:
return [["Error: Model or vectorizer not loaded correctly.", "", ""]]
try:
password_tfidf = vectorizer.transform([password_input])
# Make predictions
predicted_proba = model.predict_proba(password_tfidf)
predicted_class = int(model.predict(password_tfidf)[0]) # Convert to Python integer
output = ''
if predicted_class == 0:
output = "The password is very weak..."
elif predicted_class == 1:
output = "The password is average."
else:
output = "The password is strong. But alas, it is not unbreakable."
confidence = float(predicted_proba.max())
# Return as a list of lists for DataFrame
return [[password_input, output, confidence]]
except Exception as e:
return [[f"Error during prediction: {e}", "", ""]]
demo = gr.Interface(
fn=predictPasswordStrength,
inputs=[gr.Textbox('Hello123', label='Password', info='The password to check the strength of', max_lines=1)],
outputs=[
gr.Dataframe(
row_count=(1, "fixed"),
col_count=(3, "fixed"),
headers=["Password", "Prediction", "Confidence"],
label="Password Strength Analysis"
)
],
title='Helix - Password Strength Analyzer',
description='A password strength analyzer, trained on over 10 million different passwords.'
)
demo.launch() |