RAG_Chatbot / README.md
Noorhan's picture
Update README.md
7ab7049 verified
|
Raw
History Blame Contribute Delete
2.76 kB
---
title: Educational Assistant
emoji: πŸŒ–
colorFrom: purple
colorTo: green
sdk: docker
app_port: 7860
pinned: false
---
## Quick start (clone for your own course)
1. **Duplicate this Space** on Hugging Face.
2. In your Space β†’ **Settings β†’ Variables and secrets**, add:
- `HF_TOKEN` β€” required; use a token with write access so the app can create/sync the dataset.
- `APP_PASSWORD` β€” strongly recommended if the Space is public/protected; default is `password`.
3. Optional overrides:
- `APP_USERNAME` β€” defaults to `student`.
- `DATASET_ID` β€” defaults to `<SPACE_ID>-corpus` on Spaces and is created automatically when needed.
- `ADMIN_PASSCODE` β€” defaults to `password`; set this for real deployments.
- *(optional)* `LLM_MODEL` β€” defaults to `Qwen/Qwen2.5-7B-Instruct`.
- *(optional)* `EMBED_MODEL` β€” defaults to `BAAI/bge-small-en-v1.5`.
4. Restart the Space. Open `/admin`, sign in with the passcode, drag in PDFs.
5. Share the root URL with your students β€” they land on the chat UI.
## Local development
Requires Python 3.13, Node 20+, and [`uv`](https://docs.astral.sh/uv/).
```bash
cp .env.example .env # fill in HF_TOKEN; other values have defaults
# Backend
cd backend && uv sync && uv run uvicorn main:app --port 8000 --reload
# Frontend (in another shell)
cd frontend && npm install && npm run dev
```
Visit <http://localhost:7860>. Next.js proxies `/api/*` to `127.0.0.1:8000`.
### Or with Docker (matches the HF Space environment exactly)
```bash
docker build -t iamearthdev .
docker run --rm -p 7860:7860 --env-file .env iamearthdev
```
## Customizing personas
Edit [`frontend/lib/personas.ts`](frontend/lib/personas.ts) β€” each persona is just an
`id`, `name`, `description`, and a `prompt` that gets prepended to the system message.
Rebuild the Space to deploy.
## Repo layout
```
/
β”œβ”€β”€ Dockerfile # multi-stage: Next build β†’ Python+Node runtime
β”œβ”€β”€ start.sh # launches FastAPI (:8000) and Next.js (:7860)
β”œβ”€β”€ .env.example
β”œβ”€β”€ backend/
β”‚ β”œβ”€β”€ pyproject.toml # uv-managed deps
β”‚ β”œβ”€β”€ main.py # FastAPI app, /chat streams NDJSON
β”‚ β”œβ”€β”€ rag.py # PyMuPDF4LLM β†’ LlamaIndex β†’ LanceDB
β”‚ β”œβ”€β”€ hf_sync.py # Dataset upload/download/list/delete
β”‚ └── auth.py # passcode cookie middleware
└── frontend/
β”œβ”€β”€ next.config.js # /api/* β†’ http://127.0.0.1:8000/*
β”œβ”€β”€ package.json
β”œβ”€β”€ app/
β”‚ β”œβ”€β”€ page.tsx # chat UI
β”‚ β”œβ”€β”€ admin/page.tsx # upload + file list
β”‚ └── admin/login/page.tsx
└── components/ # chat-interface, persona-selector, file-uploader, …
```