{ "nbformat": 4, "nbformat_minor": 0, "metadata": { "colab": { "provenance": [] }, "kernelspec": { "name": "python3", "display_name": "Python 3" }, "language_info": { "name": "python" } }, "cells": [ { "cell_type": "code", "execution_count": null, "metadata": { "id": "M8NNCivsv-38" }, "outputs": [], "source": [ "!pip install -q huggingface-hub joblib pandas scikit-learn matplotlib seaborn" ] }, { "cell_type": "code", "source": [ "from huggingface_hub import hf_hub_download\n", "import joblib, os, pandas as pd\n", "\n", "REPO_ID = \"dr-rakshith-truth-zeeker/truth-zeeker-ai-demo\"\n", "FNAME = \"model.joblib\"\n", "\n", "path = hf_hub_download(repo_id=REPO_ID, filename=FNAME)\n", "print(\"✅ Downloaded model from Hugging Face:\", path)\n", "\n", "model = joblib.load(path)\n", "print(\"Model loaded successfully:\", type(model))" ], "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "4cRLizbOwmYH", "outputId": "e8c03cc1-4573-4d17-95aa-73955dbafc76" }, "execution_count": null, "outputs": [ { "output_type": "stream", "name": "stdout", "text": [ "✅ Downloaded model from Hugging Face: /root/.cache/huggingface/hub/models--dr-rakshith-truth-zeeker--truth-zeeker-ai-demo/snapshots/c53c401c56ba50cac5bb805104dfe5ecf380d022/model.joblib\n", "Model loaded successfully: \n" ] } ] }, { "cell_type": "code", "source": [ "csv_url = \"https://raw.githubusercontent.com/dr-rakshith-truth-zeeker/Truth-Zeeker-AI/refs/heads/release/demo_data/sample_features.csv?token=GHSAT0AAAAAADNHI2OE4ZDLAJ26R6E2CJZY2HP242Q\"\n", "\n", "df = pd.read_csv(csv_url)\n", "print(\"Loaded demo data shape:\", df.shape)\n", "print(\"\\nFirst 10 rows:\\n\")\n", "print(df.head(10).to_string(index=False))\n", "\n", "# Run inference (handle tuple (scaler, model) or plain model)\n", "if isinstance(model, tuple) and len(model) == 2:\n", " scaler, clf = model\n", " Xs = scaler.transform(df[['duration','orig_bytes','resp_bytes']])\n", " preds = clf.predict(Xs)\n", "else:\n", " clf = model\n", " preds = clf.predict(df[['duration','orig_bytes','resp_bytes']])\n", "\n", "df['anomaly_flag'] = preds\n", "print(\"\\nResults with anomaly_flag:\\n\")\n", "print(df.to_string(index=False))" ], "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "4NqEdftzx-dN", "outputId": "dcff4174-28dc-4ea5-b900-18575399a712" }, "execution_count": null, "outputs": [ { "output_type": "stream", "name": "stdout", "text": [ "Loaded demo data shape: (10, 3)\n", "\n", "First 10 rows:\n", "\n", " duration orig_bytes resp_bytes\n", " 0.12 456 789\n", " 0.08 123 80\n", " 0.30 2000 150\n", " 0.05 60 0\n", " 0.90 4000 1200\n", " 0.02 50 10\n", " 0.20 300 400\n", " 0.25 1500 1200\n", " 0.15 800 200\n", " 0.07 90 70\n", "\n", "Results with anomaly_flag:\n", "\n", " duration orig_bytes resp_bytes anomaly_flag\n", " 0.12 456 789 1\n", " 0.08 123 80 1\n", " 0.30 2000 150 1\n", " 0.05 60 0 1\n", " 0.90 4000 1200 -1\n", " 0.02 50 10 1\n", " 0.20 300 400 1\n", " 0.25 1500 1200 -1\n", " 0.15 800 200 1\n", " 0.07 90 70 1\n" ] }, { "output_type": "stream", "name": "stderr", "text": [ "/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", " warnings.warn(\n" ] } ] } ] }