dylanglenister
commited on
Commit
·
73b8ca8
1
Parent(s):
e079207
CHORE: Updated readme and setup guide
Browse files- LICENSE → LICENCE +0 -0
- README.md +49 -115
- SETUP_GUIDE.md +93 -202
LICENSE → LICENCE
RENAMED
|
File without changes
|
README.md
CHANGED
|
@@ -5,122 +5,56 @@ colorFrom: yellow
|
|
| 5 |
colorTo: green
|
| 6 |
sdk: docker
|
| 7 |
pinned: false
|
| 8 |
-
license:
|
| 9 |
-
short_description:
|
| 10 |
python_version: 3.11
|
| 11 |
app_port: 7860
|
| 12 |
---
|
| 13 |
|
| 14 |
-
# Medical
|
| 15 |
-
|
| 16 |
-
AI-powered medical chatbot
|
| 17 |
-
|
| 18 |
-
##
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
-
|
| 25 |
-
-
|
| 26 |
-
-
|
| 27 |
-
-
|
| 28 |
-
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
###
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
context
|
| 37 |
-
- **
|
| 38 |
-
|
| 39 |
-
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
-
|
| 44 |
-
-
|
| 45 |
-
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
### Prerequisites
|
| 62 |
-
- Python 3.11+
|
| 63 |
-
- pip
|
| 64 |
-
|
| 65 |
-
### Setup
|
| 66 |
-
1. Clone and install
|
| 67 |
-
```bash
|
| 68 |
-
git clone https://huggingface.co/spaces/MedAI-COS30018/MedicalDiagnosisSystem
|
| 69 |
-
cd MedAI
|
| 70 |
-
pip install -r requirements.txt
|
| 71 |
-
```
|
| 72 |
-
2. Configure environment
|
| 73 |
-
```bash
|
| 74 |
-
# Create .env
|
| 75 |
-
echo "GEMINI_API_1=your_gemini_api_key_1" > .env
|
| 76 |
-
echo "NVIDIA_API_1=your_nvidia_api_key_1" >> .env
|
| 77 |
-
# MongoDB (required)
|
| 78 |
-
echo "MONGO_USER=your_mongodb_connection_string" >> .env
|
| 79 |
-
# Optional DB name (default: medicaldiagnosissystem)
|
| 80 |
-
# Optional DB name (default: medicaldiagnosissystem). Env var key: USER_DB
|
| 81 |
-
echo "USER_DB=medicaldiagnosissystem" >> .env
|
| 82 |
-
```
|
| 83 |
-
3. Run
|
| 84 |
-
```bash
|
| 85 |
-
python -m src.main
|
| 86 |
-
```
|
| 87 |
-
Helpful: [UI SETUP](https://huggingface.co/spaces/MedAI-COS30018/MedicalDiagnosisSystem/blob/main/UI_SETUP.md) | [SETUP GUIDE](https://huggingface.co/spaces/MedAI-COS30018/MedicalDiagnosisSystem/blob/main/SETUP_GUIDE.md)
|
| 88 |
-
|
| 89 |
-
## 🔧 Config
|
| 90 |
-
- `GEMINI_API_1..5`, `NVIDIA_API_1..5`
|
| 91 |
-
- `MONGO_USER`, `MONGO_DB`
|
| 92 |
-
- `LOG_LEVEL`, `PORT`
|
| 93 |
-
- Memory: 3 short‑term, 20 long‑term
|
| 94 |
-
|
| 95 |
-
## 📱 Usage
|
| 96 |
-
1. Select/create a doctor; set role/specialty.
|
| 97 |
-
2. Search patient by name/ID; select a result.
|
| 98 |
-
3. Start a new chat; ask your question.
|
| 99 |
-
4. Manage sessions in the sidebar (rename/delete from menu).
|
| 100 |
-
5. View patient profile and create/edit via modals/pages.
|
| 101 |
-
|
| 102 |
-
## 🔌 Endpoints (selected)
|
| 103 |
-
- `POST /chat` → `{ response, session_id, timestamp, medical_context? }`
|
| 104 |
-
- `POST /sessions` → `{ session_id }`
|
| 105 |
-
- `GET /patients/{patient_id}/sessions`
|
| 106 |
-
- `GET /sessions/{session_id}/messages`
|
| 107 |
-
- `DELETE /sessions/{session_id}` → deletes session (cache + Mongo) and its messages
|
| 108 |
-
- `GET /patients/search?q=term&limit=8`
|
| 109 |
-
|
| 110 |
-
## 🔒 Data & Privacy
|
| 111 |
-
- MongoDB persistence keyed by `patient_id` with `doctor_id` attribution
|
| 112 |
-
- UI localStorage for UX (doctor list, preferences, selected patient)
|
| 113 |
-
- Avoid logging PHI; secure Mongo credentials
|
| 114 |
-
|
| 115 |
-
## 🧪 Dev
|
| 116 |
-
```bash
|
| 117 |
-
pip install -r requirements.txt
|
| 118 |
-
python -m src.main # run
|
| 119 |
-
pytest # tests
|
| 120 |
-
black . && flake8 # format + lint
|
| 121 |
-
```
|
| 122 |
-
|
| 123 |
-
## 🧾 License & Disclaimer
|
| 124 |
-
- Apache 2.0 License (see [LICENSE](./LICENSE))
|
| 125 |
-
- Educational information only; not a substitute for professional medical advice
|
| 126 |
-
- Team D1 - COS30018, Swinburne University of Technology
|
|
|
|
| 5 |
colorTo: green
|
| 6 |
sdk: docker
|
| 7 |
pinned: false
|
| 8 |
+
license: apache-2.0
|
| 9 |
+
short_description: University project creating an AI-powered medical system
|
| 10 |
python_version: 3.11
|
| 11 |
app_port: 7860
|
| 12 |
---
|
| 13 |
|
| 14 |
+
# Medical Diagnosis System
|
| 15 |
+
|
| 16 |
+
An AI-powered medical chatbot designed for patient-centric interactions, featuring persistent memory and a modern, intuitive user interface. This system is containerised using Docker for simplified deployment and scalability.
|
| 17 |
+
|
| 18 |
+
## System Architecture
|
| 19 |
+
|
| 20 |
+
The application is comprised of a FastAPI backend and a static frontend, communicating via a RESTful API. The entire system is designed to be run within Docker containers, ensuring a consistent and reproducible environment.
|
| 21 |
+
|
| 22 |
+
### Services and Technologies
|
| 23 |
+
|
| 24 |
+
- **Backend**: Python 3.11 with FastAPI
|
| 25 |
+
- **Database**: MongoDB for all persistent data, including user information, chat sessions, and long-term memory.
|
| 26 |
+
- **AI Models**:
|
| 27 |
+
- **Primary**: Google's Gemini Pro for response generation.
|
| 28 |
+
- **Fallback**: An NVIDIA-based model for summarisation, accessed via a dedicated API.
|
| 29 |
+
- **Containerisation**: Docker and Docker Compose for service orchestration.
|
| 30 |
+
- **Frontend**: Static HTML, CSS, and vanilla JavaScript.
|
| 31 |
+
|
| 32 |
+
### Retrieval-Augmented Generation (RAG) Implementation
|
| 33 |
+
|
| 34 |
+
The system's contextual memory is built upon a RAG architecture to provide relevant and informed responses. This is achieved through a multi-layered memory system:
|
| 35 |
+
|
| 36 |
+
- **Short-Term Memory**: An in-memory LRU (Least Recently Used) cache stores the summaries of the last three interactions. This allows for immediate context recall within an ongoing conversation.
|
| 37 |
+
- **Long-Term Memory**: The summaries of the last twenty interactions for each patient are persisted in MongoDB. This provides a deeper historical context for recurring patients, allowing the system to reference past conversations and maintain continuity over time.
|
| 38 |
+
|
| 39 |
+
When a query is received, the system retrieves the relevant short and long-term memory summaries to build a comprehensive context. This context is then provided to the Gemini model along with the user's query to generate an accurate and context-aware response.
|
| 40 |
+
|
| 41 |
+
## Key Features
|
| 42 |
+
|
| 43 |
+
- **Patient-Centric Memory**: Utilises both short-term and long-term memory to maintain context throughout conversations.
|
| 44 |
+
- **Persistent Chat History**: All chat sessions are saved in MongoDB, allowing for a complete history of interactions.
|
| 45 |
+
- **Contextual Awareness**: The system maintains the context of both the patient and the doctor in all messages and summaries.
|
| 46 |
+
- **User Management**: Includes features for patient search (by name or ID) and a doctor dropdown with a streamlined user creation process.
|
| 47 |
+
- **Modern User Interface**: The application features a sidebar for session management, modals for doctor and patient profiles, a dark/light mode, and a mobile-friendly design.
|
| 48 |
+
- **AI Model Integration**: The system leverages Gemini for generating responses and includes a fallback to an NVIDIA summariser.
|
| 49 |
+
|
| 50 |
+
## Getting Started
|
| 51 |
+
|
| 52 |
+
To get the project up and running, please refer to the detailed instructions in the [setup guide](./SETUP_GUIDE.md).
|
| 53 |
+
|
| 54 |
+
## Licence & Disclaimer
|
| 55 |
+
|
| 56 |
+
This project is licensed under the Apache 2.0 Licence. See the [LICENCE](./LICENCE) file for details.
|
| 57 |
+
|
| 58 |
+
The information provided by this system is for educational purposes only and is not a substitute for professional medical advice, diagnosis, or treatment. Always seek the advice of your physician or other qualified health provider with any questions you may have regarding a medical condition.
|
| 59 |
+
|
| 60 |
+
Team D1 - COS30018, Swinburne University of Technology
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SETUP_GUIDE.md
CHANGED
|
@@ -1,256 +1,147 @@
|
|
| 1 |
-
#
|
| 2 |
|
| 3 |
-
|
| 4 |
|
| 5 |
-
|
| 6 |
|
| 7 |
-
|
| 8 |
-
2. **Multi-user Support** - Individual profiles and chat sessions
|
| 9 |
-
3. **Medical Context Memory** - LRU-based memory system
|
| 10 |
-
4. **API Key Rotation** - Dynamic Gemini API management
|
| 11 |
-
5. **Fallback Systems** - Graceful degradation when services unavailable
|
| 12 |
|
| 13 |
-
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
-
|
| 16 |
-
```bash
|
| 17 |
-
pip install -r requirements.txt
|
| 18 |
-
```
|
| 19 |
|
| 20 |
-
|
| 21 |
-
```bash
|
| 22 |
-
# For full Gemini AI functionality
|
| 23 |
-
export GEMINI_API_1="your_api_key_1"
|
| 24 |
-
export GEMINI_API_2="your_api_key_2"
|
| 25 |
-
...
|
| 26 |
-
export GEMINI_API_5="your_api_key_5"
|
| 27 |
-
```
|
| 28 |
|
| 29 |
-
|
| 30 |
-
```bash
|
| 31 |
-
python3 start.py
|
| 32 |
-
```
|
| 33 |
|
| 34 |
-
### 4. Access the UI
|
| 35 |
-
Open your browser and go to: **http://localhost:8000**
|
| 36 |
-
|
| 37 |
-
## 🏗️ System Architecture
|
| 38 |
-
|
| 39 |
-
### Core Components
|
| 40 |
-
- **`app.py`** - FastAPI main application with all endpoints
|
| 41 |
-
- **`memo/memory.py`** - Enhanced LRU memory with user/session management
|
| 42 |
-
- **`memo/history.py`** - Medical history manager with context awareness
|
| 43 |
-
- **`utils/rotator.py`** - API key rotation for reliability
|
| 44 |
-
- **`utils/embeddings.py`** - Embedding client with fallback support
|
| 45 |
-
- **`static/`** - Complete web UI (HTML, CSS, JavaScript)
|
| 46 |
-
|
| 47 |
-
### Key Features
|
| 48 |
-
- **User Management**: Create profiles with medical roles and specialties
|
| 49 |
-
- **Session Management**: Multiple concurrent chat sessions per user
|
| 50 |
-
- **Medical Memory**: Context-aware responses using conversation history
|
| 51 |
-
- **API Integration**: Gemini AI with automatic key rotation
|
| 52 |
-
- **Responsive UI**: Works on desktop, tablet, and mobile
|
| 53 |
-
|
| 54 |
-
## 📱 Using the System
|
| 55 |
-
|
| 56 |
-
### First Time Setup
|
| 57 |
-
1. **Access the UI** at http://localhost:8000
|
| 58 |
-
2. **Click your profile** to set name, role, and specialty
|
| 59 |
-
3. **Start a new chat** to begin your first conversation
|
| 60 |
-
4. **Ask medical questions** in natural language
|
| 61 |
-
|
| 62 |
-
### User Roles Available
|
| 63 |
-
- **Physician** - Full medical context and clinical guidance
|
| 64 |
-
- **Nurse** - Nursing-focused responses and care instructions
|
| 65 |
-
- **Medical Student** - Educational content with learning objectives
|
| 66 |
-
- **Healthcare Professional** - General medical information
|
| 67 |
-
- **Patient** - Educational content with appropriate disclaimers
|
| 68 |
-
|
| 69 |
-
### Features
|
| 70 |
-
- **Real-time Chat**: Instant responses with typing indicators
|
| 71 |
-
- **Session Export**: Download chat history as JSON files
|
| 72 |
-
- **Context Memory**: System remembers previous conversations
|
| 73 |
-
- **Medical Disclaimers**: Appropriate warnings for medical information
|
| 74 |
-
- **Dark/Light Theme**: Automatic theme switching
|
| 75 |
-
|
| 76 |
-
## 🔧 Configuration Options
|
| 77 |
-
|
| 78 |
-
### Environment Variables
|
| 79 |
```bash
|
| 80 |
-
|
| 81 |
-
GEMINI_API_1=your_key_1
|
| 82 |
-
GEMINI_API_2=your_key_2
|
| 83 |
-
GEMINI_API_3=your_key_3
|
| 84 |
-
|
| 85 |
-
# Optional
|
| 86 |
-
LOG_LEVEL=INFO
|
| 87 |
-
PORT=8000
|
| 88 |
```
|
| 89 |
|
| 90 |
-
|
| 91 |
-
- **LRU Capacity**: 50 QA summaries per user (configurable)
|
| 92 |
-
- **Max Sessions**: 20 sessions per user (configurable)
|
| 93 |
-
- **Session Timeout**: Configurable session expiration
|
| 94 |
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
|
|
|
| 99 |
|
| 100 |
-
|
|
|
|
|
|
|
|
|
|
| 101 |
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
```
|
| 106 |
-
|
| 107 |
-
### Test Individual Components
|
| 108 |
-
```bash
|
| 109 |
-
# Test memory system
|
| 110 |
-
python3 -c "from memo.memory import MemoryLRU; m = MemoryLRU(); print('✅ Memory system works')"
|
| 111 |
-
|
| 112 |
-
# Test API rotator
|
| 113 |
-
python3 -c "from utils.rotator import APIKeyRotator; r = APIKeyRotator('TEST_'); print('✅ Rotator works')"
|
| 114 |
-
|
| 115 |
-
# Test embeddings
|
| 116 |
-
python3 -c "from utils.embeddings import create_embedding_client; c = create_embedding_client(); print('✅ Embeddings work')"
|
| 117 |
```
|
| 118 |
|
| 119 |
-
|
| 120 |
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
- **`GET /users/{user_id}`** - Get user data and sessions
|
| 126 |
-
- **`POST /sessions`** - Create chat sessions
|
| 127 |
-
- **`GET /sessions/{session_id}`** - Get session details
|
| 128 |
-
- **`DELETE /sessions/{session_id}`** - Delete sessions
|
| 129 |
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
|
| 135 |
-
##
|
| 136 |
|
| 137 |
-
|
| 138 |
-
- **Local Storage**: User data stored in browser (no server persistence)
|
| 139 |
-
- **Session Isolation**: Users can only access their own data
|
| 140 |
-
- **No PII Storage**: Personal information not logged or stored
|
| 141 |
-
- **Medical Disclaimers**: Clear warnings about information limitations
|
| 142 |
|
| 143 |
-
###
|
| 144 |
-
|
| 145 |
-
- **Rate Limiting**: Built-in protection against API abuse
|
| 146 |
-
- **Error Handling**: Graceful degradation on API failures
|
| 147 |
|
| 148 |
-
|
|
|
|
| 149 |
|
| 150 |
-
### Local Development
|
| 151 |
```bash
|
| 152 |
-
|
| 153 |
```
|
| 154 |
|
| 155 |
-
|
| 156 |
-
```bash
|
| 157 |
-
# Set production environment variables
|
| 158 |
-
export PRODUCTION=true
|
| 159 |
-
export LOG_LEVEL=WARNING
|
| 160 |
|
| 161 |
-
|
| 162 |
-
|
| 163 |
```
|
| 164 |
|
| 165 |
-
|
|
|
|
|
|
|
|
|
|
| 166 |
```bash
|
| 167 |
-
|
| 168 |
-
docker build -t medical-ai-assistant .
|
| 169 |
-
docker run -p 8000:8000 medical-ai-assistant
|
| 170 |
```
|
| 171 |
|
| 172 |
-
##
|
| 173 |
|
| 174 |
-
|
| 175 |
|
| 176 |
-
|
| 177 |
```bash
|
| 178 |
-
|
| 179 |
cd MedicalDiagnosisSystem
|
| 180 |
-
|
| 181 |
-
# Install dependencies
|
| 182 |
-
pip install -r requirements.txt
|
| 183 |
-
|
| 184 |
-
# Check Python version (3.8+ required)
|
| 185 |
-
python3 --version
|
| 186 |
```
|
| 187 |
|
| 188 |
-
|
| 189 |
-
|
| 190 |
-
# Check what's using port 8000
|
| 191 |
-
lsof -i :8000
|
| 192 |
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
python3 start.py
|
| 196 |
-
```
|
| 197 |
|
| 198 |
-
|
| 199 |
```bash
|
| 200 |
-
|
| 201 |
-
echo $GEMINI_API_1
|
| 202 |
-
|
| 203 |
-
# Set them if missing
|
| 204 |
-
export GEMINI_API_1="your_key_here"
|
| 205 |
```
|
|
|
|
| 206 |
|
| 207 |
-
|
| 208 |
-
```bash
|
| 209 |
-
|
| 210 |
-
|
| 211 |
-
top
|
| 212 |
|
| 213 |
-
|
| 214 |
-
|
| 215 |
-
|
|
|
|
| 216 |
|
| 217 |
-
|
| 218 |
-
|
| 219 |
-
|
| 220 |
-
|
| 221 |
-
- **API docs**: Visit http://localhost:8000/docs
|
| 222 |
|
| 223 |
-
|
| 224 |
|
| 225 |
-
###
|
| 226 |
-
|
| 227 |
-
- **Advanced RAG**: Vector database for medical knowledge
|
| 228 |
-
- **Multi-language Support**: Internationalization
|
| 229 |
-
- **Voice Interface**: Speech-to-text and text-to-speech
|
| 230 |
-
- **Mobile App**: Native iOS/Android applications
|
| 231 |
-
- **Analytics Dashboard**: Usage statistics and insights
|
| 232 |
|
| 233 |
-
|
| 234 |
-
|
| 235 |
-
|
| 236 |
-
- **Integration APIs**: Connect with existing medical systems
|
| 237 |
-
- **Custom Models**: Use different AI models or fine-tuned versions
|
| 238 |
|
| 239 |
-
|
|
|
|
|
|
|
| 240 |
|
| 241 |
-
###
|
| 242 |
-
|
| 243 |
-
- **Uvicorn**: https://www.uvicorn.org/
|
| 244 |
-
- **Google Gemini**: https://ai.google.dev/
|
| 245 |
-
- **Sentence Transformers**: https://www.sbert.net/
|
| 246 |
|
| 247 |
-
|
| 248 |
-
|
| 249 |
-
|
| 250 |
-
|
| 251 |
|
| 252 |
-
|
| 253 |
|
| 254 |
-
|
|
|
|
| 255 |
|
| 256 |
-
|
|
|
|
|
|
|
|
|
| 1 |
+
# Setup Guide
|
| 2 |
|
| 3 |
+
This guide provides instructions on how to set up and run the Medical Diagnosis System for both local development and using Docker.
|
| 4 |
|
| 5 |
+
## Prerequisites
|
| 6 |
|
| 7 |
+
Before you begin, ensure you have the following installed:
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
+
- Git
|
| 10 |
+
- Python 3.11 or higher
|
| 11 |
+
- pip (Python package installer)
|
| 12 |
+
- Docker and Docker Compose
|
| 13 |
|
| 14 |
+
## Environment Variable Setup
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
+
The application is configured using a `.env` file in the project's root directory. This file is required for both local and Docker setups, but the values will differ.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
+
First, create the file:
|
|
|
|
|
|
|
|
|
|
| 19 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
```bash
|
| 21 |
+
touch .env
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
```
|
| 23 |
|
| 24 |
+
Next, add the following variables to the file. Explanations for each setup type are provided below.
|
|
|
|
|
|
|
|
|
|
| 25 |
|
| 26 |
+
```ini
|
| 27 |
+
# --- AI Model API Keys ---
|
| 28 |
+
# Add at least one key for each service. The application will rotate through them.
|
| 29 |
+
GEMINI_API_KEY_1=your_gemini_api_key
|
| 30 |
+
NVIDIA_API_KEY_1=your_nvidia_api_key
|
| 31 |
|
| 32 |
+
# --- MongoDB Connection ---
|
| 33 |
+
# Use the appropriate URI for your setup (see examples below)
|
| 34 |
+
MONGO_URI=your_mongodb_connection_string
|
| 35 |
+
DB_NAME=medicaldiagnosissystem
|
| 36 |
|
| 37 |
+
# --- Application Settings ---
|
| 38 |
+
LOG_LEVEL=INFO
|
| 39 |
+
PORT=7860
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
```
|
| 41 |
|
| 42 |
+
### MongoDB URI Examples
|
| 43 |
|
| 44 |
+
- **For Docker Setup (Recommended):** The `docker-compose.yml` file includes a MongoDB service. Use the following URI to connect the application container to the database container:
|
| 45 |
+
```ini
|
| 46 |
+
MONGO_URI=mongodb://root:example@mongo:27017/
|
| 47 |
+
```
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
|
| 49 |
+
- **For Local Development:** You must run your own MongoDB instance. If it is running locally on the default port without authentication, your URI would be:
|
| 50 |
+
```ini
|
| 51 |
+
MONGO_URI=mongodb://localhost:27017/
|
| 52 |
+
```
|
| 53 |
|
| 54 |
+
## Docker Setup (Recommended)
|
| 55 |
|
| 56 |
+
This method runs the application and a MongoDB database in isolated containers, which is the quickest way to get started.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
|
| 58 |
+
### 1. Configure Environment
|
| 59 |
+
Ensure your `.env` file is present in the project root and contains the correct `MONGO_URI` for a Docker environment.
|
|
|
|
|
|
|
| 60 |
|
| 61 |
+
### 2. Build and Run Containers
|
| 62 |
+
From the project's root directory, run the following command. This will build the Docker images and start the application and database services.
|
| 63 |
|
|
|
|
| 64 |
```bash
|
| 65 |
+
docker-compose up --build
|
| 66 |
```
|
| 67 |
|
| 68 |
+
To run the containers in the background (detached mode), add the `-d` flag:
|
|
|
|
|
|
|
|
|
|
|
|
|
| 69 |
|
| 70 |
+
```bash
|
| 71 |
+
docker-compose up --build -d
|
| 72 |
```
|
| 73 |
|
| 74 |
+
The application will now be accessible at `http://localhost:7860`.
|
| 75 |
+
|
| 76 |
+
### 3. Stopping the Application
|
| 77 |
+
To stop and remove the containers, use:
|
| 78 |
```bash
|
| 79 |
+
docker-compose down
|
|
|
|
|
|
|
| 80 |
```
|
| 81 |
|
| 82 |
+
## Local Development Setup
|
| 83 |
|
| 84 |
+
This method requires you to run a MongoDB instance on your local machine or have one accessible on your network.
|
| 85 |
|
| 86 |
+
### 1. Clone the Repository
|
| 87 |
```bash
|
| 88 |
+
git clone https://github.com/COS30018-2025-Sem2-GroupD1/MedicalDiagnosisSystem.git
|
| 89 |
cd MedicalDiagnosisSystem
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 90 |
```
|
| 91 |
|
| 92 |
+
### 2. Configure Environment
|
| 93 |
+
Ensure your `.env` file is present and contains the correct `MONGO_URI` that points to your externally-managed MongoDB instance.
|
|
|
|
|
|
|
| 94 |
|
| 95 |
+
### 3. Create and Activate a Virtual Environment
|
| 96 |
+
It is highly recommended to use a virtual environment to isolate project dependencies.
|
|
|
|
|
|
|
| 97 |
|
| 98 |
+
First, create the environment in the project's root directory:
|
| 99 |
```bash
|
| 100 |
+
python -m venv .venv
|
|
|
|
|
|
|
|
|
|
|
|
|
| 101 |
```
|
| 102 |
+
Next, activate it. The command differs depending on your operating system:
|
| 103 |
|
| 104 |
+
- **On Linux or macOS:**
|
| 105 |
+
```bash
|
| 106 |
+
source .venv/bin/activate
|
| 107 |
+
```
|
|
|
|
| 108 |
|
| 109 |
+
- **On Windows (using PowerShell):**
|
| 110 |
+
```powershell
|
| 111 |
+
.\.venv\Scripts\Activate.ps1
|
| 112 |
+
```
|
| 113 |
|
| 114 |
+
- **On Windows (using Command Prompt):**
|
| 115 |
+
```cmd
|
| 116 |
+
.\.venv\Scripts\activate.bat
|
| 117 |
+
```
|
|
|
|
| 118 |
|
| 119 |
+
Your shell prompt should now indicate that you are in the `.venv` environment.
|
| 120 |
|
| 121 |
+
### 4. Install Dependencies
|
| 122 |
+
Install the required Python packages into your active virtual environment:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 123 |
|
| 124 |
+
```bash
|
| 125 |
+
# Install all requirements for running
|
| 126 |
+
pip install -r requirements.txt
|
|
|
|
|
|
|
| 127 |
|
| 128 |
+
# Install development-specific dependencies
|
| 129 |
+
pip install -r requirements-dev.txt
|
| 130 |
+
```
|
| 131 |
|
| 132 |
+
### 5. Run the Application
|
| 133 |
+
To run the application for development, use `uvicorn`. This will start a local server that automatically reloads when you make code changes.
|
|
|
|
|
|
|
|
|
|
| 134 |
|
| 135 |
+
```bash
|
| 136 |
+
uvicorn src.main:app --reload
|
| 137 |
+
```
|
| 138 |
+
The application will be accessible at `http://localhost:7860`.
|
| 139 |
|
| 140 |
+
## Development Workflow
|
| 141 |
|
| 142 |
+
### Running Tests
|
| 143 |
+
To run the test suite, use `pytest`:
|
| 144 |
|
| 145 |
+
```bash
|
| 146 |
+
pytest
|
| 147 |
+
```
|