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.
| 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 |
- π€ 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)
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)
- Python 3.10 or higher
- pip (Python package manager)
- (Optional) GPU with CUDA support for faster TensorFlow training
# 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.pyThe server will start at http://localhost:8000. Visit http://localhost:8000/docs for the interactive Swagger UI.
Health check endpoint.
Response:
{
"status": "healthy",
"service": "Medical AI Diagnostic Assistant",
"version": "1.0.0"
}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": "..."
}Rule-based symptom analysis with optional severity scoring.
Request:
{
"symptoms": ["fever", "cough"],
"severity": {
"fever": 2.0,
"cough": 1.0
}
}Get treatment recommendations for a specific disease.
Request:
{
"disease": "Influenza"
}Returns the list of all supported symptoms.
Returns the list of all supported diseases.
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
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)
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.
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 -X POST http://localhost:8000/predict \
-H "Content-Type: application/json" \
-d '{"symptoms": ["fever", "cough", "headache"]}'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)- 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
This project is licensed under the MIT License. See the LICENSE file for details.
Contributions are welcome! Please open an issue or submit a pull request.
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request