Skip to content

Latest commit

 

History

8 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

HealthBot — Multilingual AI Health Assistant

🏥 HealthBot — Multilingual AI Health Assistant

An AI-powered multilingual healthcare assistance platform that provides general health information through WhatsApp using medical-focused Large Language Models, Retrieval-Augmented Generation (RAG), voice processing, multilingual NLP, and automated health outbreak monitoring.

🚀 Features

  • 💬 WhatsApp Health Chatbot using Twilio

  • 🤖 Medical-focused LLM using NVIDIA NIM / Palmyra-Med-70B

  • 📚 Retrieval-Augmented Generation (RAG) for grounded responses

  • 🔎 FAISS vector search for semantic document retrieval

  • 🌍 Multilingual support

    • English
    • Tamil
    • Hindi
  • 🎙️ Voice message processing

    • Whisper speech-to-text
    • gTTS text-to-speech
  • 🏥 External health information integration

    • WHO
    • MedlinePlus
    • disease.sh
  • 🚨 Health outbreak monitoring

    • RSS-based monitoring
    • automated alert processing
    • subscriber notifications

System Architecture

flowchart LR

    A["WhatsApp User"] --> B["Twilio WhatsApp API"]
    B --> C["Flask Webhook"]
    C --> D{"Request Validation"}

    D -->|Valid| E["Language Detection"]
    D -->|Invalid| X["Reject Request"]

    E --> F{"Message Type"}

    F -->|Text| G["User Query"]
    F -->|Voice| H["Whisper Speech-to-Text"]

    H --> G

    G --> I["RAG Pipeline"]
    I --> J["Sentence Transformer"]
    J --> K["FAISS Semantic Search"]
    K --> L["Relevant Health Context"]

    L --> M["Medical LLM<br/>NVIDIA NIM / Palmyra-Med-70B"]

    G --> M

    M --> N["Medical Safety Layer"]
    N --> O{"Response Type"}

    O -->|Text| P["Text Response"]
    O -->|Voice| Q["gTTS Text-to-Speech"]

    P --> R["Twilio WhatsApp API"]
    Q --> R
    R --> S["WhatsApp User"]


    T["WHO / MedlinePlus / disease.sh"] --> I


    U["Health RSS Feeds"] --> V["Outbreak Monitoring"]
    W["APScheduler"] --> V
    V --> X1["Alert Processing"]
    X1 --> Y["Admin Review"]
    Y --> Z["Subscriber Management"]
    Z --> AA["WhatsApp Alert Broadcast"]
    AA --> B


    AB["Admin API"] --> AC["Admin Authentication"]
    AC --> Y
Loading

Voice Processing

WhatsApp Voice Message
        │
        ▼
      Twilio
        │
        ▼
 Media Download
        │
        ▼
     Whisper
        │
        ▼
 Speech-to-Text
        │
        ▼
 Language Detection
        │
        ▼
      RAG + LLM
        │
        ▼
     Response
        │
        ▼
      gTTS
        │
        ▼
 Audio Response
        │
        ▼
     WhatsApp

Outbreak Monitoring

flowchart LR

    A["WHO / Health RSS Feeds"] --> B["Feed Monitoring"]

    B --> C["Article Processing"]

    C --> D["Alert Detection"]

    D --> E["Admin Approval"]

    E --> F["Subscriber Management"]

    F --> G["WhatsApp Notifications"]

    G --> H["Subscribers"]
Loading

🧰 Technology Stack

Component Technology
Backend Python
Web Framework Flask
Messaging WhatsApp + Twilio
LLM NVIDIA NIM / Palmyra-Med-70B
AI API OpenAI-compatible API
RAG Retrieval-Augmented Generation
Vector Database FAISS
Embeddings Sentence Transformers
Speech-to-Text OpenAI Whisper
Text-to-Speech Google Text-to-Speech (gTTS)
Language Detection langdetect + ensemble detection
PDF Processing pypdf
Feed Monitoring feedparser
Scheduling APScheduler
HTTP Requests Requests
Tunneling pyngrok
Storage JSON
Testing Python unittest

📁 Project Structure

Health_Chatbot/
│
├── app.py
├── config.py
├── requirements.txt
├── README.md
├── .env.example
├── .gitignore
│
├── bot/
│   ├── __init__.py
│   ├── external_apis.py
│   ├── feeds.py
│   ├── language.py
│   ├── llm.py
│   ├── rag.py
│   ├── storage.py
│   └── voice.py
│
├── routes/
│   ├── __init__.py
│   ├── admin.py
│   └── webhook.py
│
└── tests/
    ├── __init__.py
    └── test_healthbot.py

Runtime directories such as .venv/, data/, __pycache__/, temporary files, generated audio, and local runtime state are excluded from version control through .gitignore.


⚙️ Requirements

  • Python 3.10+
  • Twilio account with WhatsApp access
  • NVIDIA API key
  • Internet connection for external APIs and model services
  • FFmpeg for audio processing where required by the voice pipeline

🔧 Installation

1. Clone the repository

git clone https://github.com/MathuBharathi/Health_Chatbot.git
cd Health_Chatbot

2. Create a virtual environment

Windows:

python -m venv .venv
.venv\Scripts\Activate.ps1

