LiamKhoaLe's picture
Upd README
ef1c061
|
raw
history blame
7.05 kB
metadata
title: Medical Diagnosis System
emoji: πŸ₯
colorFrom: yellow
colorTo: green
sdk: docker
pinned: false
license: mit
short_description: Group project for uni work
python_version: 3.11
app_port: 7860

Medical AI Assistant

AI-powered medical chatbot with patient-centric memory, MongoDB persistence, and a fast, modern UI.

πŸš€ Key Features

  • Patient-centric RAG memory
    • Short-term: last 3 QA summaries in in-memory LRU (fast context)
    • Long-term: last 20 QA summaries per patient persisted in MongoDB (continuity)
  • Chat history persistence per session in MongoDB
  • Patient/Doctor context saved on all messages and summaries
  • Patient search typeahead (name or ID) with instant session hydration
  • Doctor dropdown with built‑in "Create doctor user..." flow
  • Modern UI: sidebar sessions, modals (doctor, settings, patient profile), dark/light mode, mobile-friendly
  • Model integration: Gemini responses, NVIDIA summariser fallback via key rotators

πŸ—οΈ Architecture (high-level)

Medical Features

  • Medical Knowledge Base: Built-in medical information for common symptoms, conditions, and medications
  • Context Awareness: Remembers previous conversations and provides relevant medical context
  • Role-Based Responses: Tailored responses based on user's medical role and specialty
  • Medical Disclaimers: Appropriate warnings and disclaimers for medical information
  • Export Functionality: Export chat sessions for medical records or educational purposes

Backend (FastAPI):

  • src/core/memory/memory.py: LRU short‑term memory + sessions
  • src/core/memory/history.py: builds context; writes memory/messages to Mongo
  • src/data/: Mongo helpers (modularized)
    • connection.py: Mongo connection + collection names
    • session/operations.py: chat sessions (ensure/list/delete/etc.)
    • message/operations.py: chat messages (save/list)
    • patient/operations.py: patients (get/create/update/search)
    • user/operations.py: accounts/doctors (create/search/list)
    • medical/operations.py: medical records + memory summaries
    • utils.py: generic helpers (indexing, backups)
  • src/api/routes/: chat, session, user (patients), system, static

