import gradio as gr import pandas as pd import joblib model = joblib.load('decision_tree.pkl') def onehot(df, column): df = df.copy() dummies = pd.get_dummies(df[column]) df = pd.concat([df,dummies], axis=1) df = df.drop(column, axis=1) return df def dataframe(file_obj): df = pd.read_csv(file_obj.name) df = onehot(df, column='type') df = df.drop(['nameOrig','nameDest','isFlaggedFraud'], axis=1) print(df.shape) y_pred = model.predict(df) pred_df = pd.DataFrame(y_pred, columns = ['isFraud']) print(type(pred_df)) print(pred_df.shape) # clr = classification_report(y_test, y_pred, target_names=['Not Fraud','Fraud']) # return 'Classification Report:\n'+ clr return pred_df file = gr.inputs.File(file_count="single", type="file", label="CSV File for Predictions", optional=False) y_pred_df = gr.outputs.Dataframe(max_rows=20, max_cols=None, overflow_row_behaviour="paginate", type="auto", label="Predictions of records in the file") interface_csv = gr.Interface( fn=dataframe, inputs=file, outputs=y_pred_df, title="Fraud Detection - EXPERT SYSTEM", theme="dark-peach" ) interface_csv.launch(share=True, inline=False)