This repository contains Python-based machine learning microservices for the CrimeLinkAnalyzer application.
Analyzes call records from PDF files to identify patterns, build network graphs, and match against criminal database.
Features:
- PDF parsing with multiple format support
- Network graph generation using NetworkX
- Call pattern analysis (frequency, time patterns, common contacts)
- Criminal database matching
- Risk score calculation
Endpoints:
GET /health- Health checkPOST /analyze- Upload PDF and analyze call recordsGET /results/<analysis_id>- Get analysis resultsGET /results- List all results
Coming soon - Will integrate with custom Asian face recognition model
- Python 3.9+
- pip
- PostgreSQL database access
- Install dependencies:
cd call_analysis_service
pip install -r requirements.txt- Configure environment:
cp .env.example .env
# Edit .env with your database credentials- Run the service:
python app.pyThe service will start on http://localhost:5001
curl -X POST http://localhost:5001/analyze \
-F "file=@sample_call_records.pdf"curl http://localhost:5001/healthThe parser supports multiple call record formats:
Format 1:
2024-01-15 10:30:45 | +94771234567 | Outgoing | 00:05:23
Format 2:
15/01/2024 10:30 +94771234567 OUT 5m 23s
Format 3:
15-01-2024 10:30, +94771234567, Outgoing, 00:05:23
The Spring Boot backend calls these services via REST API:
RestTemplate restTemplate = new RestTemplate();
String pythonServiceUrl = "http://localhost:5001/analyze";
ResponseEntity<Map> response = restTemplate.postForEntity(
pythonServiceUrl,
fileData,
Map.class
);The service interacts with these tables:
- id (VARCHAR PRIMARY KEY)
- name (VARCHAR)
- nic (VARCHAR)
- contact_number (VARCHAR)
- secondary_contact (VARCHAR)
- id (VARCHAR PRIMARY KEY)
- file_name (VARCHAR)
- analysis_data (JSONB)
- risk_score (INTEGER)
- created_at (TIMESTAMP)
call_analysis_service/
├── app.py # Flask application
├── requirements.txt # Python dependencies
├── .env.example # Environment configuration
├── uploads/ # Uploaded PDF files
├── results/ # Analysis results
└── utils/
├── pdf_parser.py # PDF parsing logic
├── network_analyzer.py # Network graph analysis
└── database.py # Database operations
docker build -t crimelink-call-analysis .
docker run -p 5001:5001 --env-file .env crimelink-call-analysis- Use Redis for result caching instead of in-memory storage
- Implement rate limiting
- Add authentication/API keys
- Use Celery for async processing of large files
- Set up monitoring and logging
- Use environment-specific configurations
Proprietary - Crime Link Analyzer System