Skip to content

edityeah/ocr

Repository files navigation

OCR Toolkit — Chat for Documents

Hosted at ocr.adityeah.ai.

Drop a file (image, PDF, Word, Excel, CSV, plain text), and chat with it. Built on OpenAI gpt-4o-mini. No mode picker, no buttons to memorize — just upload and ask.

What you can do

  • Extract anything. Images, scanned PDFs, text-PDFs, Word docs, Excel sheets, CSVs, and plain text are all auto-detected.
  • Ask follow-ups in the same thread. "Summarize this." "What are the action items?" "Translate to Hindi." "Convert this table to JSON." The assistant has the document content for the rest of the conversation.
  • Stay organized. Every file you drop starts a new thread, with a title derived from your first question. Threads persist across page refreshes (in your browser's localStorage).

Local dev

cp .env.local.example .env.local
# paste your OPENAI_API_KEY (sk-...)
npm install
npm run dev
# → http://localhost:3002

Rate limiting is a no-op locally if the Upstash env vars are blank. For production-faithful testing, create a free Upstash project at https://console.upstash.com and paste the REST URL + token into .env.local.

Architecture (one line each)

  • src/app/page.tsx — orchestrates the chat: extract on client, append user message, POST /api/chat, append assistant message, auto-scroll
  • src/app/api/chat/route.ts — the only API route; accepts {messages: ChatTurn[]}, runs OpenAI, returns Markdown
  • src/lib/extract.ts — client-side extractFromFile(file){text? | image?, attachmentName, attachmentType, ...}
  • src/lib/thread-store.ts — localStorage CRUD + useThreadStore() hook
  • src/lib/prompts.ts — single adaptive SYSTEM_PROMPT
  • src/lib/ratelimit.ts — Upstash sliding window (15/day per IP) with no-op dev fallback
  • src/lib/openai.ts — thin OpenAI client (used by /api/chat)
  • src/lib/types.tsThread, Message, Attachment, ChatTurn, …
  • src/components/ThreadList.tsx — sidebar
  • src/components/MessageBubble.tsx — rendered message
  • src/components/Composer.tsx — input bar with file-attach + send

Stack

Next.js 16 (App Router) · TypeScript · Tailwind CSS v4 · OpenAI gpt-4o-mini · pdfjs-dist · mammoth · xlsx · react-markdown · Upstash Redis (rate limiting) · nanoid

Rate limits

  • 15 actions per IP per UTC day. Each call to /api/chat counts as 1 action (including follow-up questions in the same thread).
  • MAX_DAILY_REQUESTS site-wide safety cap (default 1000) — a hard ceiling so a viral burst can't run up the OpenAI bill.

File size limit

8 MB per upload. The Composer rejects oversized files client-side and /api/chat rejects oversized bodies server-side.

Privacy

Threads live in your browser's localStorage only — they aren't sent anywhere except to OpenAI inside the chat request. Clearing your browser data clears your threads. (Cross-device sync via Upstash KV is a possible follow-up.)

Built by

Aditya · adityeah.ai · github.com/edityeah/ocr

About

OCR Toolkit — chat with any document. Drop an image/PDF/Word/Excel/CSV and ask anything. Built with Next.js + OpenAI.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors