Spaces:
Runtime error
Runtime error
Document Intelligence System - Quick Start Guide
π Getting Started in 5 Minutes
Option 1: Local Installation (Using Python)
Step 1: Install Dependencies
# Install Python dependencies
pip install -r requirements.txt
# Install Tesseract OCR
# Windows: Download from https://github.com/UB-Mannheim/tesseract/wiki
# Linux: sudo apt-get install tesseract-ocr
# macOS: brew install tesseract
Step 2: Run the Application
# Start the API server
python main.py
Step 3: Access Dashboard
Open your browser and go to:
http://localhost:8000/dashboard
Option 2: Docker Installation
Step 1: Build and Run
# Using Docker Compose (recommended)
docker-compose up -d
# Or using Docker directly
docker build -t doc-intelligence .
docker run -p 8000:8000 doc-intelligence
Step 2: Access Dashboard
http://localhost:8000/dashboard
π Usage Examples
1. Extract Data from Text
Via Dashboard
- Go to the "Extract from Text" card
- Paste your document text
- Click "Extract Data"
- View results
Via API
curl -X POST "http://localhost:8000/extract" \
-H "Content-Type: application/json" \
-d '{
"text": "Invoice #123 Amount Due: $500"
}'
Via Python
import asyncio
from app.pipeline import DocumentProcessingPipeline
async def main():
pipeline = DocumentProcessingPipeline()
result = await pipeline.process_document(
document_id="doc_001",
text="Your document text here"
)
print(result.classification.document_type)
print(result.extraction.extracted_fields)
asyncio.run(main())
2. Upload Document
Via Dashboard
- Click "Upload Document" card
- Select a file (image, PDF, or text)
- System processes automatically
- View results in "Results" tab
Via API
curl -X POST "http://localhost:8000/upload" \
-F "file=@document.pdf"
3. Batch Processing
Via API
curl -X POST "http://localhost:8000/batch" \
-H "Content-Type: application/json" \
-d '{
"documents": [
{"text": "Document 1 text"},
{"text": "Document 2 text"},
{"text": "Document 3 text"}
]
}'
Via Python
documents = [
{"id": "doc_1", "text": "Invoice text..."},
{"id": "doc_2", "text": "Receipt text..."}
]
results = asyncio.run(pipeline.process_batch(documents))
stats = pipeline.get_statistics(results)
print(stats)
π Interactive Dashboard Features
Features Available
- β Upload Documents - Upload images, PDFs, or text files
- β Extract Data - Extract structured data from text
- β View Results - See extraction and validation results in real-time
- β Monitor Jobs - Track processing jobs and their status
- β View Statistics - Monitor system performance
- β API Documentation - Browse available endpoints
Navigation
| Tab | Purpose |
|---|---|
| Results | View processing results |
| Jobs | Monitor active and completed jobs |
| API Docs | View API endpoint documentation |
π How It Works
Processing Pipeline
Document Input
β
[OCR] Extract text from images
β
[Classify] Determine document type
β
[Extract] Pull out structured data
β
[Validate] Check data quality
β
Results & Insights
Example: Processing an Invoice
- Input: Invoice image or text
- Classification: "invoice" (95% confidence)
- Extraction:
- Invoice Number: INV-2024-001
- Date: 01/15/2024
- Amount: $500.00
- Vendor: Acme Corp
- Validation:
- All required fields present β
- Data format correct β
- Quality score: 92%
- Output: Structured JSON with confidence scores
π― Supported Document Types
- Invoice - Bill, sales invoice, receipt
- Receipt - Purchase receipt, transaction record
- Contract - Legal agreement, terms & conditions
- Report - Business report, analysis
- Email - Email message, correspondence
- Form - Application, questionnaire
- Letter - Business letter, notification
βοΈ Configuration
Environment Variables
Create a .env file in the root directory:
# API Configuration
API_HOST=0.0.0.0
API_PORT=8000
DEBUG=false
# Database
DATABASE_URL=sqlite:///./documents.db
# OCR Settings
OCR_LANG=eng
OCR_PSM=3
# File Upload
UPLOAD_DIR=./uploads
MAX_FILE_SIZE=52428800
# Logging
LOG_LEVEL=INFO
For Production
# Use PostgreSQL instead of SQLite
DATABASE_URL=postgresql://user:password@localhost/doc_intelligence
# Use Redis for caching
REDIS_URL=redis://localhost:6379
# Enable CORS
ENABLE_CORS=true
# Disable debug mode
DEBUG=false
π§ͺ Testing
Run Examples
python examples.py
This will:
- β Process a single invoice document
- β Batch process multiple documents
- β Demonstrate custom field extraction
- β Show validation results
Check Health
curl http://localhost:8000/health
π API Endpoints
| Method | Endpoint | Purpose |
|---|---|---|
| GET | / |
API information |
| GET | /health |
Health check |
| POST | /upload |
Upload document file |
| POST | /extract |
Extract from text |
| POST | /batch |
Batch process documents |
| GET | /jobs |
List all jobs |
| GET | /jobs/{job_id} |
Get job status |
| GET | /stats |
System statistics |
| GET | /dashboard |
Web dashboard |
π³ Docker-Compose Services
The included docker-compose.yml sets up:
- App - Main FastAPI application (port 8000)
- PostgreSQL - Database (port 5432)
- Redis - Cache/Queue (port 6379)
Start All Services
docker-compose up -d
View Logs
docker-compose logs -f app
Stop Services
docker-compose down
π Project Structure
Agentic-Doc-Intelligence/
βββ agents/
β βββ classifier.py # Document classification
β βββ extractor.py # Data extraction
β βββ validator.py # Data validation
βββ tools/
β βββ ocr_engine.py # OCR processing
β βββ table_parser.py # Table extraction
βββ app/
β βββ pipeline.py # Main pipeline
β βββ main.py # FastAPI app
β βββ README.md # Documentation
βββ database.py # Database models
βββ settings.py # Configuration
βββ utils.py # Utilities
βββ examples.py # Usage examples
βββ requirements.txt # Dependencies
βββ Dockerfile # Docker image
βββ docker-compose.yml # Docker services
βββ .env.example # Environment template
π¨ Troubleshooting
"Tesseract not found" Error
Solution: Install Tesseract OCR
- Windows: Download installer from GitHub
- Linux:
sudo apt-get install tesseract-ocr - macOS:
brew install tesseract
"Port 8000 already in use" Error
Solution: Change port in settings or stop the service using port 8000
Low OCR Accuracy
Tips:
- Ensure image resolution is at least 150 DPI
- Keep documents upright and well-lit
- Use PNG or TIFF formats
- Remove noise/shadows if possible
Database Errors
Solution: Reset the database
rm documents.db
python database.py
π Additional Resources
π Learning Path
- Start with the Dashboard to familiarize yourself
- Run examples.py to see different capabilities
- Try the API using curl or Python
- Explore the source code to understand the architecture
- Customize for your use case with custom fields and schemas
π‘ Tips & Tricks
- Batch Processing: Process multiple documents at once for efficiency
- Custom Fields: Define extraction patterns for your specific needs
- Validation Schemas: Create custom validation rules
- Caching: Enable Redis for faster repeated processing
- Database: Upgrade to PostgreSQL for production use
π Support
For issues or questions:
- Check the detailed README
- Review examples.py
- Check API documentation at
/docs
Ready to process documents? π
Start the application and go to: http://localhost:8000/dashboard