Spaces:
Paused
Paused
HNTAI - Medical Data Extraction & AI Processing Platform
A comprehensive, scalable AI platform for medical data extraction, processing, and analysis. Built with FastAPI, supporting multiple AI model backends including Transformers, OpenVINO, and GGUF models with automatic GPU/CPU optimization.
π₯ Overview
HNTAI is a production-ready medical AI platform that provides:
- Medical Document Processing: PDF, DOCX, image, and audio transcription
- Protected Health Information (PHI) Scrubbing: HIPAA-compliant data anonymization
- AI-Powered Summarization: Multi-model support with automatic device optimization
- Patient Summary Generation: Comprehensive clinical assessments
- Scalable Architecture: Kubernetes-ready with monitoring and security features
π Key Features
π€ Multi-Model AI Support
- Transformers Models: Hugging Face models with automatic GPU/CPU detection
- OpenVINO Optimization: Intel-optimized models for production performance
- GGUF Models: Quantized models for efficient inference
- Automatic Device Selection: GPU when available, CPU fallback
- Model Caching: Intelligent model management and caching
π Document Processing
- Multi-format Support: PDF, DOCX, images, audio files
- OCR Integration: Tesseract-based text extraction
- Audio Transcription: Whisper-based speech-to-text
- Batch Processing: Async processing for scalability
π Security & Compliance
- HIPAA Compliance: PHI scrubbing with audit logging
- Data Encryption: Secure data handling and storage
- Audit Trails: Comprehensive logging for compliance
- Non-root Containers: Security-hardened deployments
π Monitoring & Observability
- Health Endpoints:
/health/live,/health/ready - Prometheus Metrics:
/metricsendpoint - Structured Logging: Comprehensive application monitoring
- Performance Tracking: Model inference metrics
ποΈ Architecture
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β FastAPI β β AI Models β β PostgreSQL β
β Web Server βββββΊβ (Multi-backend)β β Database β
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β β β
βΌ βΌ βΌ
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β Redis Cache β β File Storage β β Audit Logs β
β (PHI Stats) β β (Documents) β β (Compliance) β
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
π οΈ Installation
Prerequisites
- Python 3.11+
- CUDA 11.8+ (for GPU support)
- Docker (for containerized deployment)
- PostgreSQL 13+
- Redis 6+
Local Development
- Clone the repository:
git clone <repository-url>
cd HNTAI
- Create virtual environment:
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
- Install dependencies:
pip install -r requirements.txt
- Set up environment variables:
export DATABASE_URL="postgresql://user:password@localhost:5432/hntai"
export REDIS_URL="redis://localhost:6379"
export SECRET_KEY="your-secret-key"
export JWT_SECRET_KEY="your-jwt-secret"
export HF_HOME="/tmp/huggingface"
- Run the application:
# Development server
python -m uvicorn services.ai-service.src.ai_med_extract.main:app --reload --host 0.0.0.0 --port 7860
# Or using the service directly
cd services/ai-service
python src/ai_med_extract/main.py
Docker Deployment
- Build the image:
docker build -t hntai:latest .
- Run with Docker Compose:
docker-compose up -d
Kubernetes Deployment
- Apply Kubernetes manifests:
kubectl apply -f infra/k8s/secure_deployment.yaml
- Check deployment status:
kubectl get pods -l app=hntai
π API Documentation
Core Endpoints
Health & Monitoring
GET /health/live- Liveness probeGET /health/ready- Readiness probeGET /metrics- Prometheus metrics
Document Processing
POST /upload- Upload and process documentsPOST /transcribe- Transcribe audio filesGET /get_updated_medical_data- Retrieve processed dataPUT /update_medical_data- Update medical data
AI Processing
POST /generate_patient_summary- Generate comprehensive patient summariesPOST /api/generate_summary- Generate text summariesPOST /api/patient_summary_openvino- OpenVINO-optimized summariesPOST /extract_medical_data- Extract structured medical data
Model Management
POST /api/load_model- Load specific AI modelsGET /api/model_info- Get model informationPOST /api/switch_model- Switch between models
π€ AI Model Configuration
Supported Model Types
1. Transformers Models
{
"model_name": "microsoft/Phi-3-mini-4k-instruct",
"model_type": "text-generation"
}
2. OpenVINO Models
{
"model_name": "OpenVINO/Phi-3-mini-4k-instruct-fp16-ov",
"model_type": "openvino"
}
3. GGUF Models
{
"model_name": "microsoft/Phi-3-mini-4k-instruct-gguf",
"model_type": "gguf"
}
Automatic Device Detection
The system automatically detects and uses:
- GPU: When CUDA is available
- CPU: Fallback when GPU is not available
- Optimization: Intel OpenVINO for production performance
π§ Configuration
Environment Variables
| Variable | Description | Default |
|---|---|---|
DATABASE_URL |
PostgreSQL connection string | Required |
REDIS_URL |
Redis connection string | Required |
SECRET_KEY |
Application secret key | Required |
JWT_SECRET_KEY |
JWT signing key | Required |
HF_HOME |
Hugging Face cache directory | /tmp/huggingface |
TORCH_HOME |
PyTorch cache directory | /tmp/torch |
WHISPER_CACHE |
Whisper model cache | /tmp/whisper |
HF_SPACES |
Hugging Face Spaces mode | false |
PRELOAD_GGUF |
Preload GGUF models | false |
Model Configuration
The system supports flexible model configuration through model_config.py:
# Default models for different tasks
DEFAULT_MODELS = {
"text-generation": {
"primary": "microsoft/Phi-3-mini-4k-instruct",
"fallback": "facebook/bart-base"
},
"openvino": {
"primary": "OpenVINO/Phi-3-mini-4k-instruct-fp16-ov",
"fallback": "microsoft/Phi-3-mini-4k-instruct"
},
"gguf": {
"primary": "microsoft/Phi-3-mini-4k-instruct-gguf",
"fallback": "microsoft/Phi-3-mini-4k-instruct-gguf"
}
}
π§ͺ Testing
Run Tests
# Unit tests
python -m pytest tests/
# Smoke test (no model loading)
cd services/ai-service
python run_smoke_test.py
# Integration tests
python -m pytest tests/integration/
Code Quality
# Format code
black .
isort .
# Lint code
flake8 .
mypy .
# Type checking
mypy services/ai-service/src/ai_med_extract/
π Monitoring
Health Checks
- Liveness:
GET /health/live- Application is running - Readiness:
GET /health/ready- Application is ready to serve requests
Metrics
- Prometheus:
GET /metrics- Application and model metrics - Custom Metrics: Model inference time, success rates, error rates
Logging
- Structured Logging: JSON-formatted logs
- Audit Trails: PHI access and modification logs
- Performance Logs: Model loading and inference timing
π Security Features
HIPAA Compliance
- PHI Scrubbing: Automatic removal of protected health information
- Audit Logging: Comprehensive access and modification logs
- Data Encryption: Secure data handling and storage
- Access Controls: Role-based access to sensitive data
Container Security
- Non-root Containers: Security-hardened container images
- Resource Limits: CPU and memory limits
- Network Policies: Secure network communication
- Secrets Management: Secure handling of sensitive configuration
π Deployment Options
1. Local Development
python -m uvicorn services.ai-service.src.ai_med_extract.main:app --reload
2. Docker
docker run -p 7860:7860 hntai:latest
3. Kubernetes
kubectl apply -f infra/k8s/secure_deployment.yaml
4. Hugging Face Spaces
# Configure for HF Spaces
export HF_SPACES=true
python start_hf_spaces.py
π Project Structure
HNTAI/
βββ services/
β βββ ai-service/
β βββ src/ai_med_extract/
β β βββ agents/ # AI agents and processors
β β βββ api/ # FastAPI routes and management
β β βββ utils/ # Utilities and model management
β β βββ app.py # Main application
β β βββ main.py # Application entry point
β βββ docker-compose.yml # Docker services
β βββ Dockerfile # Container image
βββ infra/
β βββ k8s/ # Kubernetes manifests
βββ monitoring/
β βββ prometheus.yml # Monitoring configuration
βββ database/
β βββ postgresql/ # Database schemas
βββ requirements.txt # Python dependencies
π€ Contributing
- Fork the repository
- Create a feature branch:
git checkout -b feature/amazing-feature - Make your changes
- Run tests:
python -m pytest - Commit changes:
git commit -m 'Add amazing feature' - Push to branch:
git push origin feature/amazing-feature - Open a Pull Request
π License
This project is licensed under the MIT License - see the LICENSE file for details.
π Support
- Documentation: Check the
/docsendpoint for interactive API documentation - Issues: Report bugs and feature requests via GitHub Issues
- Discussions: Join community discussions for questions and support
π Changelog
Latest Updates
- β Fixed OpenVINO GPU/CPU auto-detection
- β Improved model loading with fallback mechanisms
- β Enhanced security and HIPAA compliance
- β Added comprehensive monitoring and health checks
- β Optimized for production deployment
Built with β€οΈ for the medical AI community