CoolFace
Apppublic

spchetan1987/hospitalqueuemanager

sourceHugging Faceupdated 1mo agoView on Hugging Face
0likes
App README

๐Ÿฅ AI Hospital Queue Management System (ML-Powered)

An intelligent hospital queue management system that uses Machine Learning to prioritize patients based on age and critical symptoms.

๐ŸŽฏ Features

  • โ€”ML-Based Prioritization: Uses a Random Forest Classifier trained on 5000 samples
  • โ€”Real-time Queue Management: Automatically sorts patients by priority
  • โ€”Confidence Scores: Shows prediction confidence for transparency
  • โ€”Interactive UI: Built with Gradio for easy use
  • โ€”Feature Engineering: Extracts meaningful features from age and symptoms

๐Ÿง  ML Model Details

Model Performance

  • โ€”Training Accuracy: 92.37%
  • โ€”Test Accuracy: 91.10%
  • โ€”Algorithm: Random Forest Classifier (100 trees)
  • โ€”Training Samples: 5000 synthetic patient records

Features Used

  1. 1.Age: Patient's age
  2. 2.Has Critical Symptom: Binary indicator for life-threatening symptoms
  3. 3.Has Medium Symptom: Binary indicator for moderate symptoms
  4. 4.Is Elderly: Age > 65
  5. 5.Is Child: Age < 12
  6. 6.Is Infant: Age < 5
  7. 7.Age Normalized: Age scaled to 0-1 range
  8. 8.Symptom Word Count: Complexity of symptom description

Priority Levels

  • โ€”Priority 1 (HIGH): Critical symptoms requiring immediate attention
  • โ€”Examples: chest pain, shortness of breath, severe bleeding, unconscious, heart attack, stroke
  • โ€”Priority 2 (MEDIUM): Moderate symptoms or vulnerable age groups
  • โ€”Examples: high fever, fracture, vomiting, elderly patients, infants
  • โ€”Priority 3 (LOW): Minor symptoms that can wait
  • โ€”Examples: cold, cough, minor headache, rash, routine check-up

๐Ÿ“ฆ Installation

Prerequisites

  • โ€”Python 3.7 or higher
  • โ€”pip package manager

Steps

  1. 1.Clone or download this repository
  1. 1.Install dependencies:
bash
pip install -r requirements.txt
  1. 1.Train the ML model (if not already trained):
bash
python train_model.py

This will:

  • โ€”Generate 5000 synthetic training samples
  • โ€”Train a Random Forest model
  • โ€”Save the model to queue_priority_model.pkl
  • โ€”Save configuration to model_config.json
  • โ€”Create training_data.csv with the training dataset
  1. 1.Run the application:
bash
python app.py

The Gradio interface will launch in your default browser (usually at http://127.0.0.1:7860)

๐Ÿš€ Usage

Adding Patients to Queue

  1. 1.Enter the patient's Name
  2. 2.Enter the patient's Age (0-120)
  3. 3.Enter Symptoms (e.g., "chest pain", "high fever", "minor headache")
  4. 4.Click "Add to Queue"

The ML model will:

  • โ€”Extract features from the input
  • โ€”Predict the priority level (1, 2, or 3)
  • โ€”Show confidence scores for transparency
  • โ€”Add the patient to the queue sorted by priority

Example Inputs

High Priority Patient:

  • โ€”Name: John Doe
  • โ€”Age: 55
  • โ€”Symptoms: chest pain and shortness of breath

Medium Priority Patient:

  • โ€”Name: Mary Smith
  • โ€”Age: 72
  • โ€”Symptoms: high fever and dizziness

Low Priority Patient:

  • โ€”Name: Tom Brown
  • โ€”Age: 25
  • โ€”Symptoms: minor headache and cough

Clearing the Queue

Click the "Clear Queue" button to reset the patient queue.

๐Ÿ“Š Model Training Details

Data Generation

The training data is synthetically generated with realistic distributions:

  • โ€”25% High Priority cases
  • โ€”25% Medium Priority cases
  • โ€”50% Low Priority cases

Special rules applied:

  • โ€”Elderly patients (>65) with non-critical symptoms โ†’ Medium priority
  • โ€”Infants (<5) with any symptoms โ†’ At least Medium priority
  • โ€”Critical symptoms โ†’ Always High priority regardless of age

Feature Importance

Based on the trained model:

  1. 1.Has Critical Symptom: 53.96% importance
  2. 2.Has Medium Symptom: 34.94% importance
  3. 3.Age: 3.24% importance
  4. 4.Symptom Word Count: 3.23% importance
  5. 5.Other features: < 3% each

๐Ÿ”ง Project Structure

hospital-queue-management/
โ”œโ”€โ”€ app.py                      # Main Gradio application
โ”œโ”€โ”€ train_model.py              # ML model training script
โ”œโ”€โ”€ requirements.txt            # Python dependencies
โ”œโ”€โ”€ queue_priority_model.pkl    # Trained ML model (generated)
โ”œโ”€โ”€ model_config.json          # Model configuration (generated)
โ”œโ”€โ”€ training_data.csv          # Training dataset (generated)
โ””โ”€โ”€ README.md                  # This file

๐Ÿ› ๏ธ Technical Stack

  • โ€”Frontend: Gradio 5.49.1
  • โ€”ML Framework: scikit-learn
  • โ€”Data Processing: pandas, numpy
  • โ€”Model Persistence: joblib

๐Ÿ“ˆ Future Enhancements

  • โ€”Add more features (vital signs, medical history)
  • โ€”Implement real-time model retraining
  • โ€”Add patient wait time estimation
  • โ€”Include doctor availability in prioritization
  • โ€”Export queue data to CSV/Excel
  • โ€”Multi-language support
  • โ€”Integration with hospital management systems

๐Ÿค Contributing

Feel free to fork this project and submit pull requests for improvements!

๐Ÿ“„ License

This project is open source and available for educational purposes.

๐Ÿ™ Acknowledgments

Built with Gradio and deployed on Hugging Face Spaces


Note: This is a demonstration system. For production use in real hospitals, please consult with medical professionals and ensure compliance with healthcare regulations (HIPAA, etc.).