Spaces:
Sleeping
Sleeping
Commit ·
35fbb15
0
Parent(s):
Initial clean LFS commit
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- .dockerignore +9 -0
- .gitattributes +40 -0
- .gitignore +12 -0
- Dockerfile +21 -0
- README.md +182 -0
- backend/Untitled +1 -0
- backend/db.py +132 -0
- backend/ingest.py +139 -0
- backend/main.py +200 -0
- backend/rag.py +139 -0
- documents/.gitkeep +0 -0
- documents/A011-Research-Honorarium-and-Conference-Assistance-Policy-V3.pdf +3 -0
- documents/A013-Policy-for-Workload-Relief-of-PhD-Scholars-V2.pdf +3 -0
- documents/A014-Policy-for-Honorarium-on-Research-Project-Grants-V1-16-08-2021.pdf +3 -0
- documents/A014-Policy-for-Honorarium-on-Research-Project-Grants-V2-08-05-2023.pdf +3 -0
- documents/A015-Semester-Rules-for-Post-Graduate-Programs-V2.pdf +3 -0
- documents/A024-Policy-for-Transfer-of-Credit-Hours-Student-Mobility-12-08-2021-min.pdf +3 -0
- documents/A025-Admission-Policy-Fall-2021-12-08-2021-min.pdf +3 -0
- documents/A026-Policy-for-Role-and-Responsibility-of-Academic-Advisor-V1.pdf +3 -0
- documents/A028-Internship-Policy-and-Mechanism-V1.pdf +3 -0
- documents/A07-Rules-Regulations-for-the-Degree-of-Masters-in-Science-V2.pdf +3 -0
- documents/A08-Rules-and-Regulations-for-the-degree-of-PhD-V5.pdf +3 -0
- documents/A21-Attendance-Policy-for-Online-Classes-Fall-2020-1-converted.pdf +3 -0
- documents/Academic-Freedom-Policy.pdf +3 -0
- documents/Academic-Rules-Regulations.pdf +3 -0
- documents/Admission-Policy-2021-2022-12-06-2021-V0-converted-min.pdf +3 -0
- documents/Admission-Policy-2022-2023-14-11-2022-min.pdf +3 -0
- documents/Admission-Policy-2024-2025.pdf +3 -0
- documents/Amendment_Policy_Sexual_Harassment-ACT-2022.pdf +3 -0
- documents/Annex-F-SSUET-MBA-Rules-Regulations-Ver-2.pdf +3 -0
- documents/Appeals-Procedure-Policy.pdf +3 -0
- documents/Application-Form-for-Publication-Honorarium-1-converted.pdf +3 -0
- documents/Arrangements-to-Prevent-Fradulent-Claims-of-Degree-Policy (1).pdf +3 -0
- documents/Arrangements-to-Prevent-Fradulent-Claims-of-Degree-Policy.pdf +3 -0
- documents/Conflict-of-Interest-Policy.pdf +3 -0
- documents/Environment-Health-and-Safety-Policy.pdf +3 -0
- documents/Evaluation-of-University-Performance-by-Stakeholders-Policy.pdf +3 -0
- documents/G009-Employee-Separation-Policy-and-Procedure-V1-14-02-2023.pdf +3 -0
- documents/G023-Policy-and-Procedure-for-Flexible-Working-Hours-V1-12-11-21.pdf +3 -0
- documents/G024-Policy-and-Procedure-for-Engaging-Interns.pdf +3 -0
- documents/G025-Policy-Against-Drug-and-Tobacco-Abuse-at-SSUET-12-08-2021-min (1).pdf +3 -0
- documents/G025-Policy-Against-Drug-and-Tobacco-Abuse-at-SSUET-12-08-2021-min.pdf +3 -0
- documents/G029-Policy-and-Procedures-for-Engaging-Temporary-Teaching-Staff-V2_2.pdf +3 -0
- documents/G03-Policy-for-Students-with-Disabilities-V2-12-08-2021-min.pdf +3 -0
- documents/G033-Onboarding-Staff-Induction-Policy-Procedures-V1-11-01-2023.pdf +3 -0
- documents/G051-Patent-Support-Policy-V1.pdf +3 -0
- documents/G30-Policy-for-Authorization-of-Cellular-Phone-and-Calling-Cards-V1-07-12-21.pdf +3 -0
- documents/Grading-System.pdf +3 -0
- documents/HEC-Refund-Policy-2024.pdf +3 -0
- documents/Members-of-Inquiry-Committee-for-Protection-against-Sexual-Harassment-at-SSUET.pdf +3 -0
.dockerignore
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Never bake secrets or local cruft into the image
|
| 2 |
+
.env
|
| 3 |
+
.git
|
| 4 |
+
.gitignore
|
| 5 |
+
__pycache__/
|
| 6 |
+
*.pyc
|
| 7 |
+
.venv/
|
| 8 |
+
venv/
|
| 9 |
+
*.log
|
.gitattributes
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
*.7z filter=lfs diff=lfs merge=lfs -text
|
| 2 |
+
*.arrow filter=lfs diff=lfs merge=lfs -text
|
| 3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
| 4 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
| 5 |
+
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
| 6 |
+
*.ftz filter=lfs diff=lfs merge=lfs -text
|
| 7 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
| 8 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
| 9 |
+
*.joblib filter=lfs diff=lfs merge=lfs -text
|
| 10 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
| 11 |
+
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
| 12 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
| 13 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
| 14 |
+
*.npy filter=lfs diff=lfs merge=lfs -text
|
| 15 |
+
*.npz filter=lfs diff=lfs merge=lfs -text
|
| 16 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
| 17 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
| 18 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
| 19 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
| 20 |
+
*.pickle filter=lfs diff=lfs merge=lfs -text
|
| 21 |
+
*.pkl filter=lfs diff=lfs merge=lfs -text
|
| 22 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
| 23 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
| 24 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
| 25 |
+
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
| 26 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
| 27 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
| 28 |
+
*.tar filter=lfs diff=lfs merge=lfs -text
|
| 29 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
| 30 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
| 31 |
+
*.wasm filter=lfs diff=lfs merge=lfs -text
|
| 32 |
+
*.xz filter=lfs diff=lfs merge=lfs -text
|
| 33 |
+
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
+
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
+
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
*.pdf filter=lfs diff=lfs merge=lfs -text
|
| 37 |
+
*.png filter=lfs diff=lfs merge=lfs -text
|
| 38 |
+
*.jpeg filter=lfs diff=lfs merge=lfs -text
|
| 39 |
+
*.jpg filter=lfs diff=lfs merge=lfs -text
|
| 40 |
+
*.faiss filter=lfs diff=lfs merge=lfs -text
|
.gitignore
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Secrets — NEVER commit (contains the Supabase service-role key + NVIDIA key)
|
| 2 |
+
.env
|
| 3 |
+
|
| 4 |
+
# Python
|
| 5 |
+
__pycache__/
|
| 6 |
+
*.pyc
|
| 7 |
+
.venv/
|
| 8 |
+
venv/
|
| 9 |
+
*.log
|
| 10 |
+
|
| 11 |
+
# Note: vector_db/, images/ and documents/ ARE committed on purpose so the
|
| 12 |
+
# deployed app ships with the policy index already built.
|
Dockerfile
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Docent AI — container image for free deployment (Hugging Face Spaces / Render / Fly.io)
|
| 2 |
+
FROM python:3.11-slim
|
| 3 |
+
|
| 4 |
+
WORKDIR /app
|
| 5 |
+
|
| 6 |
+
# Install Python dependencies first (better layer caching)
|
| 7 |
+
COPY requirements.txt .
|
| 8 |
+
RUN pip install --no-cache-dir -r requirements.txt
|
| 9 |
+
|
| 10 |
+
# Copy the whole project (includes the pre-built vector_db/ and images/)
|
| 11 |
+
COPY . .
|
| 12 |
+
|
| 13 |
+
# These dirs must exist at startup: StaticFiles mounts images/, and uploads
|
| 14 |
+
# write into documents/ + vector_db/.
|
| 15 |
+
RUN mkdir -p documents images vector_db
|
| 16 |
+
|
| 17 |
+
# Hugging Face Spaces expects the app on port 7860 by default.
|
| 18 |
+
EXPOSE 7860
|
| 19 |
+
|
| 20 |
+
WORKDIR /app/backend
|
| 21 |
+
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]
|
README.md
ADDED
|
@@ -0,0 +1,182 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: Docent AI Policy Chatbot
|
| 3 |
+
emoji: 📚
|
| 4 |
+
colorFrom: green
|
| 5 |
+
colorTo: gray
|
| 6 |
+
sdk: docker
|
| 7 |
+
app_port: 7860
|
| 8 |
+
pinned: false
|
| 9 |
+
---
|
| 10 |
+
|
| 11 |
+
# Docent AI — NVIDIA RAG Policy Chatbot
|
| 12 |
+
|
| 13 |
+
A production-ready Retrieval-Augmented Generation (RAG) chatbot that answers questions strictly from uploaded policy PDFs. Powered by NVIDIA's `llama-3.3-70b-instruct` and LangChain, with Supabase-backed user accounts and persistent chat history.
|
| 14 |
+
|
| 15 |
+
## Features
|
| 16 |
+
|
| 17 |
+
- **User authentication** (Supabase email/password) — each user has their own private chats
|
| 18 |
+
- **Persistent chat history** — conversations are stored in Supabase and reload on login
|
| 19 |
+
- **Conversational memory** — follow-up questions ("what about for managers?") are understood using prior turns via a history-aware retriever
|
| 20 |
+
- Upload one or many PDF documents; they are indexed and **persisted** in a FAISS vector store
|
| 21 |
+
- Answers come **only from the documents** — the LLM is instructed never to hallucinate or use outside knowledge
|
| 22 |
+
- Every answer shows **source file + page number** references (persisted with history)
|
| 23 |
+
- Adding more PDFs at any time merges them into the existing index with no data loss
|
| 24 |
+
|
| 25 |
+
## Project Structure
|
| 26 |
+
|
| 27 |
+
```
|
| 28 |
+
docent-ai-nvidia/
|
| 29 |
+
├── .env # NVIDIA API key + Supabase keys
|
| 30 |
+
├── supabase_schema.sql # Run once in the Supabase SQL editor
|
| 31 |
+
├── requirements.txt
|
| 32 |
+
├── documents/ # Uploaded PDFs are stored here
|
| 33 |
+
├── vector_db/ # Persisted FAISS index
|
| 34 |
+
├── backend/
|
| 35 |
+
│ ├── main.py # FastAPI app + auth + history endpoints
|
| 36 |
+
│ ├── rag.py # History-aware RAG engine
|
| 37 |
+
│ ├── db.py # Supabase auth + chat persistence
|
| 38 |
+
│ └── ingest.py # PDF ingestion + FAISS management
|
| 39 |
+
└── frontend/
|
| 40 |
+
├── index.html
|
| 41 |
+
├── style.css
|
| 42 |
+
└── script.js
|
| 43 |
+
```
|
| 44 |
+
|
| 45 |
+
## Setup
|
| 46 |
+
|
| 47 |
+
### 1. Install dependencies
|
| 48 |
+
|
| 49 |
+
```powershell
|
| 50 |
+
cd c:\docent-ai-nvidia
|
| 51 |
+
pip install -r requirements.txt
|
| 52 |
+
```
|
| 53 |
+
|
| 54 |
+
### 2. Verify `.env`
|
| 55 |
+
|
| 56 |
+
The `.env` file should contain:
|
| 57 |
+
|
| 58 |
+
```
|
| 59 |
+
NVIDIA_API_KEY=nvapi-...
|
| 60 |
+
SUPABASE_URL=https://<project-ref>.supabase.co
|
| 61 |
+
SUPABASE_ANON_KEY=eyJ...
|
| 62 |
+
SUPABASE_SERVICE_ROLE_KEY=eyJ...
|
| 63 |
+
```
|
| 64 |
+
|
| 65 |
+
### 3. Set up Supabase (one time)
|
| 66 |
+
|
| 67 |
+
1. Open your project → **SQL Editor** → **New query**.
|
| 68 |
+
2. Paste the contents of `supabase_schema.sql` and click **Run**. This creates the
|
| 69 |
+
`chat_sessions` and `messages` tables with row-level security.
|
| 70 |
+
3. (Recommended for quick testing) Go to **Authentication → Providers → Email** and
|
| 71 |
+
turn **off** "Confirm email" so new sign-ups can log in immediately. Leave it on
|
| 72 |
+
in production and users will receive a confirmation email.
|
| 73 |
+
|
| 74 |
+
### 4. Run the server
|
| 75 |
+
|
| 76 |
+
From the project root:
|
| 77 |
+
|
| 78 |
+
```powershell
|
| 79 |
+
cd c:\docent-ai-nvidia
|
| 80 |
+
run
|
| 81 |
+
```
|
| 82 |
+
|
| 83 |
+
Or double-click `run.bat`. Then open [http://localhost:8000](http://localhost:8000).
|
| 84 |
+
|
| 85 |
+
### 5. Open the chatbot
|
| 86 |
+
|
| 87 |
+
Go to [http://localhost:8000](http://localhost:8000) in your browser.
|
| 88 |
+
|
| 89 |
+
## Deploy for free (Hugging Face Spaces)
|
| 90 |
+
|
| 91 |
+
The repo ships a `Dockerfile` and the pre-built `vector_db/`, so the deployed app
|
| 92 |
+
works out of the box. Hugging Face Spaces' free tier gives 16 GB RAM (enough for the
|
| 93 |
+
heavy `faiss`/`langchain` deps) with no credit card.
|
| 94 |
+
|
| 95 |
+
1. Create a free account at [huggingface.co](https://huggingface.co).
|
| 96 |
+
2. **New → Space**: pick a name, **SDK = Docker** (Blank template), visibility Public.
|
| 97 |
+
3. Push this project to the Space's git repo (or upload the files), e.g.:
|
| 98 |
+
|
| 99 |
+
```bash
|
| 100 |
+
git init
|
| 101 |
+
git add .
|
| 102 |
+
git commit -m "Docent AI"
|
| 103 |
+
git remote add origin https://huggingface.co/spaces/<user>/<space-name>
|
| 104 |
+
git push origin main
|
| 105 |
+
```
|
| 106 |
+
|
| 107 |
+
4. In the Space → **Settings → Variables and secrets**, add these **secrets**:
|
| 108 |
+
`NVIDIA_API_KEY`, `SUPABASE_URL`, `SUPABASE_ANON_KEY`, `SUPABASE_SERVICE_ROLE_KEY`.
|
| 109 |
+
5. Run `supabase_schema.sql` in the Supabase SQL Editor and turn **off** "Confirm email".
|
| 110 |
+
6. The Space builds and serves at `https://<user>-<space-name>.hf.space`.
|
| 111 |
+
|
| 112 |
+
> `.env` is gitignored and never deployed — all keys come from Space secrets.
|
| 113 |
+
> Runtime PDF uploads are ephemeral on free tiers (they reset on rebuild); the
|
| 114 |
+
> committed `vector_db/` is what ships. Re-ingest locally and push to update it.
|
| 115 |
+
|
| 116 |
+
## Usage
|
| 117 |
+
|
| 118 |
+
1. **Upload PDFs** — drag-and-drop or click "Drop PDFs here" in the sidebar and click **Upload**.
|
| 119 |
+
2. **Ask questions** — type in the chat box and press Enter.
|
| 120 |
+
3. **See sources** — each answer shows which document and page the information came from.
|
| 121 |
+
4. **Add more documents** — upload additional PDFs at any time; they are merged into the existing index.
|
| 122 |
+
|
| 123 |
+
## API Reference
|
| 124 |
+
|
| 125 |
+
All routes except `/` and `/config` require a Supabase access token in the
|
| 126 |
+
`Authorization: Bearer <token>` header.
|
| 127 |
+
|
| 128 |
+
| Method | Path | Description |
|
| 129 |
+
|--------|------|-------------|
|
| 130 |
+
| `GET` | `/` | Serves the chat UI |
|
| 131 |
+
| `GET` | `/config` | Public Supabase URL + anon key for the frontend |
|
| 132 |
+
| `POST` | `/upload` | Upload one or more PDF files (auth) |
|
| 133 |
+
| `GET` | `/documents` | List all ingested document filenames (auth) |
|
| 134 |
+
| `GET` | `/sessions` | List the user's conversations (auth) |
|
| 135 |
+
| `POST` | `/sessions` | Create a new conversation (auth) |
|
| 136 |
+
| `GET` | `/sessions/{id}/messages` | Load a conversation's messages (auth) |
|
| 137 |
+
| `DELETE` | `/sessions/{id}` | Delete a conversation (auth) |
|
| 138 |
+
| `POST` | `/chat` | Send a question, get an answer + sources (auth) |
|
| 139 |
+
|
| 140 |
+
### `/chat` request body
|
| 141 |
+
|
| 142 |
+
```json
|
| 143 |
+
{
|
| 144 |
+
"question": "What is the leave policy?",
|
| 145 |
+
"session_id": "optional-existing-session-uuid"
|
| 146 |
+
}
|
| 147 |
+
```
|
| 148 |
+
|
| 149 |
+
If `session_id` is omitted, a new conversation is created automatically.
|
| 150 |
+
|
| 151 |
+
### `/chat` response
|
| 152 |
+
|
| 153 |
+
```json
|
| 154 |
+
{
|
| 155 |
+
"answer": "According to the HR Policy document, employees are entitled to ...",
|
| 156 |
+
"sources": [
|
| 157 |
+
{ "file": "hr-policy.pdf", "page": 4, "image_urls": [] }
|
| 158 |
+
],
|
| 159 |
+
"session_id": "…",
|
| 160 |
+
"title": "What is the leave policy?"
|
| 161 |
+
}
|
| 162 |
+
```
|
| 163 |
+
|
| 164 |
+
## How conversational memory works
|
| 165 |
+
|
| 166 |
+
On each `/chat` call the backend loads the recent turns of that conversation from
|
| 167 |
+
Supabase and (a) rewrites the follow-up into a standalone question for retrieval,
|
| 168 |
+
and (b) passes the history to the LLM so references like "it" / "that policy"
|
| 169 |
+
resolve correctly. The strict "answer only from the documents" rule still applies.
|
| 170 |
+
|
| 171 |
+
## Tech Stack
|
| 172 |
+
|
| 173 |
+
| Component | Library |
|
| 174 |
+
|-----------|---------|
|
| 175 |
+
| LLM | `langchain-nvidia-ai-endpoints` — `ChatNVIDIA` (`meta/llama-3.3-70b-instruct`) |
|
| 176 |
+
| Embeddings | `NVIDIAEmbeddings` (`nvidia/nv-embedqa-e5-v5`) |
|
| 177 |
+
| Vector store | `faiss-cpu` (persisted to disk) |
|
| 178 |
+
| Auth & history | Supabase (Postgres + Auth) |
|
| 179 |
+
| PDF loading | `pypdf` via `PyPDFLoader` |
|
| 180 |
+
| Framework | `langchain` |
|
| 181 |
+
| Backend | `fastapi` + `uvicorn` |
|
| 182 |
+
| Frontend | HTML + CSS + Vanilla JS + `@supabase/supabase-js` |
|
backend/Untitled
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
python ingest_all.py
|
backend/db.py
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Supabase integration: token verification + chat-history persistence.
|
| 3 |
+
|
| 4 |
+
All database access here uses the *service-role* key, which bypasses Row Level
|
| 5 |
+
Security. Because of that, every query is explicitly scoped to the
|
| 6 |
+
authenticated user's id — never trust a client-supplied user id.
|
| 7 |
+
"""
|
| 8 |
+
import os
|
| 9 |
+
from pathlib import Path
|
| 10 |
+
from datetime import datetime, timezone
|
| 11 |
+
|
| 12 |
+
from dotenv import load_dotenv
|
| 13 |
+
from supabase import create_client, Client
|
| 14 |
+
|
| 15 |
+
load_dotenv(Path(__file__).parent.parent / ".env")
|
| 16 |
+
|
| 17 |
+
SUPABASE_URL = os.environ.get("SUPABASE_URL", "").rstrip("/")
|
| 18 |
+
SUPABASE_ANON_KEY = os.environ.get("SUPABASE_ANON_KEY", "")
|
| 19 |
+
SERVICE_ROLE_KEY = os.environ.get("SUPABASE_SERVICE_ROLE_KEY", "")
|
| 20 |
+
|
| 21 |
+
_admin: Client | None = None
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
def is_configured() -> bool:
|
| 25 |
+
return bool(SUPABASE_URL and SERVICE_ROLE_KEY and SUPABASE_ANON_KEY)
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
def admin() -> Client:
|
| 29 |
+
"""Lazily create and reuse a single service-role client."""
|
| 30 |
+
global _admin
|
| 31 |
+
if _admin is None:
|
| 32 |
+
if not is_configured():
|
| 33 |
+
raise RuntimeError(
|
| 34 |
+
"Supabase is not configured. Set SUPABASE_URL, SUPABASE_ANON_KEY "
|
| 35 |
+
"and SUPABASE_SERVICE_ROLE_KEY in your .env file."
|
| 36 |
+
)
|
| 37 |
+
_admin = create_client(SUPABASE_URL, SERVICE_ROLE_KEY)
|
| 38 |
+
return _admin
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
def _now() -> str:
|
| 42 |
+
return datetime.now(timezone.utc).isoformat()
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
# ── Auth ────────────────────────────────────────────────────────────────────
|
| 46 |
+
|
| 47 |
+
def verify_token(token: str):
|
| 48 |
+
"""Validate a Supabase access token and return the user, or None."""
|
| 49 |
+
try:
|
| 50 |
+
res = admin().auth.get_user(token)
|
| 51 |
+
return res.user if res else None
|
| 52 |
+
except Exception:
|
| 53 |
+
return None
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
# ── Sessions ──────────────────────────────────────────────────────────────────
|
| 57 |
+
|
| 58 |
+
def create_session(user_id: str, title: str) -> dict:
|
| 59 |
+
res = (
|
| 60 |
+
admin()
|
| 61 |
+
.table("chat_sessions")
|
| 62 |
+
.insert({"user_id": user_id, "title": title[:80] or "New chat"})
|
| 63 |
+
.execute()
|
| 64 |
+
)
|
| 65 |
+
return res.data[0]
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
def list_sessions(user_id: str) -> list[dict]:
|
| 69 |
+
res = (
|
| 70 |
+
admin()
|
| 71 |
+
.table("chat_sessions")
|
| 72 |
+
.select("id, title, created_at, updated_at")
|
| 73 |
+
.eq("user_id", user_id)
|
| 74 |
+
.order("updated_at", desc=True)
|
| 75 |
+
.execute()
|
| 76 |
+
)
|
| 77 |
+
return res.data or []
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
def get_session(session_id: str, user_id: str) -> dict | None:
|
| 81 |
+
res = (
|
| 82 |
+
admin()
|
| 83 |
+
.table("chat_sessions")
|
| 84 |
+
.select("*")
|
| 85 |
+
.eq("id", session_id)
|
| 86 |
+
.eq("user_id", user_id)
|
| 87 |
+
.limit(1)
|
| 88 |
+
.execute()
|
| 89 |
+
)
|
| 90 |
+
return res.data[0] if res.data else None
|
| 91 |
+
|
| 92 |
+
|
| 93 |
+
def touch_session(session_id: str) -> None:
|
| 94 |
+
admin().table("chat_sessions").update({"updated_at": _now()}).eq("id", session_id).execute()
|
| 95 |
+
|
| 96 |
+
|
| 97 |
+
def rename_session(session_id: str, user_id: str, title: str) -> None:
|
| 98 |
+
admin().table("chat_sessions").update({"title": title[:80]}).eq("id", session_id).eq("user_id", user_id).execute()
|
| 99 |
+
|
| 100 |
+
|
| 101 |
+
def delete_session(session_id: str, user_id: str) -> None:
|
| 102 |
+
# messages cascade-delete via the foreign key
|
| 103 |
+
admin().table("chat_sessions").delete().eq("id", session_id).eq("user_id", user_id).execute()
|
| 104 |
+
|
| 105 |
+
|
| 106 |
+
# ── Messages ──────────────────────────────────────────────────────────────────
|
| 107 |
+
|
| 108 |
+
def add_message(session_id: str, role: str, content: str, sources: list | None = None) -> dict:
|
| 109 |
+
res = (
|
| 110 |
+
admin()
|
| 111 |
+
.table("messages")
|
| 112 |
+
.insert({
|
| 113 |
+
"session_id": session_id,
|
| 114 |
+
"role": role,
|
| 115 |
+
"content": content,
|
| 116 |
+
"sources": sources or [],
|
| 117 |
+
})
|
| 118 |
+
.execute()
|
| 119 |
+
)
|
| 120 |
+
return res.data[0]
|
| 121 |
+
|
| 122 |
+
|
| 123 |
+
def list_messages(session_id: str) -> list[dict]:
|
| 124 |
+
res = (
|
| 125 |
+
admin()
|
| 126 |
+
.table("messages")
|
| 127 |
+
.select("role, content, sources, created_at")
|
| 128 |
+
.eq("session_id", session_id)
|
| 129 |
+
.order("created_at")
|
| 130 |
+
.execute()
|
| 131 |
+
)
|
| 132 |
+
return res.data or []
|
backend/ingest.py
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import json
|
| 3 |
+
from pathlib import Path
|
| 4 |
+
from dotenv import load_dotenv
|
| 5 |
+
from langchain_community.document_loaders import PyPDFLoader
|
| 6 |
+
from langchain_text_splitters import RecursiveCharacterTextSplitter
|
| 7 |
+
from langchain_nvidia_ai_endpoints import NVIDIAEmbeddings
|
| 8 |
+
from langchain_community.vectorstores import FAISS
|
| 9 |
+
|
| 10 |
+
load_dotenv(Path(__file__).parent.parent / ".env")
|
| 11 |
+
|
| 12 |
+
VECTOR_DB_PATH = Path(__file__).parent.parent / "vector_db"
|
| 13 |
+
DOCUMENTS_PATH = Path(__file__).parent.parent / "documents"
|
| 14 |
+
IMAGES_PATH = Path(__file__).parent.parent / "images"
|
| 15 |
+
|
| 16 |
+
CHUNK_SIZE = 1000
|
| 17 |
+
CHUNK_OVERLAP = 200
|
| 18 |
+
MIN_IMAGE_DIM = 80 # pixels — skip tiny icons / decorative elements
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
def get_embeddings() -> NVIDIAEmbeddings:
|
| 22 |
+
return NVIDIAEmbeddings(
|
| 23 |
+
model="nvidia/nv-embedqa-e5-v5",
|
| 24 |
+
api_key=os.environ["NVIDIA_API_KEY"],
|
| 25 |
+
truncate="END",
|
| 26 |
+
)
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
# ── Image extraction ──────────────────────────────────────────────────────────
|
| 30 |
+
|
| 31 |
+
def extract_images_from_pdf(pdf_path: str) -> dict[int, list[str]]:
|
| 32 |
+
"""
|
| 33 |
+
Extract images from every page of the PDF using PyMuPDF.
|
| 34 |
+
Returns a dict mapping page_number (0-based) → [image_filename, ...]
|
| 35 |
+
Only images larger than MIN_IMAGE_DIM × MIN_IMAGE_DIM are kept.
|
| 36 |
+
"""
|
| 37 |
+
try:
|
| 38 |
+
import fitz # PyMuPDF
|
| 39 |
+
except ImportError:
|
| 40 |
+
return {}
|
| 41 |
+
|
| 42 |
+
pdf_name = Path(pdf_path).stem
|
| 43 |
+
page_images: dict[int, list[str]] = {}
|
| 44 |
+
doc = fitz.open(pdf_path)
|
| 45 |
+
|
| 46 |
+
for page_num in range(len(doc)):
|
| 47 |
+
page = doc[page_num]
|
| 48 |
+
img_list = page.get_images(full=True)
|
| 49 |
+
saved = []
|
| 50 |
+
|
| 51 |
+
for img_idx, img_info in enumerate(img_list):
|
| 52 |
+
xref = img_info[0]
|
| 53 |
+
try:
|
| 54 |
+
base = doc.extract_image(xref)
|
| 55 |
+
except Exception:
|
| 56 |
+
continue
|
| 57 |
+
|
| 58 |
+
w, h = base.get("width", 0), base.get("height", 0)
|
| 59 |
+
if w < MIN_IMAGE_DIM or h < MIN_IMAGE_DIM:
|
| 60 |
+
continue
|
| 61 |
+
|
| 62 |
+
ext = base.get("ext", "png")
|
| 63 |
+
filename = f"{pdf_name}_p{page_num + 1}_i{img_idx + 1}.{ext}"
|
| 64 |
+
dest = IMAGES_PATH / filename
|
| 65 |
+
|
| 66 |
+
if not dest.exists():
|
| 67 |
+
dest.write_bytes(base["image"])
|
| 68 |
+
|
| 69 |
+
saved.append(filename)
|
| 70 |
+
|
| 71 |
+
if saved:
|
| 72 |
+
page_images[page_num] = saved
|
| 73 |
+
|
| 74 |
+
doc.close()
|
| 75 |
+
return page_images
|
| 76 |
+
|
| 77 |
+
|
| 78 |
+
# ── Text ingestion ────────────────────────────────────────────────────────────
|
| 79 |
+
|
| 80 |
+
def load_and_split_pdf(pdf_path: str, page_images: dict[int, list[str]]) -> list:
|
| 81 |
+
loader = PyPDFLoader(pdf_path)
|
| 82 |
+
pages = loader.load()
|
| 83 |
+
|
| 84 |
+
splitter = RecursiveCharacterTextSplitter(
|
| 85 |
+
chunk_size=CHUNK_SIZE,
|
| 86 |
+
chunk_overlap=CHUNK_OVERLAP,
|
| 87 |
+
separators=["\n\n", "\n", ".", " ", ""],
|
| 88 |
+
)
|
| 89 |
+
chunks = splitter.split_documents(pages)
|
| 90 |
+
|
| 91 |
+
for chunk in chunks:
|
| 92 |
+
page_num = chunk.metadata.get("page", 0) # PyPDFLoader uses 0-based page
|
| 93 |
+
chunk.metadata["source"] = Path(pdf_path).name
|
| 94 |
+
# Attach image filenames for this page (stored as JSON string)
|
| 95 |
+
imgs = page_images.get(page_num, [])
|
| 96 |
+
chunk.metadata["images"] = json.dumps(imgs)
|
| 97 |
+
|
| 98 |
+
return chunks
|
| 99 |
+
|
| 100 |
+
|
| 101 |
+
def ingest_pdf(pdf_path: str) -> int:
|
| 102 |
+
"""
|
| 103 |
+
Extract images, embed text chunks, merge into persisted FAISS index.
|
| 104 |
+
Returns the number of text chunks added.
|
| 105 |
+
"""
|
| 106 |
+
page_images = extract_images_from_pdf(pdf_path)
|
| 107 |
+
chunks = load_and_split_pdf(pdf_path, page_images)
|
| 108 |
+
|
| 109 |
+
if not chunks:
|
| 110 |
+
return 0
|
| 111 |
+
|
| 112 |
+
embeddings = get_embeddings()
|
| 113 |
+
index_file = VECTOR_DB_PATH / "index.faiss"
|
| 114 |
+
|
| 115 |
+
if index_file.exists():
|
| 116 |
+
store = FAISS.load_local(
|
| 117 |
+
str(VECTOR_DB_PATH),
|
| 118 |
+
embeddings,
|
| 119 |
+
allow_dangerous_deserialization=True,
|
| 120 |
+
)
|
| 121 |
+
store.add_documents(chunks)
|
| 122 |
+
else:
|
| 123 |
+
store = FAISS.from_documents(chunks, embeddings)
|
| 124 |
+
|
| 125 |
+
store.save_local(str(VECTOR_DB_PATH))
|
| 126 |
+
return len(chunks)
|
| 127 |
+
|
| 128 |
+
|
| 129 |
+
def load_vector_store() -> FAISS | None:
|
| 130 |
+
"""Load the persisted FAISS index. Returns None if no index exists yet."""
|
| 131 |
+
index_file = VECTOR_DB_PATH / "index.faiss"
|
| 132 |
+
if not index_file.exists():
|
| 133 |
+
return None
|
| 134 |
+
embeddings = get_embeddings()
|
| 135 |
+
return FAISS.load_local(
|
| 136 |
+
str(VECTOR_DB_PATH),
|
| 137 |
+
embeddings,
|
| 138 |
+
allow_dangerous_deserialization=True,
|
| 139 |
+
)
|
backend/main.py
ADDED
|
@@ -0,0 +1,200 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import shutil
|
| 2 |
+
from pathlib import Path
|
| 3 |
+
from contextlib import asynccontextmanager
|
| 4 |
+
|
| 5 |
+
from fastapi import FastAPI, UploadFile, File, HTTPException, Depends, Header
|
| 6 |
+
from fastapi.staticfiles import StaticFiles
|
| 7 |
+
from fastapi.responses import FileResponse
|
| 8 |
+
from pydantic import BaseModel
|
| 9 |
+
from dotenv import load_dotenv
|
| 10 |
+
|
| 11 |
+
from ingest import ingest_pdf, load_vector_store, DOCUMENTS_PATH, IMAGES_PATH
|
| 12 |
+
from rag import build_engine
|
| 13 |
+
import db
|
| 14 |
+
|
| 15 |
+
load_dotenv(Path(__file__).parent.parent / ".env")
|
| 16 |
+
|
| 17 |
+
FRONTEND_PATH = Path(__file__).parent.parent / "frontend"
|
| 18 |
+
|
| 19 |
+
# Global RAG state loaded once at startup and refreshed after uploads
|
| 20 |
+
_engine = None
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
def refresh_rag():
|
| 24 |
+
global _engine
|
| 25 |
+
store = load_vector_store()
|
| 26 |
+
_engine = build_engine(store) if store is not None else None
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
@asynccontextmanager
|
| 30 |
+
async def lifespan(app: FastAPI):
|
| 31 |
+
refresh_rag()
|
| 32 |
+
yield
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
app = FastAPI(title="Docent AI — Policy Chatbot", lifespan=lifespan)
|
| 36 |
+
|
| 37 |
+
# Serve frontend static files and extracted images
|
| 38 |
+
app.mount("/static", StaticFiles(directory=str(FRONTEND_PATH)), name="static")
|
| 39 |
+
app.mount("/images", StaticFiles(directory=str(IMAGES_PATH)), name="images")
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
# ---------- Models ----------
|
| 43 |
+
|
| 44 |
+
class ChatRequest(BaseModel):
|
| 45 |
+
question: str
|
| 46 |
+
session_id: str | None = None
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
class ChatResponse(BaseModel):
|
| 50 |
+
answer: str
|
| 51 |
+
sources: list[dict]
|
| 52 |
+
session_id: str
|
| 53 |
+
title: str
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
# ---------- Auth dependency ----------
|
| 57 |
+
|
| 58 |
+
async def get_current_user(authorization: str | None = Header(default=None)):
|
| 59 |
+
if not authorization or not authorization.lower().startswith("bearer "):
|
| 60 |
+
raise HTTPException(status_code=401, detail="Not authenticated.")
|
| 61 |
+
token = authorization.split(" ", 1)[1].strip()
|
| 62 |
+
user = db.verify_token(token)
|
| 63 |
+
if user is None:
|
| 64 |
+
raise HTTPException(status_code=401, detail="Invalid or expired session.")
|
| 65 |
+
return user
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
def _attach_image_urls(sources: list[dict]) -> list[dict]:
|
| 69 |
+
for src in sources:
|
| 70 |
+
src["image_urls"] = [f"/images/{fname}" for fname in src.get("images", [])]
|
| 71 |
+
return sources
|
| 72 |
+
|
| 73 |
+
|
| 74 |
+
# ---------- Routes ----------
|
| 75 |
+
|
| 76 |
+
@app.get("/")
|
| 77 |
+
async def root():
|
| 78 |
+
return FileResponse(str(FRONTEND_PATH / "index.html"))
|
| 79 |
+
|
| 80 |
+
|
| 81 |
+
@app.get("/config")
|
| 82 |
+
async def config():
|
| 83 |
+
"""Public config the frontend needs to initialise Supabase auth."""
|
| 84 |
+
return {
|
| 85 |
+
"supabaseUrl": db.SUPABASE_URL,
|
| 86 |
+
"supabaseAnonKey": db.SUPABASE_ANON_KEY,
|
| 87 |
+
"configured": db.is_configured(),
|
| 88 |
+
}
|
| 89 |
+
|
| 90 |
+
|
| 91 |
+
@app.post("/upload")
|
| 92 |
+
async def upload_documents(
|
| 93 |
+
files: list[UploadFile] = File(...),
|
| 94 |
+
user=Depends(get_current_user),
|
| 95 |
+
):
|
| 96 |
+
"""Accept one or more PDF files, ingest them into the FAISS store."""
|
| 97 |
+
if not files:
|
| 98 |
+
raise HTTPException(status_code=400, detail="No files provided.")
|
| 99 |
+
|
| 100 |
+
results = []
|
| 101 |
+
for upload in files:
|
| 102 |
+
if not upload.filename.lower().endswith(".pdf"):
|
| 103 |
+
results.append({"file": upload.filename, "status": "skipped — not a PDF"})
|
| 104 |
+
continue
|
| 105 |
+
|
| 106 |
+
dest = DOCUMENTS_PATH / upload.filename
|
| 107 |
+
with open(dest, "wb") as f:
|
| 108 |
+
shutil.copyfileobj(upload.file, f)
|
| 109 |
+
|
| 110 |
+
try:
|
| 111 |
+
chunks = ingest_pdf(str(dest))
|
| 112 |
+
results.append({"file": upload.filename, "status": "ingested", "chunks": chunks})
|
| 113 |
+
except Exception as e:
|
| 114 |
+
results.append({"file": upload.filename, "status": f"error: {e}"})
|
| 115 |
+
|
| 116 |
+
refresh_rag()
|
| 117 |
+
return {"results": results}
|
| 118 |
+
|
| 119 |
+
|
| 120 |
+
@app.get("/documents")
|
| 121 |
+
async def list_documents(user=Depends(get_current_user)):
|
| 122 |
+
"""List all PDF filenames stored in the documents folder."""
|
| 123 |
+
pdfs = sorted(
|
| 124 |
+
p.name for p in DOCUMENTS_PATH.iterdir() if p.suffix.lower() == ".pdf"
|
| 125 |
+
)
|
| 126 |
+
return {"documents": pdfs}
|
| 127 |
+
|
| 128 |
+
|
| 129 |
+
# ---------- Sessions / history ----------
|
| 130 |
+
|
| 131 |
+
@app.get("/sessions")
|
| 132 |
+
async def get_sessions(user=Depends(get_current_user)):
|
| 133 |
+
return {"sessions": db.list_sessions(user.id)}
|
| 134 |
+
|
| 135 |
+
|
| 136 |
+
@app.post("/sessions")
|
| 137 |
+
async def new_session(user=Depends(get_current_user)):
|
| 138 |
+
sess = db.create_session(user.id, "New chat")
|
| 139 |
+
return sess
|
| 140 |
+
|
| 141 |
+
|
| 142 |
+
@app.get("/sessions/{session_id}/messages")
|
| 143 |
+
async def get_session_messages(session_id: str, user=Depends(get_current_user)):
|
| 144 |
+
if db.get_session(session_id, user.id) is None:
|
| 145 |
+
raise HTTPException(status_code=404, detail="Conversation not found.")
|
| 146 |
+
messages = db.list_messages(session_id)
|
| 147 |
+
for m in messages:
|
| 148 |
+
if m.get("sources"):
|
| 149 |
+
_attach_image_urls(m["sources"])
|
| 150 |
+
return {"messages": messages}
|
| 151 |
+
|
| 152 |
+
|
| 153 |
+
@app.delete("/sessions/{session_id}")
|
| 154 |
+
async def remove_session(session_id: str, user=Depends(get_current_user)):
|
| 155 |
+
db.delete_session(session_id, user.id)
|
| 156 |
+
return {"ok": True}
|
| 157 |
+
|
| 158 |
+
|
| 159 |
+
@app.post("/chat", response_model=ChatResponse)
|
| 160 |
+
async def chat(req: ChatRequest, user=Depends(get_current_user)):
|
| 161 |
+
if not req.question.strip():
|
| 162 |
+
raise HTTPException(status_code=400, detail="Question cannot be empty.")
|
| 163 |
+
|
| 164 |
+
if _engine is None:
|
| 165 |
+
raise HTTPException(
|
| 166 |
+
status_code=503,
|
| 167 |
+
detail="No documents have been ingested yet. Please upload policy PDFs first.",
|
| 168 |
+
)
|
| 169 |
+
|
| 170 |
+
# Resolve or create the conversation
|
| 171 |
+
if req.session_id:
|
| 172 |
+
session = db.get_session(req.session_id, user.id)
|
| 173 |
+
if session is None:
|
| 174 |
+
raise HTTPException(status_code=404, detail="Conversation not found.")
|
| 175 |
+
else:
|
| 176 |
+
title = req.question.strip()[:60]
|
| 177 |
+
session = db.create_session(user.id, title)
|
| 178 |
+
|
| 179 |
+
session_id = session["id"]
|
| 180 |
+
|
| 181 |
+
# Load prior turns BEFORE storing the new question, to use as memory
|
| 182 |
+
history = db.list_messages(session_id)
|
| 183 |
+
|
| 184 |
+
db.add_message(session_id, "user", req.question)
|
| 185 |
+
|
| 186 |
+
try:
|
| 187 |
+
answer, sources = _engine.answer(req.question, history)
|
| 188 |
+
except Exception as e:
|
| 189 |
+
raise HTTPException(status_code=500, detail=f"LLM error: {e}")
|
| 190 |
+
|
| 191 |
+
_attach_image_urls(sources)
|
| 192 |
+
db.add_message(session_id, "assistant", answer, sources)
|
| 193 |
+
db.touch_session(session_id)
|
| 194 |
+
|
| 195 |
+
return ChatResponse(
|
| 196 |
+
answer=answer,
|
| 197 |
+
sources=sources,
|
| 198 |
+
session_id=session_id,
|
| 199 |
+
title=session["title"],
|
| 200 |
+
)
|
backend/rag.py
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import json
|
| 3 |
+
from pathlib import Path
|
| 4 |
+
from dotenv import load_dotenv
|
| 5 |
+
from langchain_nvidia_ai_endpoints import ChatNVIDIA
|
| 6 |
+
from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder
|
| 7 |
+
from langchain_core.messages import HumanMessage, AIMessage
|
| 8 |
+
from langchain_core.output_parsers import StrOutputParser
|
| 9 |
+
from langchain_community.vectorstores import FAISS
|
| 10 |
+
|
| 11 |
+
load_dotenv(Path(__file__).parent.parent / ".env")
|
| 12 |
+
|
| 13 |
+
# A larger instruction-tuned model gives noticeably better policy reasoning and
|
| 14 |
+
# more reliable "I don't know" refusals than the 8B model. Free on NVIDIA NIM.
|
| 15 |
+
CHAT_MODEL = os.environ.get("CHAT_MODEL", "meta/llama-3.3-70b-instruct")
|
| 16 |
+
RETRIEVE_K = 5
|
| 17 |
+
HISTORY_TURNS = 6 # how many prior messages to feed back as conversation memory
|
| 18 |
+
|
| 19 |
+
SYSTEM_PROMPT = """You are a strict policy assistant. Your ONLY job is to answer questions \
|
| 20 |
+
using the document excerpts provided below as context.
|
| 21 |
+
|
| 22 |
+
Rules you must NEVER break:
|
| 23 |
+
1. Answer ONLY using information found in the context below.
|
| 24 |
+
2. Do NOT use any outside knowledge, assumptions, or information not present in the context.
|
| 25 |
+
3. Do NOT make up, infer, or guess any information that is not explicitly stated in the context.
|
| 26 |
+
4. If the answer is not present in the context, respond with exactly:
|
| 27 |
+
"I don't have information about that in the provided documents."
|
| 28 |
+
5. When answering, be concise and quote or closely paraphrase the relevant policy text.
|
| 29 |
+
6. Do not greet the user or add filler phrases.
|
| 30 |
+
7. The conversation history is provided only to resolve references (e.g. "it", "that policy").
|
| 31 |
+
You must STILL answer the latest question solely from the context excerpts below.
|
| 32 |
+
|
| 33 |
+
Context from documents:
|
| 34 |
+
{context}
|
| 35 |
+
"""
|
| 36 |
+
|
| 37 |
+
# Used to turn a follow-up question into a standalone one for retrieval.
|
| 38 |
+
CONDENSE_PROMPT = """Given the conversation history and a follow-up question, rewrite the \
|
| 39 |
+
follow-up as a single standalone question that can be understood without the history.
|
| 40 |
+
Only output the rewritten question — no preamble, no explanation.
|
| 41 |
+
If the question is already standalone, return it unchanged."""
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
def format_docs(docs: list) -> str:
|
| 45 |
+
parts = []
|
| 46 |
+
for i, doc in enumerate(docs, 1):
|
| 47 |
+
source = doc.metadata.get("source", "unknown")
|
| 48 |
+
page = doc.metadata.get("page", "?")
|
| 49 |
+
parts.append(f"[Excerpt {i} | File: {source} | Page: {page}]\n{doc.page_content}")
|
| 50 |
+
return "\n\n---\n\n".join(parts)
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
def _to_lc_messages(history: list[dict]) -> list:
|
| 54 |
+
"""Convert stored {role, content} dicts into LangChain message objects."""
|
| 55 |
+
msgs = []
|
| 56 |
+
for h in history[-HISTORY_TURNS:]:
|
| 57 |
+
if h.get("role") == "user":
|
| 58 |
+
msgs.append(HumanMessage(content=h.get("content", "")))
|
| 59 |
+
elif h.get("role") == "assistant":
|
| 60 |
+
msgs.append(AIMessage(content=h.get("content", "")))
|
| 61 |
+
return msgs
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
def _sources_from_docs(docs: list) -> list[dict]:
|
| 65 |
+
seen = set()
|
| 66 |
+
sources = []
|
| 67 |
+
for doc in docs:
|
| 68 |
+
source = doc.metadata.get("source", "unknown")
|
| 69 |
+
page = doc.metadata.get("page", "?")
|
| 70 |
+
key = (source, page)
|
| 71 |
+
if key in seen:
|
| 72 |
+
continue
|
| 73 |
+
seen.add(key)
|
| 74 |
+
raw_imgs = doc.metadata.get("images", "[]")
|
| 75 |
+
try:
|
| 76 |
+
images = json.loads(raw_imgs) if isinstance(raw_imgs, str) else raw_imgs
|
| 77 |
+
except Exception:
|
| 78 |
+
images = []
|
| 79 |
+
sources.append({"file": source, "page": page, "images": images})
|
| 80 |
+
return sources
|
| 81 |
+
|
| 82 |
+
|
| 83 |
+
class RagEngine:
|
| 84 |
+
"""Holds the retriever + LLM and answers questions with optional memory."""
|
| 85 |
+
|
| 86 |
+
def __init__(self, vector_store: FAISS):
|
| 87 |
+
self.retriever = vector_store.as_retriever(
|
| 88 |
+
search_type="similarity",
|
| 89 |
+
search_kwargs={"k": RETRIEVE_K},
|
| 90 |
+
)
|
| 91 |
+
self.llm = ChatNVIDIA(
|
| 92 |
+
model=CHAT_MODEL,
|
| 93 |
+
api_key=os.environ["NVIDIA_API_KEY"],
|
| 94 |
+
temperature=0.0,
|
| 95 |
+
max_tokens=1024,
|
| 96 |
+
)
|
| 97 |
+
|
| 98 |
+
self.answer_prompt = ChatPromptTemplate.from_messages([
|
| 99 |
+
("system", SYSTEM_PROMPT),
|
| 100 |
+
MessagesPlaceholder("history"),
|
| 101 |
+
("human", "{question}"),
|
| 102 |
+
])
|
| 103 |
+
|
| 104 |
+
self.condense_prompt = ChatPromptTemplate.from_messages([
|
| 105 |
+
("system", CONDENSE_PROMPT),
|
| 106 |
+
MessagesPlaceholder("history"),
|
| 107 |
+
("human", "{question}"),
|
| 108 |
+
])
|
| 109 |
+
self.condense_chain = self.condense_prompt | self.llm | StrOutputParser()
|
| 110 |
+
|
| 111 |
+
def _standalone_question(self, question: str, history_msgs: list) -> str:
|
| 112 |
+
if not history_msgs:
|
| 113 |
+
return question
|
| 114 |
+
try:
|
| 115 |
+
rewritten = self.condense_chain.invoke({"history": history_msgs, "question": question})
|
| 116 |
+
return rewritten.strip() or question
|
| 117 |
+
except Exception:
|
| 118 |
+
return question
|
| 119 |
+
|
| 120 |
+
def answer(self, question: str, history: list[dict] | None = None) -> tuple[str, list[dict]]:
|
| 121 |
+
"""Return (answer_text, sources). History is a list of {role, content}."""
|
| 122 |
+
history_msgs = _to_lc_messages(history or [])
|
| 123 |
+
search_query = self._standalone_question(question, history_msgs)
|
| 124 |
+
|
| 125 |
+
docs = self.retriever.invoke(search_query)
|
| 126 |
+
context = format_docs(docs)
|
| 127 |
+
sources = _sources_from_docs(docs)
|
| 128 |
+
|
| 129 |
+
chain = self.answer_prompt | self.llm | StrOutputParser()
|
| 130 |
+
answer = chain.invoke({
|
| 131 |
+
"context": context,
|
| 132 |
+
"history": history_msgs,
|
| 133 |
+
"question": question,
|
| 134 |
+
})
|
| 135 |
+
return answer, sources
|
| 136 |
+
|
| 137 |
+
|
| 138 |
+
def build_engine(vector_store: FAISS) -> RagEngine:
|
| 139 |
+
return RagEngine(vector_store)
|
documents/.gitkeep
ADDED
|
File without changes
|
documents/A011-Research-Honorarium-and-Conference-Assistance-Policy-V3.pdf
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:732dfcfa873e0cf2cbde055ed485e63e1636dbc6cf495f3c0381cca7fba45b77
|
| 3 |
+
size 278891
|
documents/A013-Policy-for-Workload-Relief-of-PhD-Scholars-V2.pdf
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:461dfaa73def42665a09ca375fcbfe61b5e8fc1b8918b9f668eeee71df8e5295
|
| 3 |
+
size 151344
|
documents/A014-Policy-for-Honorarium-on-Research-Project-Grants-V1-16-08-2021.pdf
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:e59f2e75e468dc5822e3f10dbdcf3b086287149d4d9e42e9a0e1816929dc3a4e
|
| 3 |
+
size 43067
|
documents/A014-Policy-for-Honorarium-on-Research-Project-Grants-V2-08-05-2023.pdf
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:6575d4cc5e51aaf4071b4e034e0e90523dc0226829476fc317514673ccfa8569
|
| 3 |
+
size 41673
|
documents/A015-Semester-Rules-for-Post-Graduate-Programs-V2.pdf
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:9dd903284ad0afdec0f7353a6612984e0032bc177aed4d00bbd1901e502e3272
|
| 3 |
+
size 86177
|
documents/A024-Policy-for-Transfer-of-Credit-Hours-Student-Mobility-12-08-2021-min.pdf
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:3e37cfac63e5cffb5944bb76e64addc1421d0869adfbae5c8036311efca9f5a4
|
| 3 |
+
size 55645
|
documents/A025-Admission-Policy-Fall-2021-12-08-2021-min.pdf
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:9a06432fdba8ff6fae5b2e08388b80a64b190480d3ce1d41a862b5bf92df0b0a
|
| 3 |
+
size 257233
|
documents/A026-Policy-for-Role-and-Responsibility-of-Academic-Advisor-V1.pdf
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:e7e73aa5c6620d716af9de7fbe5ba26000c6a9ef0f88f8bf1f43c0d8b2ea8efd
|
| 3 |
+
size 56946
|
documents/A028-Internship-Policy-and-Mechanism-V1.pdf
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:15369e7cb11dcbfe8f2d6c561f56b00168db88d921e335fc2b24053ec3935e68
|
| 3 |
+
size 123415
|
documents/A07-Rules-Regulations-for-the-Degree-of-Masters-in-Science-V2.pdf
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:59edc50f8e4cd191758229ec2c24aa36682312d53a611a78f1f4a01cddba1850
|
| 3 |
+
size 91612
|
documents/A08-Rules-and-Regulations-for-the-degree-of-PhD-V5.pdf
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:7f25dc36501fa2a2b7f5244476dcc988a2cb9ea1fe31d59a9fb212a1434b5e43
|
| 3 |
+
size 87795
|
documents/A21-Attendance-Policy-for-Online-Classes-Fall-2020-1-converted.pdf
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:739a16d52b647a3785dfedc8cf16db6e1440c370202864372b177c0d49d55c96
|
| 3 |
+
size 140968
|
documents/Academic-Freedom-Policy.pdf
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:10bceaff7de2f7df9ca9230027f548b877591cb5add8ed19067fe21209d040ba
|
| 3 |
+
size 117739
|
documents/Academic-Rules-Regulations.pdf
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:4dcfbc2094a5bc28691a2f3d51fbe348d779aa9cb6beb2289656f8cef0a48dec
|
| 3 |
+
size 388427
|
documents/Admission-Policy-2021-2022-12-06-2021-V0-converted-min.pdf
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:6ccb2c3e47e98fb20c9bc8328043d48ebbeb490c4d153a2c58a424dc429d5849
|
| 3 |
+
size 238362
|
documents/Admission-Policy-2022-2023-14-11-2022-min.pdf
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:883646c4c435e07dbfaa36be162f9dcd59648fe5f2195dd9a4c04c921fac551f
|
| 3 |
+
size 267282
|
documents/Admission-Policy-2024-2025.pdf
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:abfaf5f0a3deb2e42b04cf2c88c98b806bf79be176c184c09d0fd5513075ade2
|
| 3 |
+
size 446737
|
documents/Amendment_Policy_Sexual_Harassment-ACT-2022.pdf
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:01873b14d9030e5b007ffb5073c67d879aec7dc6c930f236203f794fd336cf56
|
| 3 |
+
size 565207
|
documents/Annex-F-SSUET-MBA-Rules-Regulations-Ver-2.pdf
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:caea79e26388e183398432ba75ae3878828cd5bdefeb9a5258685d83427e9d5c
|
| 3 |
+
size 107679
|
documents/Appeals-Procedure-Policy.pdf
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:5758411fb218fde918eaa4a6a12f1bdee39e47ea6ded834e3089bc3e498d7fdd
|
| 3 |
+
size 97719
|
documents/Application-Form-for-Publication-Honorarium-1-converted.pdf
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:cb934965735cb85aa66a87f4378d23a22695acb183bb20599251eacfb7ded13d
|
| 3 |
+
size 115719
|
documents/Arrangements-to-Prevent-Fradulent-Claims-of-Degree-Policy (1).pdf
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:cf4e78c65636f7a2c9d9470d2432720a8471304a21dd890293099e3676f005e8
|
| 3 |
+
size 124016
|
documents/Arrangements-to-Prevent-Fradulent-Claims-of-Degree-Policy.pdf
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:cf4e78c65636f7a2c9d9470d2432720a8471304a21dd890293099e3676f005e8
|
| 3 |
+
size 124016
|
documents/Conflict-of-Interest-Policy.pdf
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:37274cb945db6f812dad9c2807c58a6aa9e99c05cc51c9f37729ff7c59373118
|
| 3 |
+
size 332389
|
documents/Environment-Health-and-Safety-Policy.pdf
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:6c8cbafb6d312790c9cefe1162a1ae8bc884b4140aadaa8aaa77e9da34506c65
|
| 3 |
+
size 49024
|
documents/Evaluation-of-University-Performance-by-Stakeholders-Policy.pdf
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:833a1f4a9435ed81817b51b1145a693338af5ecb6cd19f1b4373fdb4927346b9
|
| 3 |
+
size 676313
|
documents/G009-Employee-Separation-Policy-and-Procedure-V1-14-02-2023.pdf
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:79b80a98f25cc42c40f7beb48d42119367b33e19130c5336263adc1846140f5d
|
| 3 |
+
size 94130
|
documents/G023-Policy-and-Procedure-for-Flexible-Working-Hours-V1-12-11-21.pdf
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:3fb33dbb16a65d5bcee5b9d73683a554cde4dcaa21305f5e2ee01eab196c1295
|
| 3 |
+
size 80467
|
documents/G024-Policy-and-Procedure-for-Engaging-Interns.pdf
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:597098c0c8099a3d8666011f9a6e30b82c7713e350f47059687a3aac778ecd72
|
| 3 |
+
size 58899
|
documents/G025-Policy-Against-Drug-and-Tobacco-Abuse-at-SSUET-12-08-2021-min (1).pdf
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:45cb5427ee8c9eb9294a1e723d0c06ca876cce77fa569f8570cd019f26cda499
|
| 3 |
+
size 193738
|
documents/G025-Policy-Against-Drug-and-Tobacco-Abuse-at-SSUET-12-08-2021-min.pdf
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:45cb5427ee8c9eb9294a1e723d0c06ca876cce77fa569f8570cd019f26cda499
|
| 3 |
+
size 193738
|
documents/G029-Policy-and-Procedures-for-Engaging-Temporary-Teaching-Staff-V2_2.pdf
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:c604be700b8fd9c8060f9f18e703a592f8216c9768fdc327c4eae40fafe16366
|
| 3 |
+
size 151863
|
documents/G03-Policy-for-Students-with-Disabilities-V2-12-08-2021-min.pdf
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:fefa472f783ddd7ca6577a561adb31764fe2c799c0bf253d5a835df9ba902734
|
| 3 |
+
size 190171
|
documents/G033-Onboarding-Staff-Induction-Policy-Procedures-V1-11-01-2023.pdf
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:4f07680f54d654a8e8028d4f0dbb7a7060acb2793be03748dc5699a43817d4a5
|
| 3 |
+
size 95270
|
documents/G051-Patent-Support-Policy-V1.pdf
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:3bf4d928fdb0f211cbcc7f6083431ab9ecc0da92d39b63cb7ceeb1ff62e551a1
|
| 3 |
+
size 529925
|
documents/G30-Policy-for-Authorization-of-Cellular-Phone-and-Calling-Cards-V1-07-12-21.pdf
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:b271062192268c2a9bbeef1aed99d1846a09183be04281209ba764d9b394d458
|
| 3 |
+
size 42092
|
documents/Grading-System.pdf
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:e59b7656ccdd8c1448fe66fb6d4bf3ddc6a9d8de3d80932e304d821f9be6569e
|
| 3 |
+
size 2263152
|
documents/HEC-Refund-Policy-2024.pdf
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:6519e9bf56422db3be3855f61eefe92c5ca86973a11b047fe85b06ae757a1dd3
|
| 3 |
+
size 279896
|
documents/Members-of-Inquiry-Committee-for-Protection-against-Sexual-Harassment-at-SSUET.pdf
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:a23b704ee66fefbd1428bec9af9f2a6ad46ff635e6b466f06dd5f2fb8e9dc652
|
| 3 |
+
size 25137
|