CoolFace
Apppublic

NavRBot/knowledge-agent-platform

sourceHugging Faceupdated 28d agoView on Hugging Face
0likes
App README

Knowledge Agent Platform — Phase 1 POC

A self-hosted, multi-agent RAG chatbot builder (NotebookLM / Copilot-Agent style), built entirely on free/open-source libraries.

What's included right now

  • Admin console: create agents, define role/task/context/constraints/output-structure prompts, set guardrails, pick a communication style (Formal / Casual / Child-friendly Gen-Z), upload a knowledge base, and get a shareable link.
  • Ingestion for: PDF, DOCX, PPTX, XLSX, CSV, JSON, TXT, images (OCR), and web URLs.
  • Free local embeddings (sentence-transformers) + persisted Chroma vector DB — no embedding API costs.
  • LLM provider routing with fallback chain, retries, rate limiting, and caching (model_router.py) across Anthropic / Groq / Hugging Face Inference — all have free tiers.
  • Basic PII scrubbing (pii_guard.py) applied to every message and retrieved chunk before it's sent to any LLM provider, with an audit log.
  • Works on phone and PC automatically — Gradio's layout is responsive by default; no extra work needed for mobile.

What's intentionally deferred to Phase 2/3 (see bottom)

SharePoint live connectors, PowerBI/Tableau native file parsing, real multi-tenant auth, a proper analytics database, and a certified-grade PII/DLP pipeline. These are genuine sub-projects in their own right — see roadmap below.


1. Run it locally

bash
git clone <your-repo>   # or just copy this folder
cd rag-chatbot-poc
python -m venv venv && source venv/bin/activate   # Windows: venv\Scripts\activate
pip install -r requirements.txt

# If OCR (image ingestion) is needed, also install the Tesseract binary:
#   macOS:   brew install tesseract
#   Ubuntu:  sudo apt-get install tesseract-ocr
#   Windows: https://github.com/UB-Mannheim/tesseract/wiki

# Set at least ONE provider key (pick whichever is easiest for you):
export ANTHROPIC_API_KEY=sk-ant-...
# or: export GROQ_API_KEY=gsk_...      (Groq has a generous free tier — good first pick)
# or: export HF_TOKEN=hf_...           (Hugging Face Inference API, many free models)

python app.py

Open http://localhost:7860 — you'll land on the Admin console. Create an agent, upload a few files, then click "Get share URL" and open http://localhost:7860/?agent=<slug> to chat with it.


2. Deploy to Hugging Face Spaces (free hosting)

  1. 1.Create a free Hugging Face account at huggingface.co.
  2. 2.Click New Space → choose SDK: Gradio → hardware: CPU basic (free). (Note: HF deprecated the built-in Streamlit SDK — Streamlit now only ships via the Docker SDK, which requires a paid plan on many accounts. Gradio is the free, fully-supported path, which is what this app is built on.)
  3. 3.In the new Space's Files tab, upload every file from this folder (app.py, agent_store.py, ingest.py, model_router.py, pii_guard.py, vectorstore.py, requirements.txt, packages.txt) — or connect the Space to a GitHub repo containing them for auto-deploy on push.
  4. 4.Go to Settings → Variables and secrets and add your LLM key(s) as Secrets (never as plain Variables): ANTHROPIC_API_KEY, GROQ_API_KEY, and/or HF_TOKEN. Secrets are encrypted and never shown in the app or logs.
  5. 5.The Space builds automatically. Your app is now live at https://<your-username>-<space-name>.hf.space.
  6. 6.Share an agent externally with: https://<your-username>-<space-name>.hf.space/?agent=<slug>

Persistence note: Free HF Spaces storage resets when the Space sleeps/restarts unless you enable persistent storage (small paid add-on) or use a Space with a mounted volume. For a POC this is usually fine — re-ingest docs after a cold restart, or upgrade storage once you're past the demo stage.

Alternative free/low-cost hosts, roughly in order of "how much more you get for a bit more setup effort": Railway and Render (both have free/hobby tiers, persistent disks, better for anything beyond a demo) beat HF Spaces once you need real persistence or multiple users.


3. Mobile compatibility

Nothing extra to build — Gradio's UI is responsive out of the box, and the chat view especially (single column, big touch targets) works well on phones.


4. Phased roadmap for the rest of the spec

Phase 2 — hardening & real multi-user:

  • Swap agent_store.py's JSON files for SQLite/Postgres + row-level auth (e.g. Supabase, which is free-tier and open-source, gives you auth + DB together).
  • Replace regex PII scrubbing with Microsoft Presidio (free, open-source, NER-based) for genuinely GDPR/PDPA-grade detection, plus a human-reviewed redaction policy signed off by compliance.
  • Add a jailbreak/prompt-injection classifier in front of the LLM call (e.g. protectai/deberta-v3-base-prompt-injection, free on Hugging Face).
  • Persist per-request metrics (tokens, latency, provider, cache hit) to a small table and build the Analytics tab out properly.

Phase 3 — enterprise connectors:

  • SharePoint/Graph API connector for live document sync (needs Azure AD app registration — this is genuinely a project of its own).
  • PowerBI/Tableau: these are proprietary binary container formats. The realistic free path isn't parsing the file directly — it's pulling data via their REST APIs (Power BI REST API, Tableau Server REST API) or having admins export the underlying dataset/report to CSV/PDF first, which this POC already ingests.
  • Proper multi-tenant sharing by email invite (needs an email service — free tiers exist on Resend/SendGrid) instead of a raw link.

I'd suggest running this Phase-1 POC for a week or two with real content first — it'll tell you which Phase-2 items actually matter for your use case versus which ones are nice-to-haves.