An interactive PDF analysis application that allows users to upload PDF documents and ask questions about their content using AI. The application uses FastAPI for the backend, React for the frontend, and Groq's API for AI-powered question answering.
- PDF document upload and processing
- AI-powered question answering about PDF content
- Real-time chat-like interface
- Toast notifications for system messages
- Document management system
- Responsive user interface
- Mobile-first design with adaptive layout
- TF-IDF based document similarity search
pdf_analyser/
├── backend/
│ ├── app/
│ │ ├── main.py # FastAPI application
│ │ ├── models.py # Database models
│ │ ├── db.py # Database configuration
│ │ └── pdf_utils.py # PDF processing utilities
│ ├── uploads/ # Directory for uploaded PDFs
│ ├── vector_stores/ # Directory for TF-IDF vector stores
│ └── requirements.txt # Backend dependencies
├── frontend/
│ ├── src/
│ │ ├── components/ # React components
│ │ ├── styles/ # CSS styles
│ │ ├── App.jsx # Main application component
│ │ └── main.jsx # Application entry point
│ ├── package.json # Frontend dependencies
│ └── vite.config.js # Vite configuration
└── README.md # Documentation
- Create a Python virtual environment:
cd backend
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate- Install backend dependencies:
pip install -r requirements.txt- Create a
.envfile in the backend directory:
GROQ_API_KEY=your_groq_api_key_here
- Start the FastAPI server:
uvicorn app.main:app --reload --port 8000- Install frontend dependencies:
cd frontend
npm install- Start the development server:
npm run devThe application will be available at http://localhost:5173
- POST
/upload-pdf - Request: Multipart form data with PDF file
- Response:
{
"document_id": "string",
"filename": "string",
"message": "string"
}- POST
/ask-question - Request Body:
{
"question": "string",
"document_id": "string"
}- Response:
{
"answer": "string",
"context": "string"
}- GET
/documents - Response: List of uploaded documents with their IDs
- FastAPI: Provides the REST API endpoints
- SQLAlchemy: Database ORM for document management
- LangChain: Framework for PDF processing and text chunking
- Groq API: AI model for question answering
- TF-IDF Vectorization:
- Uses scikit-learn's TfidfVectorizer for text vectorization
- Implements cosine similarity for document chunk matching
- Stores vectorized chunks for efficient retrieval
- Supports configurable chunk size and overlap
- React: UI framework
- Vite: Build tool and development server
- Axios: HTTP client for API communication
- React Icons: Icon library
- React Markdown: Markdown rendering for AI responses
- The backend uses SQLite database for development
- PDF files are stored in the
uploadsdirectory - TF-IDF vector stores are saved in
vector_storesdirectory - Text is split into chunks using LangChain's RecursiveCharacterTextSplitter
- Document similarity is calculated using cosine similarity
- Vector stores are persisted using Python's pickle format
- Components are organized in the
src/componentsdirectory - Styles are maintained in
src/styles - The application uses custom CSS for styling
- Responsive design with mobile-first approach
- Adaptive layout for different screen sizes
- Build the frontend:
cd frontend
npm run build- Configure the backend for production:
- Set appropriate environment variables
- Use a production-grade database
- Configure CORS settings
- Set up proper security measures
- API keys are stored in environment variables
- File uploads are validated and sanitized
- CORS is configured for security
- Database queries are protected against SQL injection
- File size limits are enforced for uploads
- Add user authentication
- Implement document sharing
- Add support for more file formats
- Enhance error handling and recovery
- Implement caching for better performance
- Optimize TF-IDF vector store for larger documents
- Add dark mode support
- Implement file preview functionality
- Add support for multiple languages
- Consider implementing more advanced vector stores (e.g., FAISS, HNSW)