Linux/macOS:

python3 -m venv .venv
source .venv/bin/activate

3. Install dependencies

python -m pip install --upgrade pip
pip install -r requirements.txt

🔐 Environment Configuration

Create a .env file based on .env.example.

TWILIO_ACCOUNT_SID=your_twilio_account_sid
TWILIO_AUTH_TOKEN=your_twilio_auth_token
TWILIO_WHATSAPP_NUMBER=your_whatsapp_number

NVIDIA_API_KEY=your_nvidia_api_key

ADMIN_TOKEN=your_secure_admin_token
FLASK_SECRET_KEY=your_random_secret_key

FLASK_DEBUG=false
SKIP_TWILIO_VALIDATION=false

Important

Never commit .env to GitHub.

Only .env.example containing placeholder values should be committed.

Generate a strong random value for:

FLASK_SECRET_KEY
ADMIN_TOKEN

📱 WhatsApp / Twilio Setup

  1. Create and configure a Twilio account.

  2. Enable WhatsApp messaging.

  3. Obtain:

    • Account SID
    • Auth Token
    • WhatsApp sender number
  4. Configure the WhatsApp webhook to point to the Flask application.

For local development, a tunneling service such as ngrok can expose the local Flask server.

Example:

https://your-ngrok-url/webhook

Webhook Security

Production mode uses Twilio request signature validation.

The recommended configuration is:

SKIP_TWILIO_VALIDATION=false

Development bypass can be explicitly enabled when necessary:

SKIP_TWILIO_VALIDATION=true

Do not use validation bypass in a production deployment.


🤖 NVIDIA NIM / Medical LLM

HealthBot uses a medical-focused LLM through an NVIDIA NIM-compatible API.

Configure the API key through:

NVIDIA_API_KEY=your_nvidia_api_key

The application should never contain the actual API key in source code.

The LLM is used together with retrieved contextual information when available.


📚 Retrieval-Augmented Generation

HealthBot uses RAG to improve the grounding of responses.

The general pipeline is:

Medical Documents
       │
       ▼
    PDF/Text
       │
       ▼
   Text Chunks
       │
       ▼
Sentence Transformer
       │
       ▼
   Embeddings
       │
       ▼
     FAISS
       │
       ▼
Semantic Retrieval
       │
       ▼
Relevant Context
       │
       ▼
Medical LLM
       │
       ▼
Grounded Response

The application includes defensive handling for situations such as:

  • missing indexes
  • corrupted indexes
  • missing metadata
  • empty documents
  • empty retrieval results
  • unavailable embedding models

🌍 Multilingual Support

HealthBot supports:

  • 🇬🇧 English
  • 🇮🇳 Tamil
  • 🇮🇳 Hindi

Language detection is performed before processing the user's request.

The detected language is used to provide an appropriate response.

The application is designed to preserve Unicode text throughout the processing pipeline.


🎙️ Voice Support

HealthBot supports voice messages through the WhatsApp integration.

Speech-to-Text

OpenAI Whisper is used to convert incoming audio into text.

Voice Message
     ↓
Audio Download
     ↓
Whisper
     ↓
Transcribed Text

Text-to-Speech

Generated responses can be converted back into speech using gTTS.

AI Response
     ↓
gTTS
     ↓
Audio File
     ↓
WhatsApp

Temporary audio files are cleaned up after processing.


🏥 External Health Information

HealthBot can integrate external health information sources including:

  • WHO
  • MedlinePlus
  • disease.sh

External services are handled with timeout and error-handling mechanisms so that a temporary API failure does not unnecessarily crash the application.


🚨 Outbreak Monitoring

HealthBot includes an automated health-outbreak monitoring component.

The system can process health-related RSS feeds and identify relevant updates.

The general workflow is:

Health RSS Feeds
      ↓
Feed Fetching
      ↓
Article Parsing
      ↓
Alert Processing
      ↓
Admin Review
      ↓
Subscriber Notification

APScheduler is used for background scheduled operations.


🚀 Running the Application

After configuring .env:

python app.py

The Flask application will start according to the configured environment.

For local WhatsApp development, expose the application through a secure HTTPS tunnel and configure the corresponding Twilio webhook.


🧑‍💻 Development

Recommended development workflow:

git pull

Create or activate the virtual environment:

python -m venv .venv

Install dependencies:

pip install -r requirements.txt

Run tests:

python -m unittest discover -s tests -p "test_*.py" -v

Check syntax:

python -m compileall .

📌 Project Goals

HealthBot demonstrates how multiple AI and software engineering technologies can be combined into a single conversational healthcare platform:

  • Generative AI
  • Medical language models
  • Retrieval-Augmented Generation
  • Semantic search
  • Voice AI
  • Multilingual NLP
  • WhatsApp automation
  • Health information APIs
  • Real-time health monitoring
  • Automated notifications
  • Secure backend development

📄 License

This project currently does not include an open-source license.

Until a license is added, the source code should not be assumed to be freely reusable, modified, or redistributed.


👨‍💻 Author

MathuBharathi

GitHub: https://github.com/MathuBharathi

About

Multilingual AI health assistant for WhatsApp with RAG, medical LLMs, voice support, and real-time health outbreak monitoring.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Contributors

Languages