CoolFace
Apppublic

sugan04/healthbot-crs

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

๐Ÿฅ HealthBot-CRS โ€” Clinical Response System

Group: DSA2021018 Live Demo: https://sugan04-healthbot-crs.hf.space โš ๏ธ Research Prototype โ€” Not a substitute for professional medical advice.

๐Ÿ“Œ Problem Statement

Patients often struggle to access quick, reliable answers to health-related questions outside of clinical settings. HealthBot-CRS addresses this by building an intelligent, ML-powered Clinical Response System that classifies patient intent, retrieves the most relevant medical response, and delivers it through a conversational chatbot interface โ€” complete with multilingual text-to-speech support.


๐Ÿ—‚๏ธ Dataset

  • โ€”Source: ChatDoctor-HealthCareMagic-100k
  • โ€”Size: 100,000 patient-doctor Q&A pairs
  • โ€”Working sample: 5,000 rows (stratified, for development)
  • โ€”Intent categories: emergency, symptom_inquiry, medication_inquiry, diagnostics, lifestyle, mental_health, general_inquiry

๐Ÿ—๏ธ System Architecture

Raw Data (100k Q&A)
      โ†“
01. Data Loading & Cleaning (NLTK, Regex)
      โ†“
02. Feature Engineering (TF-IDF + SBERT + SpaCy NER)
      โ†“
03. Clustering (K-Means on SBERT embeddings)
      โ†“
04. Classification (LR, RF, SVM, GB, MLP)
      โ†“
05. Recommender System (SVD, NMF, KNN โ€” Surprise-style hybrid)
      โ†“
06. Evaluation & Error Analysis (F1, ROC, Confusion Matrix)
      โ†“
08. Flask API + Chat UI (deployed on Hugging Face Spaces)

โš™๏ธ Tech Stack & Libraries

CategoryLibraries
Data Processingpandas, numpy, nltk
NLP & Featuresscikit-learn (TF-IDF), sentence-transformers (SBERT), spacy (NER)
Clusteringscikit-learn KMeans
Classificationscikit-learn (LR, RF, SVM, GradientBoosting, MLP)
Recommenderscikit-learn (SVD/NMF/KNN matrix factorization)
Evaluationscikit-learn (F1, ROC, confusion matrix)
Web APIflask, flask-cors
DeploymentDocker, Hugging Face Spaces
FrontendVanilla HTML/CSS/JS, Web Speech API (TTS)

๐Ÿ“Š ML Pipeline

Step 1 โ€” Data Loading (01_data_loading.py)

  • โ€”Loaded 100k records from HuggingFace datasets
  • โ€”Cleaned text: lowercased, removed URLs, emails, special characters
  • โ€”Rule-based intent labelling across 7 categories
  • โ€”Filtered low-quality rows (too short/long)
  • โ€”Final sample: 5,000 rows saved to data/healthbot_sample.csv

Step 2 โ€” Feature Engineering (02_feature_engineering.py)

  • โ€”TF-IDF: 5,000 features, bigrams, sublinear TF weighting
  • โ€”SBERT: all-MiniLM-L6-v2 sentence embeddings (384 dimensions)
  • โ€”SpaCy NER: Medical entity extraction (symptoms, medications, conditions)
  • โ€”Combined feature matrix: TF-IDF + SBERT โ†’ input to classifiers

Step 3 โ€” Clustering (03_clustering.py)

  • โ€”Applied K-Means on SBERT embeddings
  • โ€”Optimal K selected via Elbow method and Silhouette score
  • โ€”Cluster labels used as user profiles for the recommender system

Step 4 โ€” Classification (04_classification.py)

  • โ€”Trained 5 classifiers on combined TF-IDF + SBERT features:
  • โ€”Logistic Regression, Random Forest, SVM, Gradient Boosting, MLP
  • โ€”Best model selected automatically at runtime by weighted F1 score

Step 5 โ€” Recommender System (05_recommender.py)

  • โ€”Built implicit rating matrix from cluster ร— intent interactions
  • โ€”Trained SVD, NMF, and KNN collaborative filtering models
  • โ€”Hybrid scoring: ฮฑ ร— content-based + (1-ฮฑ) ร— collaborative filtering

Step 6 โ€” Evaluation (06_evaluation.py, 06b_error_analysis.py)

  • โ€”Metrics: Weighted F1, Precision, Recall, Accuracy
  • โ€”Confusion matrix, ROC curves per intent class
  • โ€”Error analysis: low-confidence predictions and misclassified intents

๐Ÿ“ˆ Results

ModelWeighted F1
Logistic Regression~0.82
SVM~0.84
Gradient Boosting~0.83
Random Forest~0.79
MLP~0.85
Best model is auto-selected at runtime. Hybrid recommender combines SBERT cosine similarity with CF ratings for improved retrieval quality.

๐Ÿ’ก Innovativeness

  • โ€”Hybrid CB+CF Retrieval: Combines content-based SBERT similarity with collaborative filtering โ€” most chatbots use only one approach
  • โ€”Multilingual TTS: Real-time French translation + voice output via Web Speech API and MyMemory API
  • โ€”Live Deployment: Fully containerized with Docker and hosted on Hugging Face Spaces
  • โ€”Clinical NER: SpaCy-based medical entity extraction to enrich feature representation

๐Ÿš€ How to Run Locally

bash
# 1. Clone the repo
git clone https://huggingface.co/spaces/sugan04/healthbot-crs
cd healthbot-crs

# 2. Install dependencies
pip install -r requirements.txt
python -m spacy download en_core_web_sm

# 3. Run full ML pipeline
python 01_data_loading.py
python 02_feature_engineering.py
python 03_clustering.py
python 04_classification.py
python 05_recommender.py
python 06_evaluation.py

# 4. Launch chatbot API
python 08_chatbot.py --api

# 5. Open in browser
# http://localhost:7860

๐Ÿ“ File Structure

healthbot-crs/
โ”œโ”€โ”€ 01_data_loading.py          # Data loading & cleaning
โ”œโ”€โ”€ 02_feature_engineering.py   # TF-IDF, SBERT, SpaCy NER
โ”œโ”€โ”€ 03_clustering.py            # K-Means clustering
โ”œโ”€โ”€ 04_classification.py        # 5 classifier models
โ”œโ”€โ”€ 05_recommender.py           # SVD/NMF/KNN recommender
โ”œโ”€โ”€ 06_evaluation.py            # Metrics & ROC curves
โ”œโ”€โ”€ 06b_error_analysis.py       # Error analysis
โ”œโ”€โ”€ 08_chatbot.py               # Flask API + CLI chatbot
โ”œโ”€โ”€ HealthBot_CRS_Chat.html     # Chat UI
โ”œโ”€โ”€ HealthBot_CRS_Demo.html     # Landing page
โ”œโ”€โ”€ requirements.txt
โ”œโ”€โ”€ Dockerfile
โ”œโ”€โ”€ data/
โ”‚   โ”œโ”€โ”€ healthbot_sample.csv
โ”‚   โ””โ”€โ”€ healthbot_clustered.csv
โ””โ”€โ”€ outputs/
    โ”œโ”€โ”€ models/                 # Trained .pkl files
    โ”œโ”€โ”€ plots/                  # Visualizations
    โ””โ”€โ”€ results/                # Embeddings & matrices

๐Ÿ‘ฅ Group

DSA_202101_8 Course: Data Science & Analytics Deployment: https://sugan04-healthbot-crs.hf.space