Skip to content

Thorne-Musau/medbot

Repository files navigation

πŸ₯ MedBot - Medical Diagnosis Assistant

Python Version License Code Style Tests

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.

🌟 Key Features

  • πŸ€– 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

πŸ“ Project Structure

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

πŸš€ Installation

  1. Clone the repository:
git clone https://github.com/Thorne-Musau/medbot.git
cd medbot
  1. 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
  1. Install dependencies:
pip install -r requirements.txt

πŸ’» Usage

Basic Usage

from 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)

Running Tests

python -m unittest discover tests

🧠 Model Architecture

Components Overview

  • 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

🀝 Contributing

We welcome contributions! Please follow these steps:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

Development Guidelines

  • Follow PEP 8 style guide
  • Write clear, descriptive commit messages
  • Include tests for new features
  • Update documentation as needed

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ™ Acknowledgments

  • 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

πŸ“ž Contact


Made with ❀️ by Thorne Musau

MedBot API

A FastAPI-based backend for the MedBot system, providing endpoints for user authentication, chat interactions, and disease diagnosis.

Features

  • User authentication and management
  • Chat conversation handling
  • Disease diagnosis using ML model
  • Conversation history tracking
  • Diagnosis history tracking

Prerequisites

  • Python 3.8+
  • PostgreSQL (optional, SQLite by default)
  • Trained ML model and associated files

Installation

  1. Clone the repository:
git clone https://github.com/yourusername/medbot.git
cd medbot
  1. Create and activate a virtual environment:
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate
  1. Install dependencies:
pip install -r requirements.txt
  1. Set up environment variables: Create a .env file in the project root with:
DATABASE_URL=sqlite:///./medbot.db  # Or your PostgreSQL URL
SECRET_KEY=your-secret-key-here
  1. Initialize the database:
alembic upgrade head

Project Structure

medbot/
β”œβ”€β”€ 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

Running the API

  1. Start the server:
uvicorn api.app:app --reload
  1. Access the API documentation:

API Endpoints

Authentication

  • POST /auth/register - Register a new user
  • POST /auth/token - Login and get access token

Chat

  • 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

Diagnosis

  • POST /diagnose - Get diagnosis for symptoms
  • GET /diagnoses - List user's diagnosis history
  • GET /diagnoses/{id} - Get diagnosis details

Testing

Run the test suite:

pytest

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Commit your changes
  4. Push to the branch
  5. Create a Pull Request

License

This project is licensed under the MIT License - see the LICENSE file for details.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors