Built by Fardeen as part of the DesiCrew technical evaluation.
Prototype disclaimer. These are working prototypes built to demonstrate the approach and core functionality. I’ve put my best effort into making them reliable, but as prototypes, they may still have some rough edges or limitations.
One web app, three tools:
| # | Tool | What it does | Backend package |
|---|---|---|---|
| 1 | Inventory Data Agent | Chat with an Excel inventory dataset. The agent writes and runs pandas code, searches the web for definitions, and answers in plain English. | backend/app/inventory_agent/ |
| 2 | Student Handbook Assistant | Multi-turn Q&A over the IITM BS Student Handbook. Remembers the session, avoids repeating itself, handles topic switches, cites the handbook section for every answer. | backend/app/handbook_assistant/ |
| 3 | Document Extraction Pipeline | Classifies identity proofs and insurance forms, extracts the required fields (including handwriting), scores confidence per field, and flags uncertain fields for human review. | backend/app/document_pipeline/ |
| Layer | Choice | Why |
|---|---|---|
| Backend | FastAPI (Python 3.12) | Simple, typed, auto-generated API docs at /docs |
| Frontend | React + Vite (plain JavaScript, plain CSS) | Fewest concepts to learn |
| LLM | Google Gemini | Free quota; reads images too: classifies documents and is the second, independent field reader |
| Handbook structure + page numbers | python-docx + pdfplumber | Word headings give the section tree; the PDF gives page numbers for citations |
| Scanned / handwritten documents | Sarvam Doc AI extract |
Built for Indian documents; returns each field with its own confidence |
| Web search | DuckDuckGo (ddgs) |
No API key needed |
| Embeddings | all-MiniLM-L6-v2 (sentence-transformers) |
Runs locally, free |
| Vector store | FAISS saved to disk (index.faiss + metadata.pkl) |
Build once, load quickly |
project/
├── backend/
│ ├── app/
│ │ ├── main.py # FastAPI entry point; mounts the three tools
│ │ ├── config.py # All settings and paths in one place
│ │ ├── sessions.py # In-memory, per-visitor session store
│ │ ├── errors.py # Shared error types and their HTTP responses
│ │ ├── shared/ # Code used by more than one tool
│ │ │ ├── llm_client.py # Gemini wrapper (text, JSON, images, retries)
│ │ │ ├── sarvam_reader.py # Sarvam Doc AI extract: fields + per-field confidence
│ │ │ └── page_images.py # page → image (PDFs rendered) for Gemini vision
│ │ ├── inventory_agent/ # Tool 1
│ │ ├── handbook_assistant/ # Tool 2
│ │ └── document_pipeline/ # Tool 3
│ ├── scripts/ # One-off command-line jobs (build index, batch run, evaluate)
│ └── requirements.txt
├── frontend/
│ └── src/
│ ├── pages/ # Landing page + one page per tool
│ ├── components/ # Reusable UI pieces (cards, chat window, ...)
│ └── api/ # The only place that talks to the backend
├── data/
│ ├── inventory/ # Task 1 input (Excel)
│ ├── handbook/ # Task 2 input (IITM BS Student Handbook: .docx for text, .pdf for pages)
│ ├── documents/ # Task 3 input (12 files: 10 target documents + 2 extras)
│ └── ground_truth/ # Hand-labelled answer key used to measure Task 3 accuracy
├── storage/handbook_index/ # Generated: index.faiss + metadata.pkl
├── outputs/document_pipeline/ # Generated: per-document JSON + flagging report
└── docs/ # Write-ups
├── task3_document_inventory.md # what each sample document is + the traps it contains
├── flagging_threshold_rationale.md # Task 3 deliverable: threshold + why
├── handwriting_note.md # Task 3 deliverable: handwritten vs printed + failure cases
├── handbook_demo_conversation.md # Task 2 deliverable: 13-turn demo conversation
└── sarvam_reference/ # Sarvam API as observed: payload shape, limits + real sample responses
Where to start reading: backend/app/main.py, then the pipeline/agent/assistant module of the tool you're
interested in (document_pipeline/pipeline.py, inventory_agent/agent.py, handbook_assistant/assistant.py).
Each one lists its steps at the top and points to the modules that do the work.
Each backend tool follows the same pattern:
router.py: the HTTP endpoints. They stay thin and only call the service code.prompts.py: every prompt sent to Gemini, kept together so they are easy to read and tune.- The other modules: one job each, named after that job.
cp .env.example .env
# then fill in GEMINI_API_KEY and SARVAM_API_KEYcd backend
python -m venv .venv
.venv\Scripts\activate # Windows (macOS/Linux: source .venv/bin/activate)
pip install -r requirements.txt
uvicorn app.main:app --reload --reload-dir app --port 8000
--reload-dir apprestarts the server only when the app's own code changes. Without it, uvicorn also watches.venv/, so even apip installrestarts the server, which clears all in-memory sessions. (Chats survive anyway: each tool also keeps its screen in the tab'ssessionStorage. See below.)
API docs: http://localhost:8000/docs
cd frontend
npm install
npm run devApp: http://localhost:5173. The Vite dev server forwards /api/* requests to the backend.
cd backend
python -m scripts.build_handbook_index # Task 2: PDF → index.faiss + metadata.pkl
python -m scripts.run_document_pipeline # Task 3: all documents → outputs/document_pipeline/
python -m scripts.evaluate_extraction # Task 3: compare outputs against the answer key
python -m scripts.run_handbook_demo # Task 2: scripted 10+ turn conversation| Tool | Status |
|---|---|
| 1 · Inventory Data Agent | ✅ Built. Gemini function-calling loop with two tools: run_python (pandas on the dataset) and web_search (DuckDuckGo). Shows every step, handles follow-ups, accepts uploaded Excel files. |
| 2 · Student Handbook Assistant | ✅ Built. Sections from the .docx heading styles, pages from the PDF, hybrid retrieval (MiniLM + BM25), session memory. 13-turn demo in docs/handbook_demo_conversation.md. |
| 3 · Document Extraction Pipeline | ✅ Built and evaluated. 12/12 classified, 42/44 fields correct (27/28 handwritten), 0 wrong-and-unflagged. Deliverables in outputs/document_pipeline/ and docs/. |
question + earlier chat ─► Gemini (system prompt holds the dataset's columns + first rows)
│ asks for a tool?
├─ run_python(code) ─► code_runner: exec on a COPY of df, captured print, 10 s timeout
├─ web_search(query) ─► DuckDuckGo top 5 (title, url, snippet)
└─ results go back to Gemini … repeat (max 6 rounds) … final plain-English answer
Safety note (prototype): agent-written code runs in-process with a whitelist of built-ins, a blocklist of dangerous names (imports, files, dunder access) and a timeout. That is NOT a real sandbox; production would run it in an isolated container.
OFFLINE Student Handbook.docx ─► sections from Word heading styles (115 sections, tables kept as rows)
Student Handbook.pdf ─► page of each section, found by searching its heading (TOC page numbers are stale)
─► 148 section-aware chunks ─► MiniLM vectors ─► index.faiss + metadata.pkl
ONLINE question + session memory
─► Gemini: short stand-alone search query, broad topic, topic switch? return to earlier topic?
─► hybrid retrieval: FAISS (meaning) + BM25 (exact words), fused with Reciprocal Rank Fusion
─► chunks already cited in earlier turns are marked "ALREADY SHARED IN TURN n"
─► Gemini answers with [n] markers ─► citations: section path + PDF pages
─► memory records question, topic, cited sections, one-line summary
| Requirement | How |
|---|---|
| Remember what was asked | per-session memory: every turn's question, topic, cited sections and a one-line summary |
| Avoid repeating | retrieved sections already used are labelled "ALREADY SHARED IN TURN n", so the model refers back ("As I mentioned in turn 2, …") |
| Handle topic switches | each question gets a broad topic label; switches and returns to earlier topics are detected and acknowledged |
| Cite the specific section | every answer cites [n] markers mapped to the full section path and PDF page(s), e.g. 15. Academic aspects › 15.7 Repeating a course › 15.7.3 Repeating a Course for Improvement (p. 47) |
Rebuild the index after changing the handbook: python -m scripts.build_handbook_index.
Regenerate the demo transcript: python -m scripts.run_handbook_demo (≈ 25 Gemini calls).
A session = one browser tab. Each tab gets an id (kept in sessionStorage) that it sends with every request,
and the backend keeps that session's chats and memory in memory. Each tool page also keeps its screen
(chat messages, document results, selected file) in sessionStorage. So the state survives going back to the
landing page, a page refresh, and even a backend restart; a new tab starts empty. If the backend restarted, the
old chat stays visible with a note that the assistant no longer remembers it (frontend/src/chatHistory.js).
The free tier allows only ~20 requests per day per model. The client walks an ordered list of models
(GEMINI_MODEL, then GEMINI_FALLBACK_MODELS) and skips any model that recently returned 429, so each extra model
adds daily capacity. If every model is exhausted, the UI shows a friendly "quota used up" message.
| Deliverable | Where |
|---|---|
| Structured JSON per document | outputs/document_pipeline/documents/*.json (+ all_documents.json) |
| Confidence score per field | every field's confidence, with confidence_breakdown and both readers' readings |
| Flagging report + threshold + rationale | outputs/document_pipeline/flagging_report.md / .json, docs/flagging_threshold_rationale.md |
| Handwritten vs printed note + failure cases | docs/handwriting_note.md |
Re-score the saved readings after changing weights or thresholds (no API calls):
python -m scripts.run_document_pipeline --rescore && python -m scripts.evaluate_extraction