A Next.js application that uses Google Cloud Document AI for OCR and Vertex AI's Gemini model to analyze legal documents and provide AI-powered Q&A functionality.
- PDF Upload: Drag-and-drop PDF upload with file validation
- OCR Processing: Extract text from legal documents using Google Cloud Document AI
- AI Summarization: Generate key points and summaries using Gemini 1.5 Pro
- Interactive Q&A: Ask questions about the document with conversational AI
- Professional UI: Clean, responsive interface optimized for legal document analysis
-
Google Cloud Project with the following APIs enabled:
- Document AI API
- Vertex AI API
-
Document AI Processor: Create a Document AI processor for OCR
- Go to the Document AI Console
- Create a new processor (type: "Document OCR")
- Note the Processor ID
-
Authentication: Set up Google Cloud authentication
- For local development: Install Google Cloud CLI and run
gcloud auth application-default login - For production: Use service account keys or workload identity
- For local development: Install Google Cloud CLI and run
-
Clone and install dependencies:
npm install
-
Environment Configuration:
cp .env.example .env.local
Edit
.env.localwith your values:PROJECT_ID=your-google-cloud-project-id LOCATION=us-central1 PROCESSOR_ID=your-document-ai-processor-id
-
Run the development server:
npm run dev
-
Open the application: Navigate to http://localhost:3000
- Upload Document: Drag and drop or click to upload a PDF legal document
- Wait for Processing: The app will extract text using OCR and generate a summary
- Review Summary: Read the AI-generated key points and analysis
- Ask Questions: Use the chat interface to ask specific questions about the document
POST /api/extract-text- Extract text from PDF using Document AIPOST /api/summarize- Generate document summary using GeminiPOST /api/ask- Answer questions about the document using Gemini
- Frontend: Next.js 15 with TypeScript and Tailwind CSS
- OCR: Google Cloud Document AI for PDF text extraction
- AI: Google Vertex AI (Gemini 1.5 Pro) for summarization and Q&A
- Styling: Tailwind CSS with responsive design
- File size limited to 10MB
- Only PDF files accepted
- All processing happens server-side
- No document content is stored permanently
-
"Cannot find module" errors: Ensure all dependencies are installed with
npm install -
Authentication errors:
- Verify Google Cloud authentication is set up
- Check that your project has the required APIs enabled
- Ensure the processor ID is correct
-
OCR failures:
- Verify the PDF contains readable text (not scanned images)
- Check file size is under 10MB
- Ensure the Document AI processor is properly configured
-
AI response errors:
- Verify Vertex AI API is enabled in your project
- Check that the location supports Gemini models
- Ensure sufficient quotas for API usage
To run in development mode with detailed error logging:
npm run dev- Fork the repository
- Create a feature branch
- Make your changes
- Test thoroughly
- Submit a pull request
This project is licensed under the MIT License.