Skip to content

Siddhant231xyz/Medical-ChatBot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

17 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Medical Chatbot with Appointment Booking πŸ₯

Python Streamlit OpenAI LangChain License

Overview 🎯

The Medical Chatbot is a Streamlit-powered virtual medical assistant that combines advanced NLP with appointment scheduling capabilities. Using retrieval-augmented generation (RAG) techniques and trusted medical references, it provides accurate, empathetic medical information while enabling patients to book appointments directly. Appointment data is stored in an AWS RDS database.

Medical Chatbot Demo

image

Features ✨

  • πŸ€– Intelligent Medical Q&A

    • RAG-based information retrieval from a medical book PDF
    • Empathetic and reassuring responses
    • Suggestions to book an appointment if symptoms are severe
  • πŸ’¬ Interactive Interface

    • User-friendly Streamlit interface
    • Context-aware and friendly conversation design
  • πŸ“… Appointment Management

    • Easy-to-use appointment booking form
    • Appointment details stored directly into an AWS RDS database
    • Option to view booked appointments directly in the app
  • πŸ”’ Safety & Compliance

    • Medical disclaimers
    • Emphasis on educational and supportive guidance

Technical Architecture πŸ—οΈ

medical-chatbot/
β”œβ”€β”€ app.py                 # Main Streamlit application with medical Q&A & appointment booking
β”œβ”€β”€ requirements.txt       # Project dependencies
β”œβ”€β”€ Dockerfile             # Containerization instructions
β”œβ”€β”€ .dockerignore          # Files to ignore when building the Docker image
β”œβ”€β”€ .streamlit/secrets.toml           # Secrets file (contains DATABASE_URL, etc.)
β”œβ”€β”€ app_local.py           # Streamlit app for localhost

image

How It Works

  1. Document Processing

    • A medical book PDF is uploaded and processed by splitting its text into chunks.
    • LangChain is used to create embeddings and retrieve context for answering user queries.
  2. Conversation Flow

    • The user asks medical questions.
    • The chatbot responds in a friendly, compassionate manner and suggests booking an appointment if symptoms seem severe.
  3. Appointment Booking

    • Users can book an appointment by filling out a form.
    • Appointment details are inserted directly into an AWS RDS database using SQLAlchemy.
  4. Viewing Appointments

    • A separate section in the app displays the list of booked appointments.

Installation πŸš€

Prerequisites

  • Python 3.7+
  • Docker (for containerization)
  • Git
  • An OpenAI API key
  • AWS RDS (MySQL/PostgreSQL) instance for storing appointments

Setup Steps

  1. Clone the Repository:

    git clone https://github.com/Siddhant231xyz/Medical-ChatBot.git
    cd Medical-ChatBot
  2. Create a Virtual Environment (for local development):

    python -m venv venv
    source venv/bin/activate  # On Windows: venv\Scripts\activate
  3. Install Dependencies:

    pip install -r requirements.txt
  4. Configure Secrets:

    Create a directory named .streamlit in the project root and add a secrets.toml file:

    # .streamlit/secrets.toml
    DATABASE_URL = "postgresql://username:password@your-rds-endpoint:port/dbname"
    OPENAI_API_KEY = "your-api-key-here"

    Note: Ensure the connection string is wrapped in quotes.

Usage Guide πŸ“š

  1. Start the Application:

    streamlit run app.py
  2. Interact with the Chatbot:

    • Upload a medical book PDF.
    • Ask medical questions to receive friendly, empathetic responses.
    • Use the appointment booking form to schedule an appointment.
    • View the list of booked appointments in the "View Appointments" section.

Deployment Options 🌐

Docker Deployment

This application is containerized using Docker. Follow these steps:

  1. Dockerfile:

    The provided Dockerfile contains:

    FROM python:3.9-slim
    
    ENV PYTHONDONTWRITEBYTECODE=1
    ENV PYTHONUNBUFFERED=1
    ENV OPENAI_API_KEY="<api_key>"
    
    WORKDIR /app
    
    # Copy and install dependencies
    COPY requirements.txt /app/
    RUN pip install --upgrade pip && pip install -r requirements.txt
    
    # Copy application code and secrets
    COPY app.py /app/
    COPY .streamlit /app/.streamlit
    
    # Expose Streamlit's default port
    EXPOSE 8501
    
    # Run the Streamlit app
    CMD ["streamlit", "run", "app.py", "--server.port=8501", "--server.address=0.0.0.0"]
  2. .dockerignore File:

    __pycache__/
    *.pyc
    venv/
    
  3. Build the Docker Image:

    docker build -t medical-chatbot .
  4. Run the Docker Container:

    docker run -d -p 8501:8501 medical-chatbot

AWS EC2 Deployment

  1. Launch an EC2 Instance:

    • Use an Amazon Linux 2 (or similar) instance.
    • Attach an IAM role with appropriate permissions if needed.
  2. Install Docker on the EC2 Instance:

    sudo yum update -y
    sudo amazon-linux-extras install docker -y
    sudo service docker start
    sudo usermod -a -G docker ec2-user
  3. Deploy Your Container:

    • Copy your project to the EC2 instance (e.g., via Git or SCP).
    • Build and run your Docker container using the commands above.

AWS RDS Setup (MySQL/PostgreSQL)

  1. Create an RDS Instance:

    • Log in to the AWS Console β†’ RDS β†’ Create database.
    • Choose MySQL or PostgreSQL.
    • Configure the instance and note the endpoint, port, username, and password.
  2. Create the Appointments Table:

    For PostgreSQL:

    CREATE TABLE appointments (
        id SERIAL PRIMARY KEY,
        name VARCHAR(255) NOT NULL,
        email VARCHAR(255) NOT NULL,
        phone VARCHAR(50) NOT NULL,
        appointment_datetime TIMESTAMP NOT NULL,
        symptoms TEXT,
        created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
    );

    For MySQL:

    CREATE TABLE appointments (
        id INT AUTO_INCREMENT PRIMARY KEY,
        name VARCHAR(255) NOT NULL,
        email VARCHAR(255) NOT NULL,
        phone VARCHAR(50) NOT NULL,
        appointment_datetime DATETIME NOT NULL,
        symptoms TEXT,
        created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
    );
  3. Configure the DATABASE_URL: Update your .streamlit/secrets.toml file with the connection string, e.g.,

    DATABASE_URL = "postgresql://username:password@your-rds-endpoint:port/dbname"

Detailed Steps & Commands

Docker:

  • Build: docker build -t medical-chatbot .
  • Run: docker run -d -p 8501:8501 medical-chatbot

EC2 Setup:

  • Update and install Docker:
    sudo yum update -y
    sudo amazon-linux-extras install docker -y
    sudo service docker start
    sudo usermod -a -G docker ec2-user
  • Deploy your container on EC2 using the Docker commands above.

RDS Setup:

  • Create an RDS instance in the AWS Console.
  • Connect with a database client (like pgAdmin, MySQL Workbench, or CLI tools) and create the appointments table using the provided SQL.

Secrets & Environment:

  • Create a .streamlit/secrets.toml file with your DATABASE_URL and OPENAI_API_KEY.
  • Ensure the secrets file is copied into the Docker container (see Dockerfile).

Contributing 🀝

We welcome contributions! Please follow these steps:

  1. Fork the repository
  2. Create a feature branch
  3. Commit your changes
  4. Push to the branch
  5. Open a Pull Request

Dependencies πŸ“¦

  • streamlit
  • langchain-openai
  • langchain-core
  • langchain-community
  • langchain-text-splitters
  • sqlalchemy
  • requests
  • numpy
  • (and other dependencies as listed in requirements.txt)

License πŸ“

This project is licensed under the MIT License - see the LICENSE file for details.

Created with ❀️ by the Medical ChatBot Team

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages