rajasri77/Network-Security-AI-Tutor
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
- Ingest: PDFs under
knowledge_base/are split per page, embedded with Sentence Transformers (all-MiniLM-L12-v2, 384-dim vectors), and stored in Qdrant. - Retrieve: Your question is embedded and matched against Qdrant; results are filtered with fuzzy text overlap so only plausible chunks are used.
- Generate: OpenAI (
OPENAI_MODEL, defaultgpt-4o-mini) produces answers and quiz content from retrieved context. - 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 setQDRANT_PATH/QDRANT_URLin.envif 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:
OPENAI_API_KEY=sk-...
SERPAPI_API_KEY=...
OPENAI_MODEL=gpt-4o-mini
PUBLIC_APP_URL=https://huggingface.co/spaces/rajasri77/Network-Security-AI-TutorUse standard KEY=value lines (no spaces around =). Never commit .env (it is listed in .gitignore).
2. Virtual environment (optional)
cd path\to\Network_Security_Project
python -m venv venv
.\venv\Scripts\activateIf PowerShell blocks scripts:
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser3. Install dependencies
pip install -r requirements.txt4. Initialize the collection and load PDFs
Creates on-disk Qdrant storage and indexes every page of each PDF in knowledge_base\:
python Scripts\initialise_qdrant.py
python Scripts\Data_insertion_qdrant.pyPlace 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
python Scripts\chatbot_application.pyOpen 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:
docker build -t ai_tutor .
docker run -p 7860:7860 --env-file .env ai_tutorNavigate your browser to http://localhost:7860.
Environment variables
Project layout
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
.envusesOPENAI_API_KEY=...and that the file lives at the project root (next toREADME.md). - Empty or weak RAG answers: Run
initialise_qdrant.pythenData_insertion_qdrant.pywith PDFs present inknowledge_base\. - Web fallback errors: Confirm
SERPAPI_API_KEYand quota on SerpAPI.
Stack: Qdrant, Sentence Transformers, OpenAI, Gradio, SerpAPI, PyMuPDF.
