import pickle import cloudpickle import gradio as gr import pandas as pd # Load pipeline and features with open("IDS_Pipeline.pkl", "rb") as f: model = pickle.load(f) with open("feature_names.pkl", "rb") as f: feature_names = cloudpickle.load(f) # Prediction function def predict(file): df = pd.read_csv(file) df = df[feature_names] preds = model.predict(df) # corrected from pipeline.predict df["Prediction"] = preds return df # Gradio UI demo = gr.Interface( fn=predict, inputs=gr.File(type="file", label="Upload CSV file"), outputs=gr.Dataframe(label="Predictions"), title="Intrusion Detection System", description="Upload a CSV file with features. The model will predict if it's Normal or Attack." ) if __name__ == "__main__": demo.launch()