Spaces:
Runtime error
Runtime error
import gradio as gr | |
from huggingface_hub import hf_hub_download | |
import joblib | |
import numpy as np | |
import os | |
# Download the model and scaler from your repository | |
model_path = hf_hub_download(repo_id="NiharMandahas/RF_Customer_Fraud", filename="random_forest_model.joblib") | |
scaler_path = hf_hub_download(repo_id="NiharMandahas/RF_Customer_Fraud", filename="rf_scaler.joblib") | |
# Load the model and scaler | |
model = joblib.load(model_path) | |
scaler = joblib.load(scaler_path) | |
def predict_fraud(account_age, cred_changes_freq, return_order_ratio, vpn_usage, credit_score): | |
# Prepare input | |
input_data = np.array([[ | |
account_age, | |
cred_changes_freq, | |
return_order_ratio, | |
vpn_usage, | |
credit_score | |
]]) | |
# Scale input | |
scaled_input = scaler.transform(input_data) | |
# Get prediction and probability | |
prediction = model.predict(scaled_input)[0] | |
probabilities = model.predict_proba(scaled_input)[0] | |
# Prepare result | |
result = "Fraud" if prediction == 1 else "Not Fraud" | |
confidence = float(probabilities[prediction]) | |
return f"Prediction: {result}\nConfidence: {confidence:.2f}" | |
# Create Gradio interface | |
iface = gr.Interface( | |
fn=predict_fraud, | |
inputs=[ | |
gr.Number(label="Account Age (months)"), | |
gr.Number(label="Credential Changes Frequency (per year)"), | |
gr.Number(label="Return to Order Ratio"), | |
gr.Number(label="VPN Usage (0 or 1)"), | |
gr.Number(label="Credit Score") | |
], | |
outputs="text", | |
title="Fraud Detection Model", | |
description="Enter account details to predict potential fraud" | |
) | |
iface.launch() |