Spaces:
Sleeping
Sleeping
File size: 2,621 Bytes
bbcdc88 |
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 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
"""
Quick test script to verify model loading and Flask setup
"""
import os
import sys
def test_setup():
print("π§ͺ Testing Fraud Detection Setup")
print("=" * 40)
# Test 1: Check files exist
print("\nπ Checking files...")
required_files = ['model.pkl', 'encoders.pkl', 'app.py', 'templates/index.html']
for file in required_files:
if os.path.exists(file):
print(f"β
{file} - Found")
else:
print(f"β {file} - Missing")
# Test 2: Test imports
print("\nπ¦ Testing imports...")
try:
import flask
print(f"β
Flask - {flask.__version__}")
except ImportError:
print("β Flask - Not installed")
try:
import sklearn
print(f"β
scikit-learn - {sklearn.__version__}")
except ImportError:
print("β scikit-learn - Not installed")
try:
import pandas
print(f"β
pandas - {pandas.__version__}")
except ImportError:
print("β pandas - Not installed")
try:
import joblib
print(f"β
joblib - {joblib.__version__}")
except ImportError:
print("β joblib - Not installed")
# Test 3: Test model loading
print("\nπ€ Testing model loading...")
try:
import joblib
model = joblib.load('model.pkl')
print(f"β
Model loaded - {type(model)}")
encoders = joblib.load('encoders.pkl')
print(f"β
Encoders loaded - {type(encoders)}")
# Test prediction
import pandas as pd
test_data = pd.DataFrame([{
'Gender': 1, 'Age': 35, 'State': 15, 'City': 127,
'Bank_Branch': 127, 'Account_Type': 2, 'Transaction_Date': 22,
'Transaction_Time': 52151, 'Transaction_Amount': 1000.0,
'Transaction_Type': 3, 'Account_Balance': 50000.0,
'Transaction_Device': 17, 'Transaction_Currency': 0
}])
prediction = model.predict(test_data)[0]
probability = model.predict_proba(test_data)[0]
print(f"β
Test prediction - {prediction} (prob: {probability[1]:.3f})")
except Exception as e:
print(f"β Model loading failed - {str(e)}")
print("\n" + "=" * 40)
print("π Setup test completed!")
print("\nIf all tests passed, you can run:")
print(" python app.py")
print("\nThen open your browser to:")
print(" http://localhost:5000")
if __name__ == "__main__":
test_setup()
|