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.
-
π€ 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
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
-
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.
-
Conversation Flow
- The user asks medical questions.
- The chatbot responds in a friendly, compassionate manner and suggests booking an appointment if symptoms seem severe.
-
Appointment Booking
- Users can book an appointment by filling out a form.
- Appointment details are inserted directly into an AWS RDS database using SQLAlchemy.
-
Viewing Appointments
- A separate section in the app displays the list of booked appointments.
- Python 3.7+
- Docker (for containerization)
- Git
- An OpenAI API key
- AWS RDS (MySQL/PostgreSQL) instance for storing appointments
-
Clone the Repository:
git clone https://github.com/Siddhant231xyz/Medical-ChatBot.git cd Medical-ChatBot -
Create a Virtual Environment (for local development):
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install Dependencies:
pip install -r requirements.txt
-
Configure Secrets:
Create a directory named
.streamlitin the project root and add asecrets.tomlfile:# .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.
-
Start the Application:
streamlit run app.py
-
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.
This application is containerized using Docker. Follow these steps:
-
Dockerfile:
The provided
Dockerfilecontains: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"]
-
.dockerignore File:
__pycache__/ *.pyc venv/ -
Build the Docker Image:
docker build -t medical-chatbot . -
Run the Docker Container:
docker run -d -p 8501:8501 medical-chatbot
-
Launch an EC2 Instance:
- Use an Amazon Linux 2 (or similar) instance.
- Attach an IAM role with appropriate permissions if needed.
-
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
-
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.
-
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.
-
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 );
-
Configure the DATABASE_URL: Update your
.streamlit/secrets.tomlfile with the connection string, e.g.,DATABASE_URL = "postgresql://username:password@your-rds-endpoint:port/dbname"
- Build:
docker build -t medical-chatbot . - Run:
docker run -d -p 8501:8501 medical-chatbot
- 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.
- 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.
- Create a
.streamlit/secrets.tomlfile with your DATABASE_URL and OPENAI_API_KEY. - Ensure the secrets file is copied into the Docker container (see Dockerfile).
We welcome contributions! Please follow these steps:
- Fork the repository
- Create a feature branch
- Commit your changes
- Push to the branch
- Open a Pull Request
- streamlit
- langchain-openai
- langchain-core
- langchain-community
- langchain-text-splitters
- sqlalchemy
- requests
- numpy
- (and other dependencies as listed in requirements.txt)
This project is licensed under the MIT License - see the LICENSE file for details.


