Skip to content

A lightweight expert-system framework for modeling and testing medical diagnostic rules, with multiple approaches.

Notifications You must be signed in to change notification settings

saad2134/neural-tech

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🩺 Neural Tech: Medical Diagnosis

A lightweight hybrid AI framework for modeling, testing, and evaluating medical diagnostic logic.

🚀 Overview

This project implements a Simple Medical Diagnosis Expert System using three complementary approaches:

  1. Rule-Based (If–Else) Reasoning Deterministic logic using a predefined knowledge base.

  2. Retrieval-Augmented Generation (RAG) Enhances reasoning by retrieving contextual medical knowledge to reduce hallucination and improve accuracy.

  3. LLM-Based (API) Inference Uses large-language-model reasoning to deliver adaptive, context-aware medical insights.

Combined, these layers form a hybrid expert system that demonstrates how classical AI and modern generative AI can work together for clinical triage-style decision support.

🧠 Concept

An expert system uses:

  • Knowledge Base: Medical rules and symptom–disease mapping
  • Inference Engine: Matches user-reported symptoms with predefined rules
  • User Interface: A simple Streamlit UI for interaction

The system provides probable diagnoses such as Flu, Common Cold, Malaria, Typhoid, etc., based on symptom combinations.

⚙️ How It Works

1. User Input

Users enter symptoms (e.g., fever, cough, sore throat).

2. Fact Collection

Symptoms are stored as facts in memory.

3. Inference

The engine compares facts with the rule base.

4. Diagnosis

Matching rules trigger one or more possible medical conditions.

5. Hybrid Layering

Layer Role Handles
If–Else Rules (Python If-Else or Prolog) Explicit logic Known symptom patterns, emergencies
RAG Retrieval Semantic matching Variants of symptoms, contextual knowledge
LLM API Adaptive reasoning Combining logic + retrieved data
download

📚 Knowledge Base (Example)

Symptom Possible Diseases Severity Recommended Tests Advice Emergency
Fever Viral Infection, Malaria, Typhoid Moderate CBC, Malaria Test Hydration, paracetamol, rest No
Chest Pain Heart Attack, Acid Reflux, Anxiety Severe ECG, Troponin Seek emergency care if persistent Yes
Cough Cold, Bronchitis, COVID-19 Mild CXR, COVID test Steam inhalation, syrup No
Shortness of Breath Asthma, Pneumonia, Heart Failure Severe X-Ray, Oxygen saturation Immediate medical care Yes

🧩 Components

  • Rule Base: Hard-coded medical rules
  • Inference Engine: Pattern matching based on symptoms
  • RAG Pipeline: Fetches semantically relevant medical context
  • LLM API: Generates summarized reasoning
  • UI: Streamlit-based interactive interface

🧪 Sample Rule-Based Logic (Simplified)

if fever and cough and sore_throat:
    diagnosis = "Flu"
elif fever and chills and sweating:
    diagnosis = "Malaria"
else:
    diagnosis = "No rule-based match found"

📌 Features

  • ✔ Rule-based medical diagnosis
  • ✔ RAG-enhanced symptom interpretation
  • ✔ LLM-driven clinical reasoning
  • ✔ Emergency detection flags
  • ✔ Recommended tests + treatment guidance
  • ✔ Modular design for integration with telemedicine tools
  • ✔ Easy to extend / plug in new medical rules

🎯 Applications

  • Educational tools for learning AI reasoning
  • Basic medical triage systems
  • Hybrid medical-AI prototypes
  • Telemedicine support platforms
  • Context-aware symptom analysis with live API access

📦 Output Example

The system provides:

  • Possible diseases
  • Severity level
  • Recommended tests
  • Treatment suggestions
  • Emergency status
  • RAG-supported context
  • LLM summary reasoning

🛠️ Tech Stack

  • Python
  • Streamlit (Frontend)
  • FAISS / Chroma (Optional RAG Vector Store)
  • Transformers / Embeddings
  • LLM API (OpenAI / Gemini / Local LLM)

🖥️ Running the Project

# Clone the repo
git clone https://github.com/saad2134/expert-system-medical-diagnosis

# Navigate to project
cd expert-system-medical-diagnosis

# Install dependencies
pip install -r requirements.txt

# Run the Streamlit app
streamlit run src/streamlit_app.py

📊 Repo Stats

Repo Size Last Commit Open Issues Open PRs License Forks Stars Watchers Contributors Languages Top Language

⭐ Star History

Star History Chart

✍️ Endnote

⭐ Star this repo if you found it helpful! Thanks for reading.


🏷 Tags

#ExpertSystem #MedicalDiagnosis #RuleBasedAI #RAG #RetrievalAugmentedGeneration #HybridAI #LLMInference #AIinHealthcare #HealthTech #DiagnosticAI #MedicalTriage #InferenceEngine #KnowledgeBase #StreamlitApp #AIDecisionSupport #SymptomChecker #ClinicalDecisionSupport #AIHealthcareTools #MachineReasoning #expert-system-medical-diagnosis NeuralTech