Spaces:
Runtime error
Runtime error
File size: 1,774 Bytes
c04e53d c893f94 c04e53d |
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 |
import h2o
import pandas as pd
import gradio as gr
# Initialize H2O server
h2o.init()
# Load the saved H2O model
saved_model_path = "XGBoost_1_AutoML_1_20240917_65817" # Replace with your model path
model = h2o.load_model(saved_model_path)
# Define the prediction function
def predict_fraud(Amount, Use_Chip, Merchant_City, Merchant_State, MCC, Errors, FICO_Score, Card_on_Dark_Web, Num_Credit_Cards):
# Create a pandas DataFrame from the input data
data = {
"Amount": [Amount],
"Use_Chip": [Use_Chip],
"Merchant_City": [Merchant_City],
"Merchant_State": [Merchant_State],
"MCC": [MCC],
"Errors": [Errors],
"FICO_Score": [FICO_Score],
"Card_on_Dark_Web": [Card_on_Dark_Web],
"Num_Credit_Cards": [Num_Credit_Cards]
}
df = pd.DataFrame(data)
# Convert to H2OFrame
hf = h2o.H2OFrame(df)
# Get predictions from the model
predictions = model.predict(hf)
# Extract the prediction result
return predictions.as_data_frame().iloc[0, 0]
# Create Gradio interface
interface = gr.Interface(
fn=predict_fraud,
inputs=[
gr.inputs.Number(label="Amount"),
gr.inputs.Dropdown(["Yes", "No"], label="Use Chip"),
gr.inputs.Textbox(label="Merchant City"),
gr.inputs.Textbox(label="Merchant State"),
gr.inputs.Number(label="MCC"),
gr.inputs.Textbox(label="Errors"),
gr.inputs.Number(label="FICO Score"),
gr.inputs.Dropdown(["Yes", "No"], label="Card on Dark Web"),
gr.inputs.Number(label="Number of Credit Cards")
],
outputs="text",
title="Fraud Detection Model",
description="Enter transaction details to predict if it's fraudulent."
)
# Launch the interface
interface.launch()
|