feat: migrate backend to HF Spaces Docker (16GB RAM free tier)
Browse filesDockerfile:
- Port 8000 β 7860 (HF Spaces convention)
- Add non-root user UID 1000 (HF Spaces requirement)
- Pre-create chroma_db dir with correct ownership
README.md:
- Add HF Spaces frontmatter (title, emoji, sdk: docker, app_port: 7860)
- Update live demo URL to askprism.vercel.app
- Update deployment instructions: Render β HF Spaces
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Dockerfile +10 -7
- README.md +21 -13
Dockerfile
CHANGED
|
@@ -3,24 +3,27 @@ WORKDIR /app
|
|
| 3 |
|
| 4 |
COPY requirements.txt .
|
| 5 |
|
| 6 |
-
#
|
| 7 |
-
# the default CUDA-enabled torch (~2GB). CUDA torch OOMs on Render's 512MB free tier.
|
| 8 |
RUN pip install torch --index-url https://download.pytorch.org/whl/cpu --no-cache-dir
|
| 9 |
RUN pip install --no-cache-dir -r requirements.txt
|
| 10 |
|
| 11 |
-
#
|
| 12 |
RUN python -c "from sentence_transformers import CrossEncoder; CrossEncoder('cross-encoder/ms-marco-TinyBERT-L-2-v2')"
|
| 13 |
|
| 14 |
COPY server/ server/
|
| 15 |
COPY config.yaml .
|
| 16 |
COPY data/ground_truth/ data/ground_truth/
|
| 17 |
|
| 18 |
-
RUN mkdir -p data/raw logs
|
| 19 |
|
| 20 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
ENV HF_HUB_OFFLINE=1
|
| 22 |
ENV TRANSFORMERS_OFFLINE=1
|
| 23 |
|
| 24 |
-
EXPOSE
|
| 25 |
|
| 26 |
-
CMD ["uvicorn", "server.main:app", "--host", "0.0.0.0", "--port", "
|
|
|
|
| 3 |
|
| 4 |
COPY requirements.txt .
|
| 5 |
|
| 6 |
+
# CPU-only torch β avoids pulling CUDA torch (~2GB) via sentence-transformers
|
|
|
|
| 7 |
RUN pip install torch --index-url https://download.pytorch.org/whl/cpu --no-cache-dir
|
| 8 |
RUN pip install --no-cache-dir -r requirements.txt
|
| 9 |
|
| 10 |
+
# Bake reranker weights into image β avoids cold-start HF Hub download
|
| 11 |
RUN python -c "from sentence_transformers import CrossEncoder; CrossEncoder('cross-encoder/ms-marco-TinyBERT-L-2-v2')"
|
| 12 |
|
| 13 |
COPY server/ server/
|
| 14 |
COPY config.yaml .
|
| 15 |
COPY data/ground_truth/ data/ground_truth/
|
| 16 |
|
| 17 |
+
RUN mkdir -p data/raw logs chroma_db
|
| 18 |
|
| 19 |
+
# HF Spaces requires non-root user UID 1000
|
| 20 |
+
RUN useradd -m -u 1000 user && chown -R user /app
|
| 21 |
+
USER user
|
| 22 |
+
|
| 23 |
+
# Prevent runtime HF Hub network calls β model is baked into image
|
| 24 |
ENV HF_HUB_OFFLINE=1
|
| 25 |
ENV TRANSFORMERS_OFFLINE=1
|
| 26 |
|
| 27 |
+
EXPOSE 7860
|
| 28 |
|
| 29 |
+
CMD ["uvicorn", "server.main:app", "--host", "0.0.0.0", "--port", "7860"]
|
README.md
CHANGED
|
@@ -1,6 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
# Prism β Document Intelligence with Self-Scoring Retrieval
|
| 2 |
|
| 3 |
-
**Live demo:** https://
|
| 4 |
|
| 5 |
Load any documents or URLs β Prism becomes an instant expert on that corpus. Ask multi-turn questions, get cited answers, and see retrieval quality scored on every response. Most RAG apps fail silently when retrieval breaks. Prism surfaces that signal.
|
| 6 |
|
|
@@ -39,7 +49,7 @@ If retrieval degrades, you see it before the user does.
|
|
| 39 |
ββββββββββββββββββββββββββ¬ββββββββββββββββββββββββββββββββββ
|
| 40 |
β HTTP
|
| 41 |
ββββββββββββββββββββββββββΌββββββββββββββββββββββββββββββββββ
|
| 42 |
-
β FastAPI Backend (
|
| 43 |
β β
|
| 44 |
β Upload / URL ingest β
|
| 45 |
β β ParentDocumentRetriever (child 200-char / parent 800) β
|
|
@@ -70,7 +80,7 @@ If retrieval degrades, you see it before the user does.
|
|
| 70 |
| **Sparse retrieval** | rank_bm25 (BM25Okapi) |
|
| 71 |
| **Hybrid fusion** | Weighted RRF (dense 0.7 + sparse 0.3) |
|
| 72 |
| **Reranker** | cross-encoder/ms-marco-TinyBERT-L-2-v2 (~17MB) |
|
| 73 |
-
| **Embeddings** | Euron API `text-embedding-3-small` β API-based
|
| 74 |
| **LLM** | Groq `llama-3.3-70b-versatile` via `langchain-groq` |
|
| 75 |
| **Orchestration** | LangChain `ConversationalRetrievalChain` |
|
| 76 |
| **Memory** | `ConversationBufferWindowMemory` (k=10 turns) |
|
|
@@ -158,20 +168,18 @@ python scripts/run_ragas_local.py --n 10
|
|
| 158 |
|
| 159 |
| Service | Platform | Notes |
|
| 160 |
|---|---|---|
|
| 161 |
-
| Backend |
|
| 162 |
| Frontend | Vercel | Free tier, auto-deploys from `main` branch. |
|
| 163 |
|
| 164 |
-
### Backend on
|
| 165 |
-
1.
|
| 166 |
-
2.
|
| 167 |
-
3.
|
| 168 |
-
4. Deploy
|
| 169 |
|
| 170 |
### Frontend on Vercel
|
| 171 |
-
1. Vercel β Import repo
|
| 172 |
-
2.
|
| 173 |
-
3.
|
| 174 |
-
4. Deploy
|
| 175 |
|
| 176 |
---
|
| 177 |
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: Prism
|
| 3 |
+
emoji: π
|
| 4 |
+
colorFrom: indigo
|
| 5 |
+
colorTo: purple
|
| 6 |
+
sdk: docker
|
| 7 |
+
app_port: 7860
|
| 8 |
+
pinned: false
|
| 9 |
+
---
|
| 10 |
+
|
| 11 |
# Prism β Document Intelligence with Self-Scoring Retrieval
|
| 12 |
|
| 13 |
+
**Live demo:** https://askprism.vercel.app
|
| 14 |
|
| 15 |
Load any documents or URLs β Prism becomes an instant expert on that corpus. Ask multi-turn questions, get cited answers, and see retrieval quality scored on every response. Most RAG apps fail silently when retrieval breaks. Prism surfaces that signal.
|
| 16 |
|
|
|
|
| 49 |
ββββββββββββββββββββββββββ¬ββββββββββββββββββββββββββββββββββ
|
| 50 |
β HTTP
|
| 51 |
ββββββββββββββββββββββββββΌββββββββββββββββββββββββββββββββββ
|
| 52 |
+
β FastAPI Backend (HF Spaces β Docker, 16GB) β
|
| 53 |
β β
|
| 54 |
β Upload / URL ingest β
|
| 55 |
β β ParentDocumentRetriever (child 200-char / parent 800) β
|
|
|
|
| 80 |
| **Sparse retrieval** | rank_bm25 (BM25Okapi) |
|
| 81 |
| **Hybrid fusion** | Weighted RRF (dense 0.7 + sparse 0.3) |
|
| 82 |
| **Reranker** | cross-encoder/ms-marco-TinyBERT-L-2-v2 (~17MB) |
|
| 83 |
+
| **Embeddings** | Euron API `text-embedding-3-small` β API-based (avoids local model RAM cost) |
|
| 84 |
| **LLM** | Groq `llama-3.3-70b-versatile` via `langchain-groq` |
|
| 85 |
| **Orchestration** | LangChain `ConversationalRetrievalChain` |
|
| 86 |
| **Memory** | `ConversationBufferWindowMemory` (k=10 turns) |
|
|
|
|
| 168 |
|
| 169 |
| Service | Platform | Notes |
|
| 170 |
|---|---|---|
|
| 171 |
+
| Backend | HF Spaces (Docker) | 16GB RAM free tier. Runs as UID 1000. Port 7860. |
|
| 172 |
| Frontend | Vercel | Free tier, auto-deploys from `main` branch. |
|
| 173 |
|
| 174 |
+
### Backend on HF Spaces
|
| 175 |
+
1. huggingface.co β New Space β Docker β link this GitHub repo
|
| 176 |
+
2. Space Settings β Repository Secrets β add `GROQ_API_KEY`, `EURON_API_KEY`, `TAVILY_API_KEY`
|
| 177 |
+
3. Space auto-builds from `main` on push
|
|
|
|
| 178 |
|
| 179 |
### Frontend on Vercel
|
| 180 |
+
1. Vercel β Import repo β Root Directory: `frontend`
|
| 181 |
+
2. Set env var: `VITE_API_URL=https://<your-hf-username>-prism.hf.space/api`
|
| 182 |
+
3. Deploy
|
|
|
|
| 183 |
|
| 184 |
---
|
| 185 |
|