A sophisticated medical diagnosis assistant powered by machine learning and natural language processing. MedBot helps identify potential diseases based on patient symptoms, providing explainable predictions using SHAP (SHapley Additive exPlanations) for transparency and trust.
-
π€ Natural Language Processing
- Understands symptom descriptions in natural language
- Handles complex medical terminology
- Supports multiple languages (English)
-
π Comprehensive Symptom Extraction
- Identifies multiple symptoms from text descriptions
- Handles medical and common terminology
- Supports symptom severity and duration
-
π₯ Disease Prediction
- Accurate disease prediction based on symptoms
- Confidence scoring for predictions
- Support for multiple disease categories
-
π Explainable AI
- Detailed SHAP-based explanations
- Visual interpretation of predictions
- Feature importance analysis
-
π Visualization
- SHAP summary plots
- Waterfall plots for individual predictions
- Interactive feature importance charts
medbot/
βββ data/
β βββ raw/ # Original dataset
β βββ processed/ # Processed data files
βββ models/
β βββ saved_models/ # Trained model files
βββ nlp/ # Natural Language Processing modules
βββ explainable_ai/ # Explainable AI components
βββ tests/ # Test files
βββ docs/ # Documentation and visualizations
- Clone the repository:
git clone https://github.com/Thorne-Musau/medbot.git
cd medbot- Create and activate a virtual environment:
python -m venv medbot_env
# On Windows
medbot_env\Scripts\activate
# On Unix or MacOS
source medbot_env/bin/activate- Install dependencies:
pip install -r requirements.txtfrom nlp import IntentClassifier, ComprehensiveSymptomExtractor
from explainable_ai import XAIPipeline
# Initialize components
classifier = IntentClassifier()
extractor = ComprehensiveSymptomExtractor()
xai_pipeline = XAIPipeline()
# Process user input
user_input = "I have a severe headache and fever"
intent = classifier.classify_intent(user_input)
if intent == "symptom_report":
# Extract symptoms
symptoms = extractor.extract_symptoms(user_input)
# Get prediction and explanation
prediction, explanation, visualization = xai_pipeline.explain_prediction(symptoms)
print(f"Predicted Condition: {prediction}")
print("\nExplanation:")
print(explanation)python -m unittest discover tests-
Intent Classification
- Pre-trained model for symptom reporting intent
- Natural language understanding
- Context-aware classification
-
Symptom Extraction
- Pattern matching algorithms
- Medical term mapping
- Context analysis
-
Disease Prediction
- Random Forest classifier
- Multi-class classification
- Probability scoring
-
Explanation Generation
- SHAP value calculation
- Feature importance analysis
- Visual explanation generation
We welcome contributions! 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 style guide
- Write clear, descriptive commit messages
- Include tests for new features
- Update documentation as needed
This project is licensed under the MIT License - see the LICENSE file for details.
- Dataset Source: [Source Name]
- SHAP Library: For explainable AI capabilities
- Medical Resources: For terminology and symptom mappings
- Contributors: All who have helped improve this project
- GitHub Issues: Open an issue
- Email: [Your Email]
- Project Link: https://github.com/Thorne-Musau/medbot
Made with β€οΈ by Thorne Musau
A FastAPI-based backend for the MedBot system, providing endpoints for user authentication, chat interactions, and disease diagnosis.
- User authentication and management
- Chat conversation handling
- Disease diagnosis using ML model
- Conversation history tracking
- Diagnosis history tracking
- Python 3.8+
- PostgreSQL (optional, SQLite by default)
- Trained ML model and associated files
- Clone the repository:
git clone https://github.com/yourusername/medbot.git
cd medbot- Create and activate a 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:
Create a
.envfile in the project root with:
DATABASE_URL=sqlite:///./medbot.db # Or your PostgreSQL URL
SECRET_KEY=your-secret-key-here
- Initialize the database:
alembic upgrade headmedbot/
βββ api/
β βββ app.py # FastAPI application
β βββ database.py # Database configuration
β βββ models/ # Pydantic and SQLAlchemy models
β βββ routes/ # API endpoints
β βββ auth/ # Authentication utilities
β βββ ml/ # ML model integration
βββ models/
β βββ saved_models/ # Trained ML models
βββ data/
β βββ processed/ # Processed data files
βββ alembic/ # Database migrations
βββ tests/ # Test files
βββ requirements.txt # Project dependencies
βββ README.md # This file
- Start the server:
uvicorn api.app:app --reload- Access the API documentation:
- Swagger UI: http://localhost:8000/docs
- ReDoc: http://localhost:8000/redoc
- POST
/auth/register- Register a new user - POST
/auth/token- Login and get access token
- POST
/conversations- Create a new conversation - GET
/conversations- List user's conversations - GET
/conversations/{id}- Get conversation details - POST
/chat- Send a message and get response
- POST
/diagnose- Get diagnosis for symptoms - GET
/diagnoses- List user's diagnosis history - GET
/diagnoses/{id}- Get diagnosis details
Run the test suite:
pytest- Fork the repository
- Create a feature branch
- Commit your changes
- Push to the branch
- Create a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.