Frontend (static):

  • static/index.html, static/css/styles.css
  • static/js/app.js (or modularized under static/js/ui/* and static/js/chat/* β€” see UI_SETUP.md)

πŸ› οΈ Quick Start

Prerequisites

  • Python 3.11+
  • pip

Setup

  1. Clone and install
git clone https://huggingface.co/spaces/MedAI-COS30018/MedicalDiagnosisSystem
cd MedAI
pip install -r requirements.txt
  1. Configure environment
# Create .env
echo "GEMINI_API_1=your_gemini_api_key_1" > .env
echo "NVIDIA_API_1=your_nvidia_api_key_1" >> .env
# MongoDB (required)
echo "MONGO_USER=your_mongodb_connection_string" >> .env
# Optional DB name (default: medicaldiagnosissystem)
# Optional DB name (default: medicaldiagnosissystem). Env var key: USER_DB
echo "USER_DB=medicaldiagnosissystem" >> .env
  1. Run
python -m src.main

Helpful: UI SETUP | SETUP GUIDE

πŸ”§ Config

  • GEMINI_API_1..5, NVIDIA_API_1..5
  • MONGO_USER, MONGO_DB
  • LOG_LEVEL, PORT
  • Memory: 3 short‑term, 20 long‑term

πŸ“± Usage

  1. Select/create a doctor; set role/specialty.
  2. Search patient by name/ID; select a result.
  3. Start a new chat; ask your question.
  4. Manage sessions in the sidebar (rename/delete from menu).
  5. View patient profile and create/edit via modals/pages.

πŸ”Œ Endpoints (selected)

  • POST /chat β†’ { response, session_id, timestamp, medical_context? }
  • POST /sessions β†’ { session_id }
  • GET /patients/{patient_id}/sessions
  • GET /sessions/{session_id}/messages
  • DELETE /sessions/{session_id} β†’ deletes session (cache + Mongo) and its messages
  • GET /patients/search?q=term&limit=8

πŸ”’ Data & Privacy

  • MongoDB persistence keyed by patient_id with doctor_id attribution
  • UI localStorage for UX (doctor list, preferences, selected patient)
  • Avoid logging PHI; secure Mongo credentials

πŸ§ͺ Dev

pip install -r requirements.txt
python -m src.main   # run
pytest               # tests
black . && flake8    # format + lint

Project Structure

MedAI/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ api/
β”‚   β”‚   └── routes/
β”‚   β”‚       β”œβ”€β”€ chat.py          # Chat endpoint
β”‚   β”‚       β”œβ”€β”€ session.py       # Session endpoints
β”‚   β”‚       β”œβ”€β”€ user.py          # Patient APIs (get/create/update/search)
β”‚   β”‚       β”œβ”€β”€ system.py        # Health/info
β”‚   β”‚       └── static.py        # Serve index
β”‚   β”œβ”€β”€ core/
β”‚   β”‚   β”œβ”€β”€ memory/
β”‚   β”‚   β”‚   β”œβ”€β”€ memory.py        # LRU short‑term memory + sessions
β”‚   β”‚   β”‚   └── history.py       # Context builder, persistence hooks
β”‚   β”‚   └── state.py             # App state (rotators, embeddings, memory)
β”‚   β”œβ”€β”€ data/
β”‚   β”‚   β”œβ”€β”€ __init__.py          # Barrel exports for data layer
β”‚   β”‚   β”œβ”€β”€ connection.py        # Mongo connection + collection names
β”‚   β”‚   β”œβ”€β”€ utils.py             # Indexing, backups
β”‚   β”‚   β”œβ”€β”€ session/
β”‚   β”‚   β”‚   └── operations.py    # Sessions: ensure/list/delete
β”‚   β”‚   β”œβ”€β”€ message/
β”‚   β”‚   β”‚   └── operations.py    # Messages: save/list
β”‚   β”‚   β”œβ”€β”€ patient/
β”‚   β”‚   β”‚   └── operations.py    # Patients: get/create/update/search
β”‚   β”‚   β”œβ”€β”€ user/
β”‚   β”‚   β”‚   └── operations.py    # Accounts/Doctors
β”‚   β”‚   └── medical/
β”‚   β”‚       └── operations.py    # Medical records + memory summaries
β”‚   β”œβ”€β”€ models/
β”‚   β”‚   β”œβ”€β”€ chat.py
β”‚   β”‚   └── user.py
β”‚   β”œβ”€β”€ services/
β”‚   β”‚   β”œβ”€β”€ medical_response.py  # Calls model(s)
β”‚   β”‚   └── summariser.py        # Title/QA summarisation
β”‚   β”œβ”€β”€ utils/
β”‚   β”‚   β”œβ”€β”€ embeddings.py
β”‚   β”‚   β”œβ”€β”€ logger.py
β”‚   β”‚   └── rotator.py
β”‚   └── main.py                  # FastAPI entrypoint
β”œβ”€β”€ static/
β”‚   β”œβ”€β”€ index.html
β”‚   β”œβ”€β”€ css/
β”‚   β”‚   β”œβ”€β”€ styles.css
β”‚   β”‚   └── patient.css
β”‚   β”œβ”€β”€ js/
β”‚   β”‚   β”œβ”€β”€ app.js               # Submodules under /ui/* and /chat/*
β”‚   β”‚   └── patient.js
β”‚   └── patient.html
β”œβ”€β”€ requirements.txt
β”œβ”€β”€ requirements-dev.txt
β”œβ”€β”€ Dockerfile
β”œβ”€β”€ docker-compose.yml
β”œβ”€β”€ LICENSE
└── README.md

🧾 License & Disclaimer

  • MIT License (see LICENSE)
  • Educational information only; not a substitute for professional medical advice
  • Team D1 - COS30018, Swinburne University of Technology