Team Ai
Apppublic

rajasri77/Network-Security-AI-Tutor

sourceHugging Faceupdated 6mo agoView on Hugging Face
0likes
App README

Network Security AI Tutor & Quiz Generator

๐Ÿ‘‰ [๐Ÿš€ Try the Live App](https://huggingface.co/spaces/rajasri77/Network-Security-AI-Tutor)

I have developed an AI Tutor and custom Quiz Generator. It uses a Retrieval-Augmented Generation (RAG) system that answers questions primarily from my own lecture slides and textbook (PDFs in a local knowledge base). When the vector store does not surface relevant material, the app falls back to the web using SerpAPI (Google search results). Answers and quizzes are generated with OpenAI using a small, fast model (gpt-4o-mini by default).

An intelligent study companion powered by Retrieval-Augmented Generation (RAG). Ask questions and get answers drawn directly from your lecture slides and textbook โ€” with automatic Google search fallback when local knowledge isn't enough. Includes a full Quiz Center for MCQ, true/false, and open-ended practice questions.

The project ships with a Gradio web UI: an AI Tutor for Q&A and a Quiz Center that generates MCQs, true/false, and open questions from the same RAG context (or from web snippets if local retrieval is weak).

Technologies Used

  • โ€”Language: Python
  • โ€”LLM Integration: OpenAI (gpt-4o-mini)
  • โ€”Embeddings: Sentence-Transformers (all-MiniLM-L12-v2)
  • โ€”Vector Database: Qdrant
  • โ€”Web Interface: Gradio
  • โ€”Web Search Fallback: SerpAPI (Google Search)
  • โ€”Document Processing: PyMuPDF (fitz)
  • โ€”String Matching: RapidFuzz & python-Levenshtein
  • โ€”Environment: Docker & Hugging Face Spaces

What this system does

  1. 1.Ingest: PDFs under knowledge_base/ are split per page, embedded with Sentence Transformers (all-MiniLM-L12-v2, 384-dim vectors), and stored in Qdrant.
  2. 2.Retrieve: Your question is embedded and matched against Qdrant; results are filtered with fuzzy text overlap so only plausible chunks are used.
  3. 3.Generate: OpenAI (OPENAI_MODEL, default gpt-4o-mini) produces answers and quiz content from retrieved context.
  4. 4.Fallback: If no good local chunks are found, SerpAPI fetches top Google organic results; the model answers from those snippets and linked titles.

Prerequisites

  • โ€”Python 3.10+
  • โ€”No Docker required. Qdrant runs in embedded mode and stores data under qdrant_storage/ in the project root (or set QDRANT_PATH / QDRANT_URL in .env if you prefer another folder or Qdrant Cloud).
  • โ€”OpenAI API key and SerpAPI API key in a project-root `.env` file (see .env.example). Keys load automatically when you run the app.
  • โ€”Optional: `PUBLIC_APP_URL` after you deploy (e.g. Hugging Face Spaces) for the โ€œGive it a tryโ€ link.

Setup

1. Environment file

Copy .env.example to .env and fill in your keys:

text
OPENAI_API_KEY=sk-...
SERPAPI_API_KEY=...
OPENAI_MODEL=gpt-4o-mini
PUBLIC_APP_URL=https://huggingface.co/spaces/rajasri77/Network-Security-AI-Tutor

Use standard KEY=value lines (no spaces around =). Never commit .env (it is listed in .gitignore).

2. Virtual environment (optional)

powershell
cd path\to\Network_Security_Project
python -m venv venv
.\venv\Scripts\activate

If PowerShell blocks scripts:

powershell
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser

3. Install dependencies

powershell
pip install -r requirements.txt

4. Initialize the collection and load PDFs

Creates on-disk Qdrant storage and indexes every page of each PDF in knowledge_base\:

powershell
python Scripts\initialise_qdrant.py
python Scripts\Data_insertion_qdrant.py

Place lecture slides and your textbook in knowledge_base\ before ingestion. Re-run Data_insertion_qdrant.py after adding or changing PDFs.

5. Run the app

powershell
python Scripts\chatbot_application.py

Open the local URL printed in the terminal (Gradio default is often http://127.0.0.1:7860).

Optional: set GRADIO_SHARE=true in the environment for a temporary Gradio public link (useful for quick demos; for GitHub, prefer a stable Space URL in PUBLIC_APP_URL).

6. Run Using Docker (Alternative)

To completely bypass local Python dependency issues, you can run the entire Tutor and Quiz Generator inside an isolated Docker container:

powershell
docker build -t ai_tutor .
docker run -p 7860:7860 --env-file .env ai_tutor

Navigate your browser to http://localhost:7860.

Environment variables

VariableRequiredPurpose
OPENAI_API_KEYYesChat completions for tutor answers and quiz generation
SERPAPI_API_KEYYes for web fallbackGoogle search via SerpAPI when RAG misses

Project layout

PathRole
knowledge_base/PDFs (lectures, textbook)
.env.exampleTemplate for required variables
Scripts/qdrant_connection.pyBuilds Qdrant client (embedded disk by default; optional cloud URL)
Scripts/initialise_qdrant.pyCreates/recreates Qdrant collection network_security_knowledge
Scripts/Data_insertion_qdrant.pyEmbeds and upserts all PDF pages
Scripts/chatbot_application.pyGradio UI + RAG + OpenAI + SerpAPI + quiz
qdrant_storage/Local vector DB files (created automatically; gitignored)
requirements.txtPython dependencies

Security note

Keep OpenAI and SerpAPI keys only in .env. If a key was ever committed or shared, rotate it in the provider dashboards.

Troubleshooting

  • โ€”Missing OpenAI errors: Check .env uses OPENAI_API_KEY=... and that the file lives at the project root (next to README.md).
  • โ€”Empty or weak RAG answers: Run initialise_qdrant.py then Data_insertion_qdrant.py with PDFs present in knowledge_base\.
  • โ€”Web fallback errors: Confirm SERPAPI_API_KEY and quota on SerpAPI.

Stack: Qdrant, Sentence Transformers, OpenAI, Gradio, SerpAPI, PyMuPDF.