Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Latest commit

Β 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Medical AI Diagnostic Assistant

AI-powered preliminary health assessment tool

Python 3.10+ TensorFlow 2.16 FastAPI License


Overview

The Medical AI Diagnostic Assistant is a machine learning-powered application designed to assist in preliminary health assessments. It combines a TensorFlow deep learning model with a rule-based symptom analyzer to provide intelligent diagnostic suggestions based on reported symptoms.

⚠️ DISCLAIMER: This tool is for educational and research purposes only. It is NOT a substitute for professional medical advice, diagnosis, or treatment. Always consult a qualified healthcare provider for medical concerns.


Tech Stack

Component Technology
Language Python 3.10+
Deep Learning TensorFlow / Keras
API Framework FastAPI + Uvicorn
Data Processing NumPy, Pandas, Scikit-learn
Validation Pydantic
Serialization Python Multipart

Features

  • πŸ€– ML-Based Diagnosis: TensorFlow neural network trained to recognize disease patterns from symptom vectors
  • πŸ“‹ Rule-Based Symptom Analysis: Knowledge-engineered symptom-disease mapping for transparent reasoning
  • πŸ”— Dual Engine Architecture: Combines ML predictions with rule-based analysis for robust results
  • πŸ’Š Treatment Recommendations: Evidence-based self-care tips, medication info, and when to seek medical help
  • 🧠 10 Disease Categories: Influenza, Pneumonia, COVID-19, Malaria, Tuberculosis, Hypertension, Anemia, Migraine, Gastritis, Heart Disease
  • 🌐 RESTful API: Well-documented FastAPI endpoints for easy integration
  • πŸ“Š Confidence Scoring: Predictions include probability and confidence levels (high/medium/low)

Project Structure

medical-ai-diagnostic/
β”œβ”€β”€ api.py                      # FastAPI application and route definitions
β”œβ”€β”€ main.py                     # Entry point to run the server
β”œβ”€β”€ config.py                   # Configuration constants and paths
β”œβ”€β”€ requirements.txt            # Python dependencies
β”œβ”€β”€ .gitignore                  # Git ignore rules
β”œβ”€β”€ README.md                   # Project documentation
β”œβ”€β”€ models/
β”‚   β”œβ”€β”€ __init__.py             # Package exports
β”‚   β”œβ”€β”€ diagnosis_model.py      # TensorFlow model definition, training, inference
β”‚   └── symptom_analyzer.py     # Rule-based symptom-disease mapping engine
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ __init__.py             # Package exports
β”‚   β”œβ”€β”€ preprocessing.py        # Data vectorization and encoding utilities
β”‚   β”œβ”€β”€ diagnostic_engine.py    # Orchestrates ML + rule-based diagnosis
β”‚   └── recommendations.py      # Treatment recommendation database and engine
└── tests/                      # Test directory (placeholder)

Installation

Prerequisites

  • Python 3.10 or higher
  • pip (Python package manager)
  • (Optional) GPU with CUDA support for faster TensorFlow training

Steps

# 1. Clone the repository
git clone https://github.com/roohan-514/medical-ai-diagnostic.git
cd medical-ai-diagnostic

# 2. Create and activate a virtual environment
python -m venv venv
# On Windows:
venv\Scripts\activate
# On macOS/Linux:
# source venv/bin/activate

# 3. Install dependencies
pip install -r requirements.txt

# 4. Run the API server
python main.py

The server will start at http://localhost:8000. Visit http://localhost:8000/docs for the interactive Swagger UI.


API Endpoints

GET /health

Health check endpoint.

Response:

{
  "status": "healthy",
  "service": "Medical AI Diagnostic Assistant",
  "version": "1.0.0"
}

POST /predict

Full diagnosis (ML + rule-based analysis) from a list of symptoms.

Request:

{
  "symptoms": ["fever", "cough", "fatigue"]
}

Response:

{
  "rule_based_analysis": {
    "predictions": [
      {
        "disease": "Influenza",
        "probability": 0.3333,
        "matched_symptoms": ["fever", "cough", "fatigue"],
        "symptom_count": 3
      }
    ],
    "total_symptoms_analyzed": 3,
    "diseases_considered": 10
  },
  "ml_based_analysis": {
    "predictions": [
      {
        "disease": "Influenza",
        "probability": 0.8921,
        "confidence": "high"
      }
    ],
    "model_used": "tensorflow"
  },
  "disclaimer": "..."
}

POST /analyze-symptoms

Rule-based symptom analysis with optional severity scoring.

Request:

{
  "symptoms": ["fever", "cough"],
  "severity": {
    "fever": 2.0,
    "cough": 1.0
  }
}

POST /get-recommendations

Get treatment recommendations for a specific disease.

Request:

{
  "disease": "Influenza"
}

GET /available-symptoms

Returns the list of all supported symptoms.

GET /available-diseases

Returns the list of all supported diseases.


Model Information

Architecture

The deep learning model is a feedforward neural network:

Layer Type Output Shape Parameters
Input Dense + ReLU (None, 256) 33,024
Batch Normalization BatchNormalization (None, 256) 1,024
Dropout Dropout (0.3) (None, 256) 0
Hidden 1 Dense + ReLU (None, 128) 32,896
Batch Normalization BatchNormalization (None, 128) 512
Dropout Dropout (0.3) (None, 128) 0
Hidden 2 Dense + ReLU (None, 64) 8,256
Output Dense + Sigmoid (None, 10) 650

Total parameters: ~76,362

Training

The model uses:

  • Loss function: Binary Crossentropy (multi-label classification)
  • Optimizer: Adam (learning rate = 0.001)
  • Metrics: Accuracy, AUC
  • Regularization: Batch normalization + Dropout (0.3)

Input Format

The model accepts a 128-dimensional binary vector where each index corresponds to a symptom (1 = present, 0 = absent). The output is a 10-dimensional vector of probabilities, one for each disease class.


Usage Examples

Python Client

import requests

BASE_URL = "http://localhost:8000"

# Health check
response = requests.get(f"{BASE_URL}/health")
print(response.json())

# Full diagnosis
response = requests.post(
    f"{BASE_URL}/predict",
    json={"symptoms": ["fever", "cough", "fatigue", "body ache"]}
)
print(response.json())

# Get recommendations
response = requests.post(
    f"{BASE_URL}/get-recommendations",
    json={"disease": "Influenza"}
)
print(response.json())

cURL

curl -X POST http://localhost:8000/predict \
  -H "Content-Type: application/json" \
  -d '{"symptoms": ["fever", "cough", "headache"]}'

Training Your Own Model

import numpy as np
from models import DiagnosisModel
from src import Preprocessor

# Generate or load your training data
X_train = np.random.rand(1000, 128)
y_train = np.random.randint(0, 2, (1000, 10))

# Build and train
model = DiagnosisModel()
metrics = model.train(X_train, y_train, epochs=30)

# Save the model
model.save()

# Evaluate
X_test = np.random.rand(200, 128)
y_test = np.random.randint(0, 2, (200, 10))
eval_results = model.evaluate(X_test, y_test)
print(eval_results)

Roadmap

  • Integration with real medical datasets (e.g., MIMIC-III, NHANES)
  • Support for image-based diagnostics (X-ray, MRI)
  • Patient history tracking and longitudinal analysis
  • Multi-language symptom input
  • Frontend dashboard (React/Next.js)
  • CI/CD pipeline with automated testing

License

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


Contributing

Contributions are welcome! Please open an issue or submit a pull request.

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

About

Medical diagnostic assistant leveraging AI to assist in preliminary health assessments. Built with Python, TensorFlow, and FastAPI.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages