Spaces:
Runtime error
Runtime error
| 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() | |