This application provides an intelligent document processing system that leverages CrewAI to orchestrate OCR and AI services for analyzing uploaded documents, automatically classifying them, and extracting relevant information.
- Document upload with drag & drop interface
- Real-time processing pipeline visualization
- CrewAI agent-based orchestration
- Intelligent service selection based on document type
- Detailed results display with confidence scores
- Status indicators showing processing progress
This project consists of two main parts:
- Frontend: A React application with a user-friendly interface for document upload and visualization
- Backend: A Python FastAPI service with CrewAI that handles document processing using various OCR and AI services
The system uses CrewAI to create a team of specialized AI agents that work together to process documents:
- Document Classifier Agent - Determines document type and structure
- OCR Specialist Agent - Extracts text using the appropriate OCR service
- Document Analyzer Agent - Analyzes content and extracts structured information
These agents work together in a sequential process to handle document processing tasks, providing a clear separation of concerns and specialized expertise for each task.
The frontend is a React application with Vite and Tailwind CSS.
Create a .env file in the root directory with the following variables:
VITE_OCR_API_ENDPOINT=http://localhost:8000/api/document-upload
# Install dependencies
npm install
# Run development server
npm run dev
# Build for production
npm run buildThe backend is located in the backend/ directory and is built with Python, FastAPI, and CrewAI.
- Python 3.8+
- Google Cloud account with Vision API enabled
- Azure account with Computer Vision and OpenAI services
-
Navigate to the backend directory:
cd backend -
Create a virtual environment:
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install dependencies:
pip install -r requirements.txt
-
Copy
.env.exampleto.envand fill in your API credentials
python app.pyOr with uvicorn directly:
uvicorn app:app --reload --host 0.0.0.0 --port 8000- Create a Google Cloud account and project at https://cloud.google.com/
- Enable the Vision API for your project
- Create an API key with appropriate permissions
- Add the API key to your backend
.envfile asGOOGLE_CLOUD_API_KEY
Alternatively, you can use a service account:
- Create a service account in the Google Cloud Console
- Download the JSON credentials file
- Either set the path to this file in your
.envasGOOGLE_APPLICATION_CREDENTIALSor include the JSON content directly asGOOGLE_CLOUD_CREDENTIALS_JSON
- Create an Azure account at https://azure.microsoft.com/
- Create a Computer Vision resource in the Azure portal
- Get your API key and endpoint URL from the resource overview
- Add these credentials to your backend
.envfile asAZURE_OCR_ENDPOINTandAZURE_OCR_KEY
- Apply for access to Azure OpenAI Service
- Create an Azure OpenAI resource in the Azure portal
- Deploy a model in the Azure OpenAI Studio
- Get your API key, endpoint URL, and deployment name
- Add these credentials to your backend
.envfile as:AZURE_OPENAI_ENDPOINTAZURE_OPENAI_KEYAZURE_OPENAI_DEPLOYMENT_NAMEAZURE_OPENAI_API_VERSION(default is 2023-05-15)
Uploads and processes documents using the CrewAI orchestrator.
Request:
- Form data with files under the key "files"
Response:
{
"success": true,
"results": [
{
"fileName": "invoice.pdf",
"fileType": "application/pdf",
"classification": {
"documentType": "Invoice",
"confidence": 95.5,
"service": "CrewAI + Azure OpenAI"
},
"extractedText": "...",
"analysis": {
"extractedData": {
"invoiceNumber": {
"value": "INV-2023-0042",
"confidence": 98
},
"date": {
"value": "2023-05-15",
"confidence": 95
},
"totalAmount": {
"value": "$1,245.00",
"confidence": 92
}
},
"confidence": 95,
"documentType": "Invoice"
},
"confidence": 95
}
]
}Health check endpoint.
Response:
{
"status": "healthy"
}Check the status of all integrated services.
Response:
{
"google_cloud_vision": "available",
"azure_ocr": "available",
"azure_openai": "available",
"crewai": "operational"
}You can deploy the backend using Docker:
cd backend
docker build -t document-processing-api .
docker run -p 8000:8000 --env-file .env document-processing-apiTo customize how the application processes documents:
- Edit the
backend/services/crewai_orchestrator.pyfile to modify the agent definitions and tasks - Update the document classification logic in
backend/utils/document_classifier.py - Adjust the service selection logic in the CrewAI orchestrator
MIT