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
| 7 |
+
},
|
| 8 |
+
"kernelspec": {
|
| 9 |
+
"name": "python3",
|
| 10 |
+
"display_name": "Python 3"
|
| 11 |
+
},
|
| 12 |
+
"language_info": {
|
| 13 |
+
"name": "python"
|
| 14 |
+
}
|
| 15 |
+
},
|
| 16 |
+
"cells": [
|
| 17 |
+
{
|
| 18 |
+
"cell_type": "code",
|
| 19 |
+
"execution_count": null,
|
| 20 |
+
"metadata": {
|
| 21 |
+
"id": "M8NNCivsv-38"
|
| 22 |
+
},
|
| 23 |
+
"outputs": [],
|
| 24 |
+
"source": [
|
| 25 |
+
"!pip install -q huggingface-hub joblib pandas scikit-learn matplotlib seaborn"
|
| 26 |
+
]
|
| 27 |
+
},
|
| 28 |
+
{
|
| 29 |
+
"cell_type": "code",
|
| 30 |
+
"source": [
|
| 31 |
+
"from huggingface_hub import hf_hub_download\n",
|
| 32 |
+
"import joblib, os, pandas as pd\n",
|
| 33 |
+
"\n",
|
| 34 |
+
"REPO_ID = \"dr-rakshith-truth-zeeker/truth-zeeker-ai-demo\"\n",
|
| 35 |
+
"FNAME = \"model.joblib\"\n",
|
| 36 |
+
"\n",
|
| 37 |
+
"path = hf_hub_download(repo_id=REPO_ID, filename=FNAME)\n",
|
| 38 |
+
"print(\"✅ Downloaded model from Hugging Face:\", path)\n",
|
| 39 |
+
"\n",
|
| 40 |
+
"model = joblib.load(path)\n",
|
| 41 |
+
"print(\"Model loaded successfully:\", type(model))"
|
| 42 |
+
],
|
| 43 |
+
"metadata": {
|
| 44 |
+
"colab": {
|
| 45 |
+
"base_uri": "https://localhost:8080/"
|
| 46 |
+
},
|
| 47 |
+
"id": "4cRLizbOwmYH",
|
| 48 |
+
"outputId": "e8c03cc1-4573-4d17-95aa-73955dbafc76"
|
| 49 |
+
},
|
| 50 |
+
"execution_count": null,
|
| 51 |
+
"outputs": [
|
| 52 |
+
{
|
| 53 |
+
"output_type": "stream",
|
| 54 |
+
"name": "stdout",
|
| 55 |
+
"text": [
|
| 56 |
+
"✅ Downloaded model from Hugging Face: /root/.cache/huggingface/hub/models--dr-rakshith-truth-zeeker--truth-zeeker-ai-demo/snapshots/c53c401c56ba50cac5bb805104dfe5ecf380d022/model.joblib\n",
|
| 57 |
+
"Model loaded successfully: <class 'tuple'>\n"
|
| 58 |
+
]
|
| 59 |
+
}
|
| 60 |
+
]
|
| 61 |
+
},
|
| 62 |
+
{
|
| 63 |
+
"cell_type": "code",
|
| 64 |
+
"source": [
|
| 65 |
+
"csv_url = \"https://raw.githubusercontent.com/dr-rakshith-truth-zeeker/Truth-Zeeker-AI/refs/heads/release/demo_data/sample_features.csv?token=GHSAT0AAAAAADNHI2OE4ZDLAJ26R6E2CJZY2HP242Q\"\n",
|
| 66 |
+
"\n",
|
| 67 |
+
"df = pd.read_csv(csv_url)\n",
|
| 68 |
+
"print(\"Loaded demo data shape:\", df.shape)\n",
|
| 69 |
+
"print(\"\\nFirst 10 rows:\\n\")\n",
|
| 70 |
+
"print(df.head(10).to_string(index=False))\n",
|
| 71 |
+
"\n",
|
| 72 |
+
"# Run inference (handle tuple (scaler, model) or plain model)\n",
|
| 73 |
+
"if isinstance(model, tuple) and len(model) == 2:\n",
|
| 74 |
+
" scaler, clf = model\n",
|
| 75 |
+
" Xs = scaler.transform(df[['duration','orig_bytes','resp_bytes']])\n",
|
| 76 |
+
" preds = clf.predict(Xs)\n",
|
| 77 |
+
"else:\n",
|
| 78 |
+
" clf = model\n",
|
| 79 |
+
" preds = clf.predict(df[['duration','orig_bytes','resp_bytes']])\n",
|
| 80 |
+
"\n",
|
| 81 |
+
"df['anomaly_flag'] = preds\n",
|
| 82 |
+
"print(\"\\nResults with anomaly_flag:\\n\")\n",
|
| 83 |
+
"print(df.to_string(index=False))"
|
| 84 |
+
],
|
| 85 |
+
"metadata": {
|
| 86 |
+
"colab": {
|
| 87 |
+
"base_uri": "https://localhost:8080/"
|
| 88 |
+
},
|
| 89 |
+
"id": "4NqEdftzx-dN",
|
| 90 |
+
"outputId": "dcff4174-28dc-4ea5-b900-18575399a712"
|
| 91 |
+
},
|
| 92 |
+
"execution_count": null,
|
| 93 |
+
"outputs": [
|
| 94 |
+
{
|
| 95 |
+
"output_type": "stream",
|
| 96 |
+
"name": "stdout",
|
| 97 |
+
"text": [
|
| 98 |
+
"Loaded demo data shape: (10, 3)\n",
|
| 99 |
+
"\n",
|
| 100 |
+
"First 10 rows:\n",
|
| 101 |
+
"\n",
|
| 102 |
+
" duration orig_bytes resp_bytes\n",
|
| 103 |
+
" 0.12 456 789\n",
|
| 104 |
+
" 0.08 123 80\n",
|
| 105 |
+
" 0.30 2000 150\n",
|
| 106 |
+
" 0.05 60 0\n",
|
| 107 |
+
" 0.90 4000 1200\n",
|
| 108 |
+
" 0.02 50 10\n",
|
| 109 |
+
" 0.20 300 400\n",
|
| 110 |
+
" 0.25 1500 1200\n",
|
| 111 |
+
" 0.15 800 200\n",
|
| 112 |
+
" 0.07 90 70\n",
|
| 113 |
+
"\n",
|
| 114 |
+
"Results with anomaly_flag:\n",
|
| 115 |
+
"\n",
|
| 116 |
+
" duration orig_bytes resp_bytes anomaly_flag\n",
|
| 117 |
+
" 0.12 456 789 1\n",
|
| 118 |
+
" 0.08 123 80 1\n",
|
| 119 |
+
" 0.30 2000 150 1\n",
|
| 120 |
+
" 0.05 60 0 1\n",
|
| 121 |
+
" 0.90 4000 1200 -1\n",
|
| 122 |
+
" 0.02 50 10 1\n",
|
| 123 |
+
" 0.20 300 400 1\n",
|
| 124 |
+
" 0.25 1500 1200 -1\n",
|
| 125 |
+
" 0.15 800 200 1\n",
|
| 126 |
+
" 0.07 90 70 1\n"
|
| 127 |
+
]
|
| 128 |
+
},
|
| 129 |
+
{
|
| 130 |
+
"output_type": "stream",
|
| 131 |
+
"name": "stderr",
|
| 132 |
+
"text": [
|
| 133 |
+
"/usr/local/lib/python3.12/dist-packages/sklearn/utils/validation.py:2732: UserWarning: X has feature names, but StandardScaler was fitted without feature names\n",
|
| 134 |
+
" warnings.warn(\n"
|
| 135 |
+
]
|
| 136 |
+
}
|
| 137 |
+
]
|
| 138 |
+
}
|
| 139 |
+
]
|
| 140 |
+
}
|