Repository: Nutlope/smartpdfs Branch: main Commit: 5021dd353c33 Files: 44 Total size: 154.3 KB Directory structure: gitextract_c9h6c21g/ ├── .eslintrc.json ├── .example.env ├── .gitignore ├── .node-version ├── .prettierrc ├── LICENSE ├── README.md ├── components.json ├── next.config.ts ├── package.json ├── postcss.config.mjs ├── prisma/ │ └── schema.prisma ├── src/ │ ├── app/ │ │ ├── actions.ts │ │ ├── api/ │ │ │ ├── image/ │ │ │ │ └── route.ts │ │ │ ├── s3-upload/ │ │ │ │ └── route.ts │ │ │ └── summarize/ │ │ │ └── route.ts │ │ ├── globals.css │ │ ├── layout.tsx │ │ ├── page.tsx │ │ └── pdf/ │ │ └── [id]/ │ │ ├── page.tsx │ │ └── smart-pdf-viewer.tsx │ ├── components/ │ │ ├── HomeLandingDrop.tsx │ │ ├── icons/ │ │ │ ├── github.tsx │ │ │ ├── sparkles.tsx │ │ │ └── x.tsx │ │ ├── images/ │ │ │ ├── homepage-image-1.tsx │ │ │ └── homepage-image-2.tsx │ │ └── ui/ │ │ ├── action-button.tsx │ │ ├── button.tsx │ │ ├── logo.tsx │ │ ├── select.tsx │ │ ├── spinner.tsx │ │ ├── summary-content.tsx │ │ ├── table-of-contents.tsx │ │ ├── toast.tsx │ │ └── toaster.tsx │ ├── hooks/ │ │ └── use-toast.ts │ └── lib/ │ ├── ai.ts │ ├── prisma.ts │ ├── s3client.ts │ ├── summarize.ts │ └── utils.ts ├── tailwind.config.ts └── tsconfig.json ================================================ FILE CONTENTS ================================================ ================================================ FILE: .eslintrc.json ================================================ { "extends": ["next/core-web-vitals", "next/typescript"] } ================================================ FILE: .example.env ================================================ TOGETHER_API_KEY= DATABASE_URL= S3_UPLOAD_KEY= S3_UPLOAD_SECRET= S3_UPLOAD_BUCKET= S3_UPLOAD_REGION= ================================================ FILE: .gitignore ================================================ # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. # dependencies /node_modules /.pnp .pnp.* .yarn/* !.yarn/patches !.yarn/plugins !.yarn/releases !.yarn/versions # testing /coverage # next.js /.next/ /out/ # production /build # misc .DS_Store *.pem # debug npm-debug.log* yarn-debug.log* yarn-error.log* # env files (can opt-in for committing if needed) .env* # vercel .vercel # typescript *.tsbuildinfo next-env.d.ts .env*.local ================================================ FILE: .node-version ================================================ 20.12.1 ================================================ FILE: .prettierrc ================================================ { "plugins": ["prettier-plugin-tailwindcss"] } ================================================ FILE: LICENSE ================================================ MIT License Copyright (c) 2025 Hassan El Mghari Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ================================================ FILE: README.md ================================================ SmartPDF

SmartPDF

Instantly summarize and section your PDFs with AI. Powered by Llama 3.3 on Together AI.

## Tech stack - [Together AI](https://togetherai.link) for inference - [Llama 3.3](https://togetherai.link/llama-3.3) for the LLM - Next.js with Tailwind & TypeScript - Prisma ORM with Neon (Postgres) - Helicone for observability - Plausible for analytics - S3 for PDF storage ## Cloning & running 1. Clone the repo: `git clone https://github.com/Nutlope/smartpdfs` 2. Create a `.env` file and add your environment variables (see `.example.env`): - `TOGETHER_API_KEY=` - `DATABASE_URL=` - `S3_UPLOAD_KEY=` - `S3_UPLOAD_SECRET=` - `S3_UPLOAD_BUCKET=` - `S3_UPLOAD_REGION=us-east-1` - `HELICONE_API_KEY=` (optional, for observability) 3. Run `pnpm install` to install dependencies 4. Run `pnpm prisma generate` to generate the Prisma client 5. Run `pnpm dev` to start the development server ## Roadmap - [ ] Add some rate limiting by IP address - [ ] Integrate OCR for image parsing in PDFs - [ ] Add a bit more polish (make the link icon nicer) & add a "powered by Together" sign - [ ] Implement additional revision steps for improved summaries - [ ] Add a demo PDF for new users to be able to see it in action - [ ] Add feedback system with thumbs up/down feature ================================================ FILE: components.json ================================================ { "$schema": "https://ui.shadcn.com/schema.json", "style": "new-york", "rsc": true, "tsx": true, "tailwind": { "config": "tailwind.config.ts", "css": "src/app/globals.css", "baseColor": "neutral", "cssVariables": true, "prefix": "" }, "aliases": { "components": "@/components", "utils": "@/lib/utils", "ui": "@/components/ui", "lib": "@/lib", "hooks": "@/hooks" }, "iconLibrary": "lucide" } ================================================ FILE: next.config.ts ================================================ import type { NextConfig } from "next"; const nextConfig: NextConfig = { images: { remotePatterns: [ { protocol: "https", hostname: "napkinsdev.s3.us-east-1.amazonaws.com", }, { protocol: "https", hostname: "api.together.ai", }, ], }, }; export default nextConfig; ================================================ FILE: package.json ================================================ { "name": "pdf-summary", "version": "0.1.0", "private": true, "scripts": { "dev": "next dev", "build": "next build", "postinstall": "prisma generate", "start": "next start", "lint": "next lint", "update:all": "pnpm update --interactive --latest" }, "dependencies": { "@ai-sdk/togetherai": "^2.0.37", "@aws-sdk/client-s3": "^3.797.0", "@neondatabase/serverless": "^1.0.0", "@prisma/adapter-neon": "^6.6.0", "@prisma/client": "^6.6.0", "@radix-ui/react-select": "^2.1.2", "@radix-ui/react-slot": "^1.1.0", "@radix-ui/react-toast": "^1.2.2", "@tailwindcss/typography": "^0.5.16", "ai": "^6.0.108", "class-variance-authority": "^0.7.0", "clsx": "^2.1.1", "dedent": "^1.5.3", "lucide-react": "^0.503.0", "nanoid": "^5.1.5", "next": "16.1.6", "next-plausible": "^3.12.5", "next-s3-upload": "^0.3.4", "pdfjs-dist": "^4.8.69", "react": "19.2.4", "react-dom": "19.2.4", "react-dropzone": "^14.3.5", "tailwind-merge": "^2.5.4", "tailwindcss-animate": "^1.0.7", "together-ai": "^0.37.0", "ws": "^8.18.0", "zod": "^4.3.6" }, "devDependencies": { "@types/node": "^22.15.3", "@types/react": "^19.2.14", "@types/react-dom": "^19.2.3", "@types/ws": "^8.5.13", "eslint": "9.25.1", "eslint-config-next": "15.3.1", "postcss": "^8", "prettier": "^3.3.3", "prettier-plugin-tailwindcss": "^0.6.8", "prisma": "^6.6.0", "tailwindcss": "^3.4.1", "typescript": "^5" }, "engines": { "node": "22.x" }, "pnpm": { "onlyBuiltDependencies": [ "@prisma/client" ] } } ================================================ FILE: postcss.config.mjs ================================================ /** @type {import('postcss-load-config').Config} */ const config = { plugins: { tailwindcss: {}, }, }; export default config; ================================================ FILE: prisma/schema.prisma ================================================ // This is your Prisma schema file, // learn more about it in the docs: https://pris.ly/d/prisma-schema // Looking for ways to speed up your queries, or scale easily with your serverless or edge functions? // Try Prisma Accelerate: https://pris.ly/cli/accelerate-init generator client { provider = "prisma-client-js" } datasource db { provider = "postgresql" url = env("DATABASE_URL") } model SmartPDF { id String @id @default(nanoid(5)) createdAt DateTime @default(now()) imageUrl String pdfUrl String pdfName String sections Section[] } model Section { id String @id @default(nanoid(5)) type String title String summary String position Int SmartPDF SmartPDF @relation(fields: [smartPDFId], references: [id]) smartPDFId String } ================================================ FILE: src/app/actions.ts ================================================ "use server"; import { nanoid } from "nanoid"; import client from "@/lib/prisma"; import { redirect } from "next/navigation"; const slugify = (text: string) => { return text .toLowerCase() .replace(/ /g, "-") .replace(/[^\w-]+/g, "") .replace(/--+/g, "-") .replace(/^-+/, "") .replace(/-+$/, "") .slice(0, 20); }; export async function sharePdf({ pdfName, pdfUrl, imageUrl, sections, }: { pdfName: string; pdfUrl: string; imageUrl: string; sections: { type: string; title: string; summary: string; position: number; }[]; }) { const smartPdf = await client.smartPDF.create({ data: { id: `${slugify(sections[0].title)}-${nanoid(4)}`, pdfName, pdfUrl, imageUrl, sections: { createMany: { data: sections, }, }, }, }); redirect(`/pdf/${smartPdf.id}`); } ================================================ FILE: src/app/api/image/route.ts ================================================ import dedent from "dedent"; import { togetheraiBaseClient, togetheraiClient } from "@/lib/ai"; import { ImageGenerationResponse } from "@/lib/summarize"; import { awsS3Client } from "@/lib/s3client"; import { PutObjectCommand } from "@aws-sdk/client-s3"; import { generateText } from "ai"; export async function POST(req: Request) { const json = await req.json(); const text = "text" in json ? json.text : ""; const start = new Date(); const truncatedText = text.slice(0, 2000); const { text: visualDescription } = await generateText({ model: togetheraiClient( "meta-llama/Llama-4-Maverick-17B-128E-Instruct-FP8", ), prompt: dedent` Based on the following content, describe a single visual scene that represents its essence. The scene should be suitable for a painting or illustration. Do NOT include any text, words, or writing in your description. Just describe what you would see: objects, colors, atmosphere, lighting, mood. Keep it to 2-3 sentences. Content: ${truncatedText} Visual scene description: `, }); const prompt = dedent` ${visualDescription} Oil painting, fine art, museum quality, artistic brushstrokes. No text, no words, no letters, no writing, no documents, no signs. Pure visual illustration only. `; const generatedImage = await togetheraiBaseClient.images.generate({ model: "black-forest-labs/FLUX.2-dev", width: 1280, height: 720, prompt: prompt, }); const end = new Date(); console.log(`Image generation took ${end.getTime() - start.getTime()}ms`); const imageData = generatedImage.data[0]; if (!imageData) throw new Error("No image data generated"); if (imageData.url === undefined) throw new Error("Expected URL response format"); const imageUrl = imageData.url; if (!imageUrl) throw new Error("No image URL returned"); const imageFetch = await fetch(imageUrl); const imageBlob = await imageFetch.blob(); const imageBuffer = Buffer.from(await imageBlob.arrayBuffer()); const coverImageKey = `pdf-cover-${generatedImage.id}.jpg`; const uploadedFile = await awsS3Client.send( new PutObjectCommand({ Bucket: process.env.S3_UPLOAD_BUCKET || "", Key: coverImageKey, Body: imageBuffer, ContentType: "image/jpeg", }), ); if (!uploadedFile) { throw new Error("Failed to upload enhanced image to S3"); } return Response.json({ url: `https://${process.env.S3_UPLOAD_BUCKET}.s3.${ process.env.S3_UPLOAD_REGION || "us-east-1" }.amazonaws.com/${coverImageKey}`, } as ImageGenerationResponse); } export const runtime = "edge"; ================================================ FILE: src/app/api/s3-upload/route.ts ================================================ export { POST } from "next-s3-upload/route"; ================================================ FILE: src/app/api/summarize/route.ts ================================================ import { togetheraiBaseClient } from "@/lib/ai"; import assert from "assert"; import dedent from "dedent"; import { z } from "zod"; export async function POST(req: Request) { const { text, language } = await req.json(); assert.ok(typeof text === "string"); assert.ok(typeof language === "string"); const systemPrompt = dedent` You are an expert at summarizing text. Your task: 1. Read the document excerpt I will provide 2. Create a concise summary in ${language} 3. Generate a short, descriptive title in ${language} Guidelines for the summary: - Format the summary in HTML - Use

tags for paragraphs (2-3 sentences each) - Use