File size: 802 Bytes
bb2d299 6ae275e cf1dc40 afc772f cf1dc40 bb2d299 cf1dc40 | 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 | 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()
|