Spaces:
Sleeping
Sleeping
| 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, β¦ | |
| ``` | |