Spaces:
Running
Running
| import joblib | |
| import gradio as gr | |
| from pathlib import Path | |
| BASE_DIR = Path(__file__).resolve().parent | |
| MODEL_PATH = BASE_DIR / "model.pkl" | |
| model = joblib.load(MODEL_PATH) | |
| def predict_payload(payload: str) -> str: | |
| if not payload or not payload.strip(): | |
| return "Please enter a payload string." | |
| pred = int(model.predict([payload])[0]) | |
| label = "Buffer Overflow / Attack" if pred == 1 else "Normal" | |
| return f"Prediction: {pred} ({label})" | |
| demo = gr.Interface( | |
| fn=predict_payload, | |
| inputs=gr.Textbox(lines=8, label="Raw Network Payload"), | |
| outputs=gr.Textbox(label="IDS Classification"), | |
| title="Cloud-Native IDS Payload Classifier", | |
| description="Paste a raw payload string. The TF-IDF + XGBoost pipeline predicts Normal (0) or Attack (1).", | |
| ) | |
| if __name__ == "__main__": | |
| demo.launch() | |