Spaces:
Running
Running
Deploy chat-with-pdf (30-in-15 #3)
Browse files- .env.example +8 -0
- .gitattributes +1 -0
- Dockerfile +11 -0
- README.md +47 -4
- app.py +389 -0
- demo.png +0 -0
- requirements.txt +6 -0
- sample_pdfs/employee_handbook.md +54 -0
- sample_pdfs/employee_handbook.pdf +3 -0
- sample_pdfs/product_manual.md +47 -0
- sample_pdfs/product_manual.pdf +0 -0
- sample_pdfs/research_report.md +47 -0
- sample_pdfs/research_report.pdf +0 -0
- sample_pdfs/simple_memo.md +23 -0
- sample_pdfs/simple_memo.pdf +0 -0
.env.example
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Pick ONE LLM backend. For a public deploy, use a cloud API (not local Ollama).
|
| 2 |
+
# Option A — Claude API (recommended):
|
| 3 |
+
ANTHROPIC_API_KEY=sk-ant-...
|
| 4 |
+
ANTHROPIC_MODEL=claude-haiku-4-5
|
| 5 |
+
# Option B — local Ollama (dev only; needs the fleet up):
|
| 6 |
+
# OLLAMA_URL=http://192.168.12.223:11434
|
| 7 |
+
# OLLAMA_MODEL=qwen2.5:7b
|
| 8 |
+
# (Embeddings run locally via fastembed — no key needed.)
|
.gitattributes
CHANGED
|
@@ -33,3 +33,4 @@ saved_model/**/* 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
|
|
|
|
|
|
| 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 |
+
sample_pdfs/employee_handbook.pdf filter=lfs diff=lfs merge=lfs -text
|
Dockerfile
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Chat with your PDF — runs on Hugging Face Spaces, Render, Railway, Fly.io, etc.
|
| 2 |
+
FROM python:3.11-slim
|
| 3 |
+
WORKDIR /app
|
| 4 |
+
COPY requirements.txt .
|
| 5 |
+
RUN pip install --no-cache-dir -r requirements.txt
|
| 6 |
+
COPY . .
|
| 7 |
+
# fastembed caches its model here; keep it writable
|
| 8 |
+
ENV FASTEMBED_CACHE_PATH=/app/.fastembed_cache
|
| 9 |
+
ENV PORT=7860
|
| 10 |
+
EXPOSE 7860
|
| 11 |
+
CMD ["python", "app.py"]
|
README.md
CHANGED
|
@@ -1,10 +1,53 @@
|
|
| 1 |
---
|
| 2 |
-
title: Chat
|
| 3 |
-
emoji:
|
| 4 |
colorFrom: green
|
| 5 |
-
colorTo:
|
| 6 |
sdk: docker
|
|
|
|
| 7 |
pinned: false
|
| 8 |
---
|
| 9 |
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
+
title: Chat with your PDF
|
| 3 |
+
emoji: 📄
|
| 4 |
colorFrom: green
|
| 5 |
+
colorTo: blue
|
| 6 |
sdk: docker
|
| 7 |
+
app_port: 7860
|
| 8 |
pinned: false
|
| 9 |
---
|
| 10 |
|
| 11 |
+
# Chat with your PDF 📄
|
| 12 |
+
|
| 13 |
+
Upload a PDF and ask questions about it. Answers are **grounded in the document** and
|
| 14 |
+
**cite the pages** they came from — and if the answer isn't in the file, it says so
|
| 15 |
+
instead of guessing. Real retrieval-augmented generation (RAG), not "paste the whole
|
| 16 |
+
thing into the prompt."
|
| 17 |
+
|
| 18 |
+
> Project **#3** of my *"30 AI Projects in 15 Days"* build-in-public challenge.
|
| 19 |
+
|
| 20 |
+
**▶ Live demo: https://pdf.gritai.solutions**
|
| 21 |
+
|
| 22 |
+

|
| 23 |
+
|
| 24 |
+
## How it works (the RAG pipeline)
|
| 25 |
+
1. **Extract** — pull text per page from the PDF (`pypdf`).
|
| 26 |
+
2. **Chunk** — split into overlapping passages, each tagged with its page number.
|
| 27 |
+
3. **Embed** — encode chunks with `fastembed` (BAAI/bge-small, ONNX/CPU — no GPU, no torch).
|
| 28 |
+
4. **Retrieve** — embed the question, cosine-rank the chunks, take the top matches.
|
| 29 |
+
5. **Answer** — Claude answers using only those excerpts and cites pages like `(p. 4)`.
|
| 30 |
+
|
| 31 |
+
## What it demonstrates
|
| 32 |
+
- **RAG fundamentals** — chunking, embeddings, vector similarity search, grounded generation.
|
| 33 |
+
- **Faithful, cited answers** — refuses to answer when the document doesn't cover it.
|
| 34 |
+
- **Lightweight + self-hosted embeddings** — no embedding API key required.
|
| 35 |
+
- **Streaming UX** and a drag-and-drop single-file interface.
|
| 36 |
+
|
| 37 |
+
## Try it with the sample PDFs
|
| 38 |
+
`sample_pdfs/` has four documents of increasing complexity to test with:
|
| 39 |
+
`simple_memo.pdf` · `product_manual.pdf` · `research_report.pdf` · `employee_handbook.pdf`.
|
| 40 |
+
|
| 41 |
+
## Run locally
|
| 42 |
+
```bash
|
| 43 |
+
pip install -r requirements.txt
|
| 44 |
+
export ANTHROPIC_API_KEY=sk-ant-... # or set OLLAMA_URL / OLLAMA_MODEL
|
| 45 |
+
python app.py # http://127.0.0.1:8500
|
| 46 |
+
```
|
| 47 |
+
|
| 48 |
+
## Deploy (always-on)
|
| 49 |
+
Ships with a `Dockerfile` — works on **Hugging Face Spaces**, Render, Railway, or Fly.io.
|
| 50 |
+
Set `ANTHROPIC_API_KEY` (+ optional `ANTHROPIC_MODEL=claude-haiku-4-5`) as a secret.
|
| 51 |
+
|
| 52 |
+
---
|
| 53 |
+
Built by **Robert Lucyk** · [GritAI Solutions](https://gritai.solutions) · part of the 30-in-15 challenge.
|
app.py
ADDED
|
@@ -0,0 +1,389 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python
|
| 2 |
+
"""Chat with your PDF — upload a PDF and ask questions; answers are grounded in the
|
| 3 |
+
document with page citations (real RAG: chunk -> embed -> retrieve -> answer).
|
| 4 |
+
|
| 5 |
+
Embeddings: fastembed (ONNX, CPU-friendly, no torch). LLM: Anthropic Claude API if
|
| 6 |
+
ANTHROPIC_API_KEY is set, else a local Ollama model.
|
| 7 |
+
|
| 8 |
+
pip install flask anthropic pypdf fastembed numpy
|
| 9 |
+
python app.py # http://127.0.0.1:8500
|
| 10 |
+
|
| 11 |
+
Project #3 of the "30 Projects in 15 Days" challenge — GritAI.
|
| 12 |
+
"""
|
| 13 |
+
import os, io, json, re, uuid
|
| 14 |
+
import numpy as np
|
| 15 |
+
from flask import Flask, request, Response, jsonify
|
| 16 |
+
|
| 17 |
+
HERE = os.path.dirname(os.path.abspath(__file__))
|
| 18 |
+
PORT = int(os.environ.get("PORT", "8500"))
|
| 19 |
+
ANTHROPIC_KEY = os.environ.get("ANTHROPIC_API_KEY")
|
| 20 |
+
ANTHROPIC_MODEL = os.environ.get("ANTHROPIC_MODEL", "claude-sonnet-5")
|
| 21 |
+
OLLAMA_URL = os.environ.get("OLLAMA_URL", "http://127.0.0.1:11434")
|
| 22 |
+
OLLAMA_MODEL = os.environ.get("OLLAMA_MODEL", "qwen2.5:7b")
|
| 23 |
+
|
| 24 |
+
MAX_PAGES = 120
|
| 25 |
+
CHUNK_CHARS = 1200
|
| 26 |
+
CHUNK_OVERLAP = 160
|
| 27 |
+
TOP_K = 6
|
| 28 |
+
MAX_DOCS = 24
|
| 29 |
+
|
| 30 |
+
SAMPLE_DIR = os.path.join(HERE, "sample_pdfs")
|
| 31 |
+
SAMPLES = {
|
| 32 |
+
"memo": ("simple_memo.pdf", "📋", "Office memo", "1-page internal memo"),
|
| 33 |
+
"manual": ("product_manual.pdf", "📘", "Product manual", "Smart thermostat guide"),
|
| 34 |
+
"report": ("research_report.pdf", "📊", "Market report", "Data, tables, findings"),
|
| 35 |
+
"handbook": ("employee_handbook.pdf", "📗", "Employee handbook", "13 pages, many sections"),
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
# ---- embedding model (lazy singleton) ----------------------------------------
|
| 39 |
+
_EMB = None
|
| 40 |
+
def emb_model():
|
| 41 |
+
global _EMB
|
| 42 |
+
if _EMB is None:
|
| 43 |
+
from fastembed import TextEmbedding
|
| 44 |
+
_EMB = TextEmbedding("BAAI/bge-small-en-v1.5")
|
| 45 |
+
return _EMB
|
| 46 |
+
|
| 47 |
+
def embed_passages(texts):
|
| 48 |
+
return np.array(list(emb_model().passage_embed(texts)), dtype=np.float32)
|
| 49 |
+
|
| 50 |
+
def embed_query(text):
|
| 51 |
+
return np.array(list(emb_model().query_embed([text]))[0], dtype=np.float32)
|
| 52 |
+
|
| 53 |
+
def _norm(m):
|
| 54 |
+
n = np.linalg.norm(m, axis=-1, keepdims=True)
|
| 55 |
+
return m / np.clip(n, 1e-8, None)
|
| 56 |
+
|
| 57 |
+
# ---- pdf -> chunks -----------------------------------------------------------
|
| 58 |
+
def extract_pages(data):
|
| 59 |
+
from pypdf import PdfReader
|
| 60 |
+
reader = PdfReader(io.BytesIO(data))
|
| 61 |
+
title = (reader.metadata.title if reader.metadata and reader.metadata.title else "").strip()
|
| 62 |
+
pages = []
|
| 63 |
+
for i, pg in enumerate(reader.pages[:MAX_PAGES], start=1):
|
| 64 |
+
txt = (pg.extract_text() or "").strip()
|
| 65 |
+
if txt:
|
| 66 |
+
pages.append((i, re.sub(r"[ \t]+", " ", txt)))
|
| 67 |
+
return title, len(reader.pages), pages
|
| 68 |
+
|
| 69 |
+
def chunk_pages(pages):
|
| 70 |
+
chunks = []
|
| 71 |
+
for pageno, text in pages:
|
| 72 |
+
i = 0
|
| 73 |
+
while i < len(text):
|
| 74 |
+
piece = text[i:i + CHUNK_CHARS].strip()
|
| 75 |
+
if len(piece) > 40:
|
| 76 |
+
chunks.append({"page": pageno, "text": piece})
|
| 77 |
+
i += CHUNK_CHARS - CHUNK_OVERLAP
|
| 78 |
+
return chunks
|
| 79 |
+
|
| 80 |
+
DOCS = {}
|
| 81 |
+
DOC_ORDER = []
|
| 82 |
+
|
| 83 |
+
def index_pdf(data, filename):
|
| 84 |
+
title, npages, pages = extract_pages(data)
|
| 85 |
+
if not pages:
|
| 86 |
+
raise ValueError("No extractable text found — this PDF may be scanned images (needs OCR).")
|
| 87 |
+
chunks = chunk_pages(pages)
|
| 88 |
+
emb = _norm(embed_passages([c["text"] for c in chunks]))
|
| 89 |
+
doc_id = uuid.uuid4().hex[:12]
|
| 90 |
+
disp = re.sub(r"\.(html?|pdf)$", "", (title or ""), flags=re.I).strip()
|
| 91 |
+
if not disp:
|
| 92 |
+
disp = re.sub(r"\.pdf$", "", filename or "document", flags=re.I)
|
| 93 |
+
DOCS[doc_id] = {"title": disp, "pages": npages, "chunks": chunks, "emb": emb}
|
| 94 |
+
DOC_ORDER.append(doc_id)
|
| 95 |
+
while len(DOC_ORDER) > MAX_DOCS:
|
| 96 |
+
DOCS.pop(DOC_ORDER.pop(0), None)
|
| 97 |
+
return doc_id, DOCS[doc_id]
|
| 98 |
+
|
| 99 |
+
def retrieve(doc, question, k=TOP_K):
|
| 100 |
+
q = _norm(embed_query(question).reshape(1, -1))[0]
|
| 101 |
+
sims = doc["emb"] @ q
|
| 102 |
+
idx = np.argsort(-sims)[:k]
|
| 103 |
+
return [doc["chunks"][i] for i in idx]
|
| 104 |
+
|
| 105 |
+
# ---- answer (streaming) ------------------------------------------------------
|
| 106 |
+
def system_prompt():
|
| 107 |
+
return (
|
| 108 |
+
"You answer questions about a specific document using ONLY the excerpts provided.\n"
|
| 109 |
+
"- Cite the page number(s) you used, in parentheses like (p. 4).\n"
|
| 110 |
+
"- If the answer is not in the excerpts, say you couldn't find it in the document — do not guess.\n"
|
| 111 |
+
"- Be concise and faithful. Write plain text; no markdown symbols like ** or #."
|
| 112 |
+
)
|
| 113 |
+
|
| 114 |
+
def build_context(chunks):
|
| 115 |
+
return "\n\n".join(f"[p. {c['page']}] {c['text']}" for c in chunks)
|
| 116 |
+
|
| 117 |
+
def answer_stream(doc, question):
|
| 118 |
+
ctx = build_context(retrieve(doc, question))
|
| 119 |
+
user = f"Document excerpts:\n\n{ctx}\n\n---\nQuestion: {question}"
|
| 120 |
+
if ANTHROPIC_KEY:
|
| 121 |
+
import anthropic
|
| 122 |
+
client = anthropic.Anthropic(api_key=ANTHROPIC_KEY)
|
| 123 |
+
with client.messages.stream(model=ANTHROPIC_MODEL, max_tokens=700,
|
| 124 |
+
system=system_prompt(),
|
| 125 |
+
messages=[{"role": "user", "content": user}]) as s:
|
| 126 |
+
for t in s.text_stream:
|
| 127 |
+
yield t
|
| 128 |
+
return
|
| 129 |
+
import requests
|
| 130 |
+
with requests.post(f"{OLLAMA_URL}/api/chat", stream=True, timeout=120, json={
|
| 131 |
+
"model": OLLAMA_MODEL, "stream": True,
|
| 132 |
+
"messages": [{"role": "system", "content": system_prompt()},
|
| 133 |
+
{"role": "user", "content": user}],
|
| 134 |
+
"options": {"temperature": 0.2}}) as r:
|
| 135 |
+
r.raise_for_status()
|
| 136 |
+
for line in r.iter_lines():
|
| 137 |
+
if not line:
|
| 138 |
+
continue
|
| 139 |
+
d = json.loads(line)
|
| 140 |
+
if d.get("message", {}).get("content"):
|
| 141 |
+
yield d["message"]["content"]
|
| 142 |
+
if d.get("done"):
|
| 143 |
+
break
|
| 144 |
+
|
| 145 |
+
app = Flask(__name__)
|
| 146 |
+
app.config["MAX_CONTENT_LENGTH"] = 20 * 1024 * 1024
|
| 147 |
+
|
| 148 |
+
@app.route("/")
|
| 149 |
+
def home():
|
| 150 |
+
return Response(PAGE, mimetype="text/html")
|
| 151 |
+
|
| 152 |
+
@app.route("/api/upload", methods=["POST"])
|
| 153 |
+
def api_upload():
|
| 154 |
+
f = request.files.get("pdf")
|
| 155 |
+
if not f:
|
| 156 |
+
return jsonify(error="No file uploaded."), 400
|
| 157 |
+
try:
|
| 158 |
+
doc_id, doc = index_pdf(f.read(), f.filename or "document.pdf")
|
| 159 |
+
return jsonify(doc_id=doc_id, title=doc["title"], pages=doc["pages"], chunks=len(doc["chunks"]))
|
| 160 |
+
except Exception as e:
|
| 161 |
+
return jsonify(error=str(e)[:200]), 400
|
| 162 |
+
|
| 163 |
+
@app.route("/api/sample", methods=["POST"])
|
| 164 |
+
def api_sample():
|
| 165 |
+
name = request.get_json(force=True).get("name")
|
| 166 |
+
meta = SAMPLES.get(name)
|
| 167 |
+
if not meta:
|
| 168 |
+
return jsonify(error="unknown sample"), 400
|
| 169 |
+
path = os.path.join(SAMPLE_DIR, meta[0])
|
| 170 |
+
if not os.path.exists(path):
|
| 171 |
+
return jsonify(error="sample not available"), 404
|
| 172 |
+
try:
|
| 173 |
+
with open(path, "rb") as fh:
|
| 174 |
+
doc_id, doc = index_pdf(fh.read(), meta[0])
|
| 175 |
+
return jsonify(doc_id=doc_id, title=doc["title"], pages=doc["pages"], chunks=len(doc["chunks"]))
|
| 176 |
+
except Exception as e:
|
| 177 |
+
return jsonify(error=str(e)[:200]), 400
|
| 178 |
+
|
| 179 |
+
@app.route("/api/ask", methods=["POST"])
|
| 180 |
+
def api_ask():
|
| 181 |
+
b = request.get_json(force=True)
|
| 182 |
+
doc = DOCS.get(b.get("doc_id", ""))
|
| 183 |
+
question = (b.get("question") or "").strip()
|
| 184 |
+
def gen():
|
| 185 |
+
import sys as _sys
|
| 186 |
+
if not doc:
|
| 187 |
+
yield "data: " + json.dumps({"t": "That document isn't loaded anymore — please re-upload it."}) + "\n\n"
|
| 188 |
+
elif not question:
|
| 189 |
+
yield "data: " + json.dumps({"t": "Please ask a question."}) + "\n\n"
|
| 190 |
+
else:
|
| 191 |
+
try:
|
| 192 |
+
for chunk in answer_stream(doc, question):
|
| 193 |
+
yield "data: " + json.dumps({"t": chunk}) + "\n\n"
|
| 194 |
+
except Exception as e:
|
| 195 |
+
print("ask error:", repr(e), file=_sys.stderr, flush=True)
|
| 196 |
+
yield "data: " + json.dumps({"t": "Sorry — I hit an error answering. Please try again."}) + "\n\n"
|
| 197 |
+
yield "data: [DONE]\n\n"
|
| 198 |
+
return Response(gen(), mimetype="text/event-stream",
|
| 199 |
+
headers={"Cache-Control": "no-cache", "X-Accel-Buffering": "no"})
|
| 200 |
+
|
| 201 |
+
PAGE = """<!doctype html><html lang="en"><head><meta charset="utf-8">
|
| 202 |
+
<title>Chat with your PDF</title>
|
| 203 |
+
<meta name="viewport" content="width=device-width,initial-scale=1">
|
| 204 |
+
<style>
|
| 205 |
+
:root{--teal:#0d9488;--teal2:#0f766e;--deep:#0b3b39;--ink:#132320;--bg:#eef4f3;--card:#fff;
|
| 206 |
+
--muted:#6f807c;--line:#e0eae8;--cite:#0d9488;--cite-bg:#e6f5f2}
|
| 207 |
+
*{box-sizing:border-box}html,body{height:100%}
|
| 208 |
+
body{margin:0;font-family:'Segoe UI',system-ui,-apple-system,sans-serif;color:var(--ink);
|
| 209 |
+
background:var(--bg);display:flex;justify-content:center;overflow-x:hidden}
|
| 210 |
+
.amb{position:fixed;inset:0;z-index:0;pointer-events:none;
|
| 211 |
+
background:radial-gradient(55vw 45vh at 82% -6%,rgba(13,148,136,.18),transparent 60%),
|
| 212 |
+
radial-gradient(50vw 40vh at 6% 8%,rgba(79,70,229,.10),transparent 62%),
|
| 213 |
+
radial-gradient(60vw 50vh at 50% 112%,rgba(13,148,136,.10),transparent 60%)}
|
| 214 |
+
.app{position:relative;z-index:1;width:100%;max-width:680px;min-height:100dvh;display:flex;flex-direction:column;
|
| 215 |
+
background:linear-gradient(180deg,rgba(255,255,255,.6),var(--card) 12%);}
|
| 216 |
+
header{padding:16px 22px;color:#fff;background:linear-gradient(120deg,var(--teal),var(--deep));
|
| 217 |
+
display:flex;align-items:center;gap:13px;position:relative;overflow:hidden}
|
| 218 |
+
header::after{content:"";position:absolute;right:-40px;top:-60px;width:200px;height:200px;border-radius:50%;
|
| 219 |
+
background:radial-gradient(circle,rgba(255,255,255,.12),transparent 70%)}
|
| 220 |
+
.brand-av{width:44px;height:44px;border-radius:12px;display:grid;place-items:center;font-size:22px;
|
| 221 |
+
background:rgba(255,255,255,.17);box-shadow:0 2px 10px rgba(0,0,0,.18);flex:none;z-index:1}
|
| 222 |
+
header h1{margin:0;font-size:19px;font-weight:700;letter-spacing:-.2px}
|
| 223 |
+
header .sub{margin:2px 0 0;font-size:12.5px;color:rgba(255,255,255,.85)}
|
| 224 |
+
.tag{margin-left:auto;z-index:1;font-size:10px;letter-spacing:.14em;text-transform:uppercase;
|
| 225 |
+
background:rgba(255,255,255,.15);border:1px solid rgba(255,255,255,.22);border-radius:20px;padding:5px 11px;font-weight:600}
|
| 226 |
+
|
| 227 |
+
/* ---- upload view ---- */
|
| 228 |
+
#uploadView{flex:1;display:flex;flex-direction:column;align-items:center;justify-content:center;padding:30px 22px;text-align:center}
|
| 229 |
+
.hero-badge{width:64px;height:64px;border-radius:18px;display:grid;place-items:center;font-size:32px;margin-bottom:18px;
|
| 230 |
+
background:linear-gradient(135deg,#d7f2ee,#c3e9ff);box-shadow:0 10px 30px -10px rgba(13,148,136,.5)}
|
| 231 |
+
#uploadView h2{margin:0;font-size:30px;font-weight:800;letter-spacing:-.5px;
|
| 232 |
+
background:linear-gradient(120deg,var(--deep),var(--teal));-webkit-background-clip:text;background-clip:text;-webkit-text-fill-color:transparent}
|
| 233 |
+
#uploadView .lead{margin:10px 0 20px;color:var(--muted);font-size:15px;max-width:46ch;line-height:1.5}
|
| 234 |
+
.feats{display:flex;gap:10px;flex-wrap:wrap;justify-content:center;margin-bottom:24px}
|
| 235 |
+
.feat{display:inline-flex;align-items:center;gap:7px;background:var(--card);border:1px solid var(--line);
|
| 236 |
+
border-radius:22px;padding:7px 14px;font-size:12.5px;color:var(--ink);box-shadow:0 2px 8px rgba(19,35,32,.04)}
|
| 237 |
+
.feat b{font-weight:600}
|
| 238 |
+
#drop{width:100%;max-width:460px;border:2px dashed #bcd6d2;border-radius:20px;padding:36px 24px;cursor:pointer;
|
| 239 |
+
transition:.18s;background:linear-gradient(180deg,#fbfefe,#f4faf9)}
|
| 240 |
+
#drop:hover,#drop.drag{border-color:var(--teal);background:#eafaf7;transform:translateY(-2px);box-shadow:0 16px 34px -20px rgba(13,148,136,.45)}
|
| 241 |
+
#drop .ic{font-size:38px}#drop .t{font-weight:700;margin:8px 0 3px;font-size:16px}#drop .h{color:var(--muted);font-size:13px}
|
| 242 |
+
.samples{margin-top:26px;width:100%;max-width:520px}
|
| 243 |
+
.samples .lbl{font-size:11px;letter-spacing:.12em;text-transform:uppercase;color:var(--muted);margin-bottom:11px}
|
| 244 |
+
.sgrid{display:grid;grid-template-columns:1fr 1fr;gap:10px}
|
| 245 |
+
.samp{display:flex;align-items:center;gap:11px;text-align:left;background:var(--card);border:1px solid var(--line);
|
| 246 |
+
border-radius:13px;padding:11px 13px;cursor:pointer;transition:.15s}
|
| 247 |
+
.samp:hover{border-color:var(--teal);transform:translateY(-2px);box-shadow:0 10px 22px -14px rgba(13,148,136,.4)}
|
| 248 |
+
.samp .e{font-size:22px;flex:none}.samp .tt{font-weight:600;font-size:13.5px}.samp .hh{color:var(--muted);font-size:11.5px}
|
| 249 |
+
|
| 250 |
+
/* ---- chat view ---- */
|
| 251 |
+
#chatView{flex:1;display:none;flex-direction:column;min-height:0}
|
| 252 |
+
.docbar{display:flex;align-items:center;gap:10px;padding:11px 18px;border-bottom:1px solid var(--line);
|
| 253 |
+
background:linear-gradient(180deg,#f5fbfa,#fff)}
|
| 254 |
+
.docbar .dic{font-size:18px}.docbar .dt{font-weight:700;font-size:14px}
|
| 255 |
+
.docbar .dm{color:var(--muted);font-size:12px}
|
| 256 |
+
.docbar .new{margin-left:auto;color:var(--teal);cursor:pointer;font-size:12.5px;font-weight:600;
|
| 257 |
+
border:1px solid var(--line);border-radius:18px;padding:6px 12px;transition:.15s}
|
| 258 |
+
.docbar .new:hover{background:var(--cite-bg);border-color:var(--teal)}
|
| 259 |
+
#log{flex:1;overflow-y:auto;padding:18px 16px;display:flex;flex-direction:column;gap:13px}
|
| 260 |
+
#log::-webkit-scrollbar{width:8px}#log::-webkit-scrollbar-thumb{background:#cfe2de;border-radius:8px}
|
| 261 |
+
.row{display:flex;gap:9px;align-items:flex-end;animation:rise .28s ease both}
|
| 262 |
+
.row.user{flex-direction:row-reverse}
|
| 263 |
+
@keyframes rise{from{opacity:0;transform:translateY(8px)}to{opacity:1;transform:none}}
|
| 264 |
+
.av{width:30px;height:30px;border-radius:50%;flex:none;display:grid;place-items:center;font-size:15px;
|
| 265 |
+
background:linear-gradient(135deg,#d7f2ee,#c3e9ff)}
|
| 266 |
+
.msg{max-width:80%;padding:12px 15px;border-radius:16px;line-height:1.55;font-size:14.5px;white-space:pre-wrap;
|
| 267 |
+
box-shadow:0 2px 6px rgba(19,35,32,.06)}
|
| 268 |
+
.msg.bot{background:var(--card);border:1px solid var(--line);border-bottom-left-radius:5px}
|
| 269 |
+
.msg.user{background:linear-gradient(135deg,var(--teal),var(--teal2));color:#fff;border-bottom-right-radius:5px}
|
| 270 |
+
.cite{display:inline-block;background:var(--cite-bg);color:var(--cite);border-radius:6px;padding:0 6px;
|
| 271 |
+
font-size:12px;font-weight:600;white-space:nowrap}
|
| 272 |
+
.starters{display:flex;flex-wrap:wrap;gap:8px;padding:2px 4px 4px 43px}
|
| 273 |
+
.starter{background:var(--card);border:1px solid var(--line);border-radius:16px;padding:7px 12px;font-size:12.5px;
|
| 274 |
+
cursor:pointer;color:var(--teal);transition:.15s}
|
| 275 |
+
.starter:hover{border-color:var(--teal);background:var(--cite-bg)}
|
| 276 |
+
form{display:flex;gap:9px;padding:12px 14px;border-top:1px solid var(--line);background:var(--card)}
|
| 277 |
+
input#q{flex:1;padding:13px 16px;border:1px solid var(--line);border-radius:24px;font-size:15px;background:#f8fcfb;color:var(--ink);outline:none;transition:.15s}
|
| 278 |
+
input#q:focus{border-color:var(--teal);background:#fff;box-shadow:0 0 0 3px rgba(13,148,136,.14)}
|
| 279 |
+
button.send{flex:none;width:46px;height:46px;border-radius:50%;border:0;cursor:pointer;display:grid;place-items:center;
|
| 280 |
+
background:linear-gradient(135deg,var(--teal),var(--teal2));color:#fff;transition:.15s}
|
| 281 |
+
button.send:hover{filter:brightness(1.1)}button.send:disabled{opacity:.45}button.send svg{width:18px;height:18px}
|
| 282 |
+
.typing{display:inline-flex;gap:4px}.typing span{width:7px;height:7px;border-radius:50%;background:var(--teal);opacity:.5;animation:bd 1.2s infinite ease-in-out}
|
| 283 |
+
.typing span:nth-child(2){animation-delay:.2s}.typing span:nth-child(3){animation-delay:.4s}
|
| 284 |
+
@keyframes bd{0%,60%,100%{transform:translateY(0);opacity:.35}30%{transform:translateY(-6px);opacity:1}}
|
| 285 |
+
.foot{text-align:center;font-size:10.5px;color:var(--muted);padding:8px}.foot b{color:#4a5d59}
|
| 286 |
+
</style></head>
|
| 287 |
+
<body><div class="amb"></div><div class="app">
|
| 288 |
+
<header>
|
| 289 |
+
<div class="brand-av">📄</div>
|
| 290 |
+
<div><h1>Chat with your PDF</h1><div class="sub">Upload a document — answers cite the exact page</div></div>
|
| 291 |
+
<span class="tag">RAG</span>
|
| 292 |
+
</header>
|
| 293 |
+
|
| 294 |
+
<div id="uploadView">
|
| 295 |
+
<div class="hero-badge">📄</div>
|
| 296 |
+
<h2>Ask your documents anything</h2>
|
| 297 |
+
<p class="lead">Drop in a PDF and get answers grounded in its contents — every answer cites the page it came from, and it won't make things up.</p>
|
| 298 |
+
<div class="feats">
|
| 299 |
+
<span class="feat">⚡ <b>Instant</b> answers</span>
|
| 300 |
+
<span class="feat">📍 <b>Cites</b> the page</span>
|
| 301 |
+
<span class="feat">🛡️ <b>Won't</b> guess</span>
|
| 302 |
+
</div>
|
| 303 |
+
<div id="drop">
|
| 304 |
+
<div class="ic">⬆️</div><div class="t">Drop a PDF here or click to upload</div>
|
| 305 |
+
<div class="h">Up to 20 MB · text-based PDFs</div>
|
| 306 |
+
<input type="file" id="file" accept="application/pdf" style="display:none">
|
| 307 |
+
</div>
|
| 308 |
+
<div class="samples">
|
| 309 |
+
<div class="lbl">— or try a sample —</div>
|
| 310 |
+
<div class="sgrid" id="sgrid"></div>
|
| 311 |
+
</div>
|
| 312 |
+
</div>
|
| 313 |
+
|
| 314 |
+
<div id="chatView">
|
| 315 |
+
<div class="docbar"><span class="dic">📄</span><div><div class="dt" id="dt">document</div><div class="dm" id="dm"></div></div>
|
| 316 |
+
<span class="new" onclick="reset()">↺ New PDF</span></div>
|
| 317 |
+
<div id="log"></div>
|
| 318 |
+
<div class="starters" id="starters"></div>
|
| 319 |
+
<form id="form" onsubmit="ask();return false;">
|
| 320 |
+
<input id="q" placeholder="Ask about the document…" autocomplete="off">
|
| 321 |
+
<button class="send" id="btn" aria-label="Send">
|
| 322 |
+
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="22" y1="2" x2="11" y2="13"></line><polygon points="22 2 15 22 11 13 2 9 22 2"></polygon></svg>
|
| 323 |
+
</button>
|
| 324 |
+
</form>
|
| 325 |
+
</div>
|
| 326 |
+
<div class="foot">Answers grounded in your uploaded PDF · <b>GritAI</b></div>
|
| 327 |
+
</div><script>
|
| 328 |
+
const SAMPLES=[["memo","📋","Office memo","1-page internal memo"],
|
| 329 |
+
["manual","📘","Product manual","Smart thermostat guide"],
|
| 330 |
+
["report","📊","Market report","Data, tables, findings"],
|
| 331 |
+
["handbook","📗","Employee handbook","13 pages, many sections"]];
|
| 332 |
+
const STARTERS=["Summarize this document","What are the key points?","What should I know first?"];
|
| 333 |
+
const $=id=>document.getElementById(id);
|
| 334 |
+
const drop=$('drop'),file=$('file'),log=$('log'),form=$('form'),q=$('q'),btn=$('btn'),
|
| 335 |
+
uploadView=$('uploadView'),chatView=$('chatView'),dt=$('dt'),dm=$('dm');
|
| 336 |
+
let docId=null,busy=false;
|
| 337 |
+
// render sample buttons
|
| 338 |
+
$('sgrid').innerHTML=SAMPLES.map(s=>`<div class="samp" onclick="loadSample('${s[0]}')"><span class="e">${s[1]}</span><div><div class="tt">${s[2]}</div><div class="hh">${s[3]}</div></div></div>`).join('');
|
| 339 |
+
$('starters').innerHTML=STARTERS.map(s=>`<span class="starter" onclick="ask('${s.replace(/'/g,"\\\\'")}')">${s}</span>`).join('');
|
| 340 |
+
drop.onclick=()=>file.click();
|
| 341 |
+
file.onchange=e=>{if(e.target.files[0])upload(e.target.files[0]);};
|
| 342 |
+
['dragover','dragenter'].forEach(ev=>drop.addEventListener(ev,e=>{e.preventDefault();drop.classList.add('drag');}));
|
| 343 |
+
['dragleave','drop'].forEach(ev=>drop.addEventListener(ev,e=>{e.preventDefault();drop.classList.remove('drag');}));
|
| 344 |
+
drop.addEventListener('drop',e=>{const f=e.dataTransfer.files[0];if(f&&f.type==='application/pdf')upload(f);});
|
| 345 |
+
function esc(s){return s.replace(/[&<>]/g,c=>({'&':'&','<':'<','>':'>'}[c]));}
|
| 346 |
+
function render(el,text){el.innerHTML=esc(text).replace(/\\(pp?\\.?\\s*\\d+(?:\\s*(?:,|;|&|and)\\s*(?:pp?\\.?\\s*)?\\d+)*\\)/gi,m=>'<span class="cite">'+m+'</span>');}
|
| 347 |
+
function add(t,who){const row=document.createElement('div');row.className='row '+who;
|
| 348 |
+
if(who==='bot'){const a=document.createElement('div');a.className='av';a.textContent='📄';row.appendChild(a);}
|
| 349 |
+
const d=document.createElement('div');d.className='msg '+who;d.textContent=t;row.appendChild(d);
|
| 350 |
+
log.appendChild(row);log.scrollTop=log.scrollHeight;return d;}
|
| 351 |
+
function showChat(d){docId=d.doc_id;dt.textContent=d.title;dm.textContent=d.pages+' pages · '+d.chunks+' chunks indexed';
|
| 352 |
+
uploadView.style.display='none';chatView.style.display='flex';log.innerHTML='';
|
| 353 |
+
add('Loaded "'+d.title+'". Ask me anything about it — I\\'ll cite the pages I use.','bot');q.focus();}
|
| 354 |
+
function reset(){docId=null;chatView.style.display='none';uploadView.style.display='flex';file.value='';
|
| 355 |
+
drop.innerHTML='<div class="ic">⬆️</div><div class="t">Drop a PDF here or click to upload</div><div class="h">Up to 20 MB · text-based PDFs</div>';drop.appendChild(file);}
|
| 356 |
+
async function post(url,opts){const r=await fetch(url,opts);return r.json();}
|
| 357 |
+
async function upload(f){
|
| 358 |
+
drop.innerHTML='<div class="ic">⏳</div><div class="t">Reading & indexing…</div><div class="h">'+esc(f.name)+'</div>';
|
| 359 |
+
const fd=new FormData();fd.append('pdf',f);
|
| 360 |
+
try{const d=await post('/api/upload',{method:'POST',body:fd});
|
| 361 |
+
if(d.error){drop.innerHTML='<div class="ic">⚠️</div><div class="t">Couldn\\'t read that PDF</div><div class="h">'+esc(d.error)+'</div>';drop.appendChild(file);return;}
|
| 362 |
+
showChat(d);}catch(e){drop.innerHTML='<div class="ic">⚠️</div><div class="t">Upload failed — click to retry</div>';drop.appendChild(file);}
|
| 363 |
+
}
|
| 364 |
+
async function loadSample(name){
|
| 365 |
+
const box=[...document.querySelectorAll('.samp')].find(x=>x.getAttribute('onclick').includes("'"+name+"'"));
|
| 366 |
+
if(box)box.style.opacity=.5;
|
| 367 |
+
try{const d=await post('/api/sample',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({name})});
|
| 368 |
+
if(d.error){alert(d.error);}else showChat(d);}catch(e){}
|
| 369 |
+
if(box)box.style.opacity=1;
|
| 370 |
+
}
|
| 371 |
+
async function ask(preset){if(busy||!docId)return;const question=(preset||q.value).trim();if(!question)return;
|
| 372 |
+
q.value='';busy=true;btn.disabled=true;add(question,'user');
|
| 373 |
+
const b=add('','bot');b.innerHTML='<span class="typing"><span></span><span></span><span></span></span>';
|
| 374 |
+
let full='';
|
| 375 |
+
try{const r=await fetch('/api/ask',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({doc_id:docId,question})});
|
| 376 |
+
const rd=r.body.getReader(),dec=new TextDecoder();let buf='';
|
| 377 |
+
while(true){const {value,done}=await rd.read();if(done)break;buf+=dec.decode(value,{stream:true});
|
| 378 |
+
let i;while((i=buf.indexOf('\\n\\n'))>=0){const line=buf.slice(0,i).trim();buf=buf.slice(i+2);
|
| 379 |
+
if(!line.startsWith('data:'))continue;const p=line.slice(5).trim();if(p==='[DONE]')continue;
|
| 380 |
+
try{const t=JSON.parse(p).t;full+=t;b.textContent=full;log.scrollTop=log.scrollHeight;}catch(e){}}}
|
| 381 |
+
if(full)render(b,full);else b.textContent='No answer produced — try rephrasing.';
|
| 382 |
+
}catch(e){b.textContent='Sorry — something went wrong.';}
|
| 383 |
+
busy=false;btn.disabled=false;q.focus();}
|
| 384 |
+
</script></body></html>"""
|
| 385 |
+
|
| 386 |
+
if __name__ == "__main__":
|
| 387 |
+
backend = "Claude API" if ANTHROPIC_KEY else f"Ollama ({OLLAMA_MODEL} @ {OLLAMA_URL})"
|
| 388 |
+
print(f"Chat with your PDF on http://127.0.0.1:{PORT} [backend: {backend}]", flush=True)
|
| 389 |
+
app.run(host="0.0.0.0", port=PORT, threaded=True)
|
demo.png
ADDED
|
requirements.txt
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
flask>=3.0
|
| 2 |
+
requests>=2.31
|
| 3 |
+
anthropic>=0.40
|
| 4 |
+
pypdf>=4.0
|
| 5 |
+
fastembed>=0.3
|
| 6 |
+
numpy>=1.26
|
sample_pdfs/employee_handbook.md
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Blue Harbor Software — Employee Handbook (2026 Edition)
|
| 2 |
+
|
| 3 |
+
Welcome to Blue Harbor Software. This handbook summarizes our policies, benefits, and expectations. It is not a contract of employment. Where this handbook conflicts with a signed agreement or applicable law, those prevail. Questions go to People Operations at **people@blueharbor.example**.
|
| 4 |
+
|
| 5 |
+
## 1. Employment Basics
|
| 6 |
+
Blue Harbor is an at-will employer. Standard full-time hours are **40 per week**. Core collaboration hours are **10:00 AM to 3:00 PM local time**; outside those hours, schedules are flexible. New employees serve a **90-day introductory period** during which either party may end employment with minimal notice.
|
| 7 |
+
|
| 8 |
+
## 2. Remote & Hybrid Work
|
| 9 |
+
Blue Harbor is **remote-first**. Employees may work from anywhere within a country where we have a legal entity (currently the U.S., Canada, and Portugal). If you relocate, notify People Ops **at least 30 days in advance**, as it may affect payroll and taxes. Teams may designate up to **four in-person gathering weeks** per year; travel for these is company-paid.
|
| 10 |
+
|
| 11 |
+
### Home Office Stipend
|
| 12 |
+
Full-time employees receive a **one-time $1,000 home-office stipend** and a **$60/month internet reimbursement**. Keep receipts for anything over $75.
|
| 13 |
+
|
| 14 |
+
## 3. Paid Time Off (PTO)
|
| 15 |
+
Blue Harbor offers **flexible (uncapped) PTO** for salaried employees, with an expectation that everyone takes **at least 15 days per year**. PTO must be approved by your manager and logged in Rippling. Because PTO is uncapped, **it does not accrue and is not paid out** at termination.
|
| 16 |
+
|
| 17 |
+
Hourly employees accrue PTO at **1.5 days per month** (18 days/year), which does carry over and is paid out on separation, up to a cap of 30 days.
|
| 18 |
+
|
| 19 |
+
## 4. Holidays
|
| 20 |
+
The company observes **12 paid holidays** per year, listed each January in the People Ops calendar. In addition, employees get **two "floating holidays"** to use for occasions meaningful to them. The office (and Slack) goes quiet during our **year-end shutdown from December 24 to January 1**, which does not count against PTO.
|
| 21 |
+
|
| 22 |
+
## 5. Sick Leave & Family Leave
|
| 23 |
+
Salaried employees use flexible PTO for illness. Hourly employees have a separate bank of **7 paid sick days** per year.
|
| 24 |
+
|
| 25 |
+
New parents receive **16 weeks of fully paid parental leave**, available to all parents regardless of gender, to be taken within 12 months of birth or adoption. Leave can be taken continuously or split into up to three blocks.
|
| 26 |
+
|
| 27 |
+
## 6. Benefits
|
| 28 |
+
- **Health insurance:** Company pays 90% of the employee premium and 60% of dependent premiums on the base PPO plan. Coverage starts on your **first day** (no waiting period).
|
| 29 |
+
- **Dental & vision:** Fully paid for the employee.
|
| 30 |
+
- **Retirement:** 401(k) with a **4% company match**, vested immediately.
|
| 31 |
+
- **Life insurance:** 1x annual salary, company-paid.
|
| 32 |
+
- **Learning budget:** **$1,500 per year** for courses, books, or conferences.
|
| 33 |
+
- **Wellness:** $50/month wellness reimbursement (gym, apps, therapy copays).
|
| 34 |
+
|
| 35 |
+
## 7. Compensation & Reviews
|
| 36 |
+
Salaries are reviewed annually each **April**. Performance reviews happen twice a year (April and October) on a 5-point scale. Promotions can occur at any cycle. Referral bonuses are **$3,000** per hired referral, paid after the new hire's 90th day.
|
| 37 |
+
|
| 38 |
+
## 8. Expenses & Travel
|
| 39 |
+
Submit expenses in Ramp within **30 days**. Pre-approval is required for any single expense over **$500**. Standard travel: economy airfare, mid-tier hotels, and a **$65/day meal per diem**. Rideshare is preferred over rental cars for trips under three days. Alcohol is not reimbursable except at pre-approved company events.
|
| 40 |
+
|
| 41 |
+
## 9. Equipment & Security
|
| 42 |
+
Each employee receives a company laptop. **Full-disk encryption and the company password manager are mandatory.** Never store customer data on personal devices. Report a lost device to security@blueharbor.example **within 24 hours**. Multi-factor authentication is required on all company accounts. Phishing tests are run quarterly.
|
| 43 |
+
|
| 44 |
+
## 10. Code of Conduct
|
| 45 |
+
We expect professionalism and respect. Harassment, discrimination, and retaliation are prohibited and grounds for termination. Report concerns to your manager, People Ops, or the anonymous ethics line at **1-800-555-0143**. All reports are investigated; retaliation against a good-faith reporter is itself a violation.
|
| 46 |
+
|
| 47 |
+
## 11. Confidentiality & IP
|
| 48 |
+
Employees sign a confidentiality and invention-assignment agreement at hire. Do not share non-public company or customer information. Work created within the scope of employment belongs to the company. Public speaking or writing about your work requires a quick heads-up to Communications.
|
| 49 |
+
|
| 50 |
+
## 12. Leaving Blue Harbor
|
| 51 |
+
We ask for **two weeks' notice**. On your last day, return all equipment. Final pay, including any accrued-and-owed hourly PTO, is issued on the next regular payroll date. Your health coverage continues through the **end of the month** of your departure, after which COBRA options are provided. We conduct optional exit interviews and genuinely value the feedback.
|
| 52 |
+
|
| 53 |
+
---
|
| 54 |
+
*This handbook is reviewed annually. Last updated January 2026. For anything not covered here, ask People Ops.*
|
sample_pdfs/employee_handbook.pdf
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:1e6b139b17d3cd5037ffaa3f677da526b9a2748239a0b164e164bf98c73e50b1
|
| 3 |
+
size 114929
|
sample_pdfs/product_manual.md
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Aeris S2 Smart Thermostat — User Manual
|
| 2 |
+
|
| 3 |
+
Thank you for choosing the **Aeris S2**. This manual covers setup, features, troubleshooting, and warranty. Model number: **AER-S2-2026**.
|
| 4 |
+
|
| 5 |
+
## 1. In the Box
|
| 6 |
+
- Aeris S2 thermostat display unit
|
| 7 |
+
- Wall mounting plate and trim ring
|
| 8 |
+
- 4 wall screws and 2 drywall anchors
|
| 9 |
+
- Quick-start card
|
| 10 |
+
- USB-C charging cable (for the internal backup battery)
|
| 11 |
+
|
| 12 |
+
## 2. Technical Specifications
|
| 13 |
+
- **Display:** 3.5-inch color LCD, 320 x 480 resolution
|
| 14 |
+
- **Connectivity:** Wi-Fi 2.4 GHz only (does **not** support 5 GHz networks)
|
| 15 |
+
- **Power:** 24V C-wire required; internal rechargeable backup battery lasts up to 8 hours
|
| 16 |
+
- **Compatibility:** Works with most 24V forced-air, heat pump, and radiant systems. **Not compatible** with high-voltage (120V/240V) baseboard heaters.
|
| 17 |
+
- **Sensors:** Temperature, humidity, occupancy (PIR motion), ambient light
|
| 18 |
+
- **Operating range:** 40°F to 90°F setpoint
|
| 19 |
+
|
| 20 |
+
## 3. Installation
|
| 21 |
+
1. **Turn off power** to your HVAC system at the breaker. This is mandatory.
|
| 22 |
+
2. Remove your old thermostat and photograph the wiring first.
|
| 23 |
+
3. Connect the wires to the labeled terminals on the mounting plate. The **C (common) wire is required** for the S2 to power continuously.
|
| 24 |
+
4. Snap the display onto the plate and restore power at the breaker.
|
| 25 |
+
5. Follow the on-screen setup to join your 2.4 GHz Wi-Fi network.
|
| 26 |
+
|
| 27 |
+
## 4. The Aeris App
|
| 28 |
+
Download the **Aeris Home** app (iOS 15+ or Android 10+). The app enables scheduling, remote control, energy reports, and software updates. Create one account per household; up to **6 family members** can be invited to control the same thermostat.
|
| 29 |
+
|
| 30 |
+
### Scheduling
|
| 31 |
+
Set up to **4 periods per day** (Wake, Away, Home, Sleep). Geofencing can automatically switch to Away mode when everyone's phone leaves a configurable radius (default 3 miles).
|
| 32 |
+
|
| 33 |
+
## 5. Energy Saving Features
|
| 34 |
+
- **Smart Eco** learns your patterns and can reduce heating/cooling runtime by up to 18% after two weeks.
|
| 35 |
+
- **Filter reminders** trigger every 90 days of runtime.
|
| 36 |
+
- Monthly energy reports are emailed on the 1st of each month.
|
| 37 |
+
|
| 38 |
+
## 6. Troubleshooting
|
| 39 |
+
- **Blank screen:** Confirm the C-wire is connected. Without it, the backup battery drains in about 8 hours and the unit shuts down.
|
| 40 |
+
- **Won't join Wi-Fi:** The S2 supports 2.4 GHz only. If your router broadcasts a combined 2.4/5 GHz network under one name, temporarily separate the bands or use a guest 2.4 GHz network.
|
| 41 |
+
- **Temperature reads high:** Keep the unit out of direct sunlight; the ambient light sensor and enclosure can bias readings near a sunny window.
|
| 42 |
+
- **Motion not detected:** The occupancy sensor has a 120-degree field of view and a 20-foot range. Mount at 52-60 inches above the floor.
|
| 43 |
+
|
| 44 |
+
## 7. Warranty & Support
|
| 45 |
+
The Aeris S2 includes a **3-year limited warranty** covering manufacturing defects from the date of purchase. The warranty does **not** cover damage from improper installation, power surges, or water exposure. Keep your proof of purchase.
|
| 46 |
+
|
| 47 |
+
For support, call **1-800-555-0199** (Mon-Fri, 8 AM-8 PM ET) or email **support@aerishome.example**. Return authorizations must be requested within **30 days** of delivery for a full refund.
|
sample_pdfs/product_manual.pdf
ADDED
|
Binary file (84.2 kB). View file
|
|
|
sample_pdfs/research_report.md
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# The State of Small-Business AI Adoption — 2026 Market Report
|
| 2 |
+
|
| 3 |
+
**Prepared by:** Meridian Insights Group
|
| 4 |
+
**Publication date:** February 2026
|
| 5 |
+
**Report ID:** MIG-SMB-2026-014
|
| 6 |
+
|
| 7 |
+
## Executive Summary
|
| 8 |
+
This report examines how small and medium-sized businesses (SMBs, defined here as fewer than 250 employees) are adopting artificial intelligence tools. Drawing on a survey of **1,840 SMB decision-makers** across North America conducted in Q4 2025, we find that adoption has accelerated sharply, but that a persistent "capability gap" separates experimenters from those achieving measurable ROI. Overall, **62% of SMBs** reported using at least one AI-powered tool in daily operations, up from 41% the prior year.
|
| 9 |
+
|
| 10 |
+
## Methodology
|
| 11 |
+
Responses were collected via a mixed online and telephone survey between October 15 and December 12, 2025. Quotas ensured representation across industry, region, and company size. The margin of error is ±2.3 percentage points at the 95% confidence level. Self-reported ROI figures were not independently audited and should be treated as directional.
|
| 12 |
+
|
| 13 |
+
## Key Findings
|
| 14 |
+
|
| 15 |
+
### Adoption by Function
|
| 16 |
+
The most common entry point for AI was **customer support** (chatbots and email drafting), followed by marketing content generation. Adoption by business function is summarized below.
|
| 17 |
+
|
| 18 |
+
| Function | Using AI (2025) | Using AI (2026) | YoY change |
|
| 19 |
+
|---|---|---|---|
|
| 20 |
+
| Customer support | 22% | 39% | +17 pts |
|
| 21 |
+
| Marketing / content | 28% | 44% | +16 pts |
|
| 22 |
+
| Bookkeeping / finance | 12% | 21% | +9 pts |
|
| 23 |
+
| Scheduling / operations | 15% | 27% | +12 pts |
|
| 24 |
+
| Data analysis / reporting | 9% | 19% | +10 pts |
|
| 25 |
+
|
| 26 |
+
### Spending
|
| 27 |
+
Median annual AI tool spend among adopters was **$2,400** per business, though the distribution was highly skewed: the top decile spent more than **$18,000**. Notably, **54%** of adopters relied entirely on free or freemium tools.
|
| 28 |
+
|
| 29 |
+
### The Capability Gap
|
| 30 |
+
While 62% report *using* AI, only **23%** said they had a defined process for measuring its impact. Businesses that assigned a specific owner to AI initiatives were **2.7x** more likely to report measurable ROI than those treating it ad hoc. The single most-cited barrier was **"we don't know what's possible"** (mentioned by 48% of respondents), ahead of cost (31%) and data-privacy concerns (27%).
|
| 31 |
+
|
| 32 |
+
## Regional Notes
|
| 33 |
+
Adoption was highest in the West (68%) and lowest in the Midwest (55%). Urban SMBs adopted at 66% versus 51% for rural businesses, a gap the authors attribute largely to broadband reliability and access to local technical talent.
|
| 34 |
+
|
| 35 |
+
## Recommendations
|
| 36 |
+
1. **Start with a bounded, high-frequency task** (e.g., answering repetitive customer questions) rather than an open-ended "AI strategy."
|
| 37 |
+
2. **Assign an owner** and define one success metric before purchasing tools.
|
| 38 |
+
3. **Prefer tools that show their work** — citations, logs, and confidence signals build trust and speed adoption.
|
| 39 |
+
4. **Budget for training, not just licenses.** The data suggests the binding constraint is know-how, not software cost.
|
| 40 |
+
|
| 41 |
+
## Limitations
|
| 42 |
+
This study relies on self-reported data and a single annual snapshot. Causal claims (e.g., that assigning an owner *causes* higher ROI) cannot be established from cross-sectional survey data. Future waves will add a longitudinal panel.
|
| 43 |
+
|
| 44 |
+
## References
|
| 45 |
+
- Meridian Insights Group, *SMB Technology Tracker*, 2024 and 2025 waves.
|
| 46 |
+
- U.S. Small Business Administration, Office of Advocacy, firm-size definitions, 2024.
|
| 47 |
+
- Interviews with 30 SMB owners conducted January 2026 (anonymized).
|
sample_pdfs/research_report.pdf
ADDED
|
Binary file (94.8 kB). View file
|
|
|
sample_pdfs/simple_memo.md
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Internal Memo — Northgate Logistics
|
| 2 |
+
|
| 3 |
+
**To:** All Warehouse Staff
|
| 4 |
+
**From:** Dana Whitfield, Operations Manager
|
| 5 |
+
**Date:** March 3, 2026
|
| 6 |
+
**Re:** Holiday closure, new scanner rollout, and parking changes
|
| 7 |
+
|
| 8 |
+
## Holiday Closure
|
| 9 |
+
The warehouse will be **closed Friday, May 22 through Monday, May 25** for the Memorial Day weekend. Normal operations resume Tuesday, May 26 at 6:00 AM. Any outbound orders due that weekend must be staged and manifested by end of shift on Thursday, May 21.
|
| 10 |
+
|
| 11 |
+
## New Handheld Scanners
|
| 12 |
+
Starting **April 6**, we are replacing the old Symbol scanners with the new **Zebra TC22** units. Key points:
|
| 13 |
+
|
| 14 |
+
- Each picker is assigned one device; sign it out at the cage and return it at end of shift.
|
| 15 |
+
- The new units use a **swappable battery** — grab a charged spare from the wall dock if you drop below 20%.
|
| 16 |
+
- Report any cracked screens to the shift lead immediately; do not tape them.
|
| 17 |
+
- Training sessions run the first week of April; a 20-minute session is required before you can badge onto the floor.
|
| 18 |
+
|
| 19 |
+
## Parking Changes
|
| 20 |
+
The north lot will be **repaved from April 13 to April 24**. During that window, park in the **east gravel lot** by Dock 7. Handicap spaces remain available by the main entrance. Do not park along the fire lane on the south side — vehicles will be towed at the owner's expense.
|
| 21 |
+
|
| 22 |
+
## Questions
|
| 23 |
+
Reach me at extension **4120** or stop by the mezzanine office. Thank you for keeping the floor running smoothly.
|
sample_pdfs/simple_memo.pdf
ADDED
|
Binary file (56.8 kB). View file
|
|
|