LungsCareAI is a comprehensive, full-stack AI-powered medical diagnostic system for lung disease detection and analysis. It combines advanced deep learning models with RAG (Retrieval-Augmented Generation) technology to provide intelligent medical insights through both lung audio analysis and chest X-ray classification.
- Binary Classification: Normal vs Abnormal lung sounds
- XAI (Explainable AI): Gradient saliency and attention rollout visualizations
- Model: Fine-tuned Audio Spectrogram Transformer (AST)
- Supported Formats: WAV, MP3, M4A, FLAC
- Multi-class Classification: 10 lung conditions
- Control (Normal)
- COVID-19
- Pleural Effusion
- Lung Opacity
- Mass
- Nodule
- Pneumonia
- Pneumothorax
- Pulmonary Fibrosis
- Tuberculosis
- Advanced Preprocessing: CLAHE + GFB colormap enhancement
- Visualization: 4-panel analysis with confidence scores
- Supported Formats: JPG, PNG, BMP, TIFF
- 17,000+ Medical Q&A knowledge base
- Context-Aware Chat: Patient-specific information retrieval
- Multi-language: English and Urdu support
- LLM: Google Gemini 2.0 Flash
- Automated PDF Generation: Medical-grade reports
- AI-Generated Summaries: Concise clinical insights
- Integrated Visualizations: XAI heatmaps and analysis
- Patient History Tracking: Complete analysis records
- Registration System: Demographics and patient tracking
- Report History: All analyses linked to patient records
- Multi-patient Support: Manage multiple patients
- Python 3.8+
- Node.js 16+
- Docker (for Qdrant vector database)
- Google Gemini API Key (Get one here)
-
Clone the repository
git clone https://github.com/aunraza19/LungsCareAI.git cd LungsCareAI -
Download ML Models
Due to GitHub's file size limitations, download the models separately:
- Audio Model (
final_model_ast (1).pt- ~350MB) - X-ray Model (
final_model.keras- ~100MB)
Download Instructions:
- See MODELS.md for detailed download options
- Upload to Google Drive, Hugging Face, or use Git LFS
- Place both model files in the project root directory
- Audio Model (
-
Set up environment variables
cp .env.example .env # Edit .env and add your GEMINI_API_KEY -
Backend Setup
cd backend python -m venv venv # Windows venv\Scripts\activate # Linux/Mac source venv/bin/activate pip install -r requirements.txt
-
Frontend Setup
cd frontend npm install -
Start Qdrant Vector Database
Windows:
.\start_qdrant.ps1
Linux/Mac:
docker run -d -p 6333:6333 -v $(pwd)/qdrant_storage:/qdrant/storage qdrant/qdrantπ For detailed Qdrant setup instructions, see QDRANT_SETUP.md
Option 1: Using automated scripts
Windows:
run_webapp_demo.batLinux/Mac:
chmod +x run_webapp_demo.sh
./run_webapp_demo.shOption 2: Manual start
Terminal 1 - Backend:
cd backend
source venv/bin/activate # or venv\Scripts\activate on Windows
uvicorn app:app --reload --host 0.0.0.0 --port 8000Terminal 2 - Frontend:
cd frontend
npm run devTerminal 3 - Qdrant:
docker run -p 6333:6333 qdrant/qdrantAccess the application:
- Frontend: http://localhost:3000
- Backend API: http://localhost:8000
- API Docs: http://localhost:8000/docs
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Frontend (React) β
β ββββββββββββ¬βββββββββββ¬βββββββββββ¬βββββββββββ¬βββββββββββ β
β β Home β Register β Audio β X-ray β Chat β β
β ββββββββββββ΄βββββββββββ΄βββββββββββ΄βββββββββββ΄βββββββββββ β
ββββββββββββββββββββββββββ¬βββββββββββββββββββββββββββββββββββββ
β REST API
ββββββββββββββββββββββββββΌβββββββββββββββββββββββββββββββββββββ
β Backend (FastAPI) β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β Audio Analysis β X-ray Analysis β RAG Chat β β
β β (AST Model) β (Custom CNN) β (Gemini) β β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β Patient Manager β Report Generator β β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
ββββββββββββββββββββββββββ¬βββββββββββββββββββββββββββββββββββββ
β
ββββββββββββββββΌβββββββββββββββ
β β β
βΌ βΌ βΌ
ββββββββββββ ββββββββββββ ββββββββββββ
β Models β β Qdrant β β Files β
β (.pt, β β Vector β β (JSON, β
β .keras) β β DB β β PDF) β
ββββββββββββ ββββββββββββ ββββββββββββ
- Framework: FastAPI
- ML: PyTorch, TensorFlow/Keras, Transformers
- RAG: LangChain, Qdrant, SentenceTransformers
- LLM: Google Gemini 2.0 Flash
- Image Processing: OpenCV, Pillow
- Audio Processing: torchaudio, librosa
- Reports: ReportLab
- Framework: React 18 + TypeScript
- Build Tool: Vite
- UI: Material-UI (MUI) v5
- State: React Query
- Routing: React Router v6
- File Upload: React Dropzone
- Vector DB: Qdrant
- Patient Data: JSON (upgradable to PostgreSQL)
LungsCareAI/
βββ backend/
β βββ app.py # FastAPI server
β βββ requirements.txt # Python dependencies
β βββ logo.png # Report logo
β βββ patient_records.json # Patient database
βββ frontend/
β βββ src/
β β βββ App.tsx
β β βββ pages/ # React pages
β β βββ components/ # React components
β βββ package.json
β βββ vite.config.ts
βββ inf.py # Audio analysis module
βββ xray_tools.py # X-ray analysis module
βββ rag.py # RAG system & reports
βββ final_model_ast (1).pt # Audio model (download separately)
βββ final_model.keras # X-ray model (download separately)
βββ inv_class_indices.json # X-ray class labels
βββ medical_meadow_*.json # Medical knowledge base
βββ Green Fire Blue (1).lut # X-ray colormap
βββ .env.example # Environment template
βββ .gitignore
βββ README.md
GEMINI_API_KEY=your_gemini_api_key_here- Host: 0.0.0.0
- Port: 8000
- CORS: Enabled for localhost:3000
- Port: 3000
- Proxy: API requests proxied to localhost:8000
Once the backend is running, visit:
- Swagger UI: http://localhost:8000/docs
- ReDoc: http://localhost:8000/redoc
Patient Management
POST /api/patients/register- Register new patientGET /api/patients- List all patients
Audio Analysis
POST /api/analyze/audio/basicPOST /api/analyze/audio/gradientPOST /api/analyze/audio/attention
X-ray Analysis
POST /api/analyze/xray/basicPOST /api/analyze/xray/visualization
AI Chat
POST /api/chat
Navigate to Patient Registration and fill in patient details.
- Go to Audio Analysis or X-ray Analysis
- Select the patient from dropdown
- Upload audio file or X-ray image
- Choose analysis type
- Classification with confidence score
- Detailed medical analysis (RAG-powered)
- Download PDF report
- View XAI visualizations
- Select patient (optional)
- Choose language
- Ask medical questions
- Get context-aware responses
- View all patient reports
- Download PDFs
- Access XAI visualizations
Sample medical files are included in the examples/ folder:
- Audio:
examples/H005_R4.wav - X-ray:
examples/covid00186.jpg,examples/fib.jpeg,examples/pn1.jpeg,examples/xray.jpeg
- Register a test patient
- Analyze sample audio file
- Analyze sample X-ray image
- Check generated reports
- Test chatbot with medical questions
This system is for research and educational purposes only. It is NOT FDA approved and should NOT be used for actual medical diagnosis without oversight from qualified healthcare professionals.
- Production: Implement authentication (JWT)
- Data: Encrypt sensitive patient information
- Database: Use PostgreSQL instead of JSON
- Compliance: Follow HIPAA/medical data regulations
- API Keys: Never commit .env file to version control
The ML models are not included in the repository due to size constraints. Download them separately:
- Audio Model: ~350MB
- X-ray Model: ~100MB
Contributions are welcome! Please follow these steps:
- Fork the repository
- Create a feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
- Follow PEP 8 for Python code
- Use TypeScript strict mode
- Add comments for complex logic
- Write unit tests for new features
- Update documentation
This project is licensed under the MIT License - see the LICENSE file for details.
- MIT AST Model for audio analysis
- Medical Meadow Dataset for knowledge base
- Google Gemini for LLM capabilities
- Qdrant for vector database
- LangChain for RAG framework
- Material-UI for React components
Project Maintainer: @aunraza19
- GitHub: @aunraza19
- Repository: LungsCareAI
- Mobile app (React Native)
- Real-time audio streaming analysis
- DICOM support
- Multi-user authentication
- Advanced analytics dashboard
- Treatment tracking
- Appointment scheduling
- Multi-language expansion
- Model fine-tuning interface
- Integration with EHR systems
- Audio Analysis: ~3-5 seconds
- X-ray Analysis: ~2-4 seconds
- Report Generation: ~1-2 seconds
- Chat Response: ~2-3 seconds
- Model caching for fast inference
- GPU acceleration support
- HNSW vector indexing
- Async processing
- Large model files require separate download
- Qdrant must be running before backend
- First analysis takes longer (model loading)
- Limited to English/Urdu languages
See Issues for full list.
Made with β€οΈ for advancing AI in healthcare
