MedPrompt AI is an innovative medical assistant chatbot engineered to deliver accurate, empathetic, and comprehensive information based on a robust medical knowledge base. It harnesses the power of cutting-edge large language models (LLMs) and an advanced Retrieval-Augmented Generation (RAG) system, designed to be your intelligent companion for medical inquiries.
- Dual LLM Integration: Seamlessly integrates with both Google's Gemini-1.5-Flash and Mistral AI models, ensuring diverse perspectives and robust medical insights.
- Retrieval-Augmented Generation (RAG): Built upon a sophisticated RAG architecture that queries a FAISS vector index of pre-processed medical text chunks, providing context-aware and highly accurate responses grounded in factual data.
- Smart Conversation History: Efficiently manages and intelligently summarizes long chat histories to maintain crucial conversational context throughout your interactions.
- Streamed Responses: Delivers AI-generated content in a real-time streaming fashion, enhancing user engagement and providing a dynamic chat experience.
- Intuitive User Interface: Features a responsive and modern web interface, developed with Flask, HTML, CSS (Tailwind CSS), and JavaScript, ensuring seamless and visually appealing interactions.
- Voice Capabilities (STT & TTS): Enhances accessibility with both speech-to-text (STT) for microphone input and optional text-to-speech (TTS) for voice output of AI responses.
- Crystal Clear Formatting: AI responses are meticulously formatted using markdown, incorporating bold text, clear headings (
##
), and organized lists (*
) for superior readability and information retention. - Quick Action Buttons: Offers pre-defined quick action buttons for common medical queries, simplifying the process of initiating conversations and exploring topics.
- Backend Framework: Flask (Python)
- Large Language Models:
- Google Gemini (
gemini-1.5-flash
) - Mistral AI (
mistral-tiny
)
- Google Gemini (
- Embeddings:
sentence-transformers
(model:BAAI/bge-base-en-v1.5
) - Vector Database: FAISS (
faiss-cpu
) - Natural Language Toolkit (NLTK): For text processing utilities like sentence tokenization.
- Data Handling:
numpy
,pickle
,requests
. - Frontend: HTML, CSS (Tailwind CSS), JavaScript, Font Awesome.
- Environment Variables:
python-dotenv
.
Follow these steps to get the MedPrompt AI Chatbot up and running on your local machine.
- Python 3.9+
pip
(Python package installer)
The application requires API keys for Google Gemini and Mistral AI to function.
- Gemini API Key: Obtain yours from the Google AI Studio.
- Mistral API Key: Get your key from the Mistral AI Platform.
Once you have your keys, create a .env
file in the root directory of your project (e.g., MedPrompt AI Chatbot/.env
) with the following content, replacing the placeholder values with your actual API keys:
GEMINI_API_KEY=YOUR_GEMINI_API_KEY
MISTRAL_API_KEY=YOUR_MISTRAL_API_KEY
Security Note: Remember to add .env
to your .gitignore
file to prevent your API keys from being accidentally committed to version control.
The MedPrompt AI Chatbot's RAG system is built upon a knowledge base derived from medical textbooks. While this project uses a custom dataset, the MedQA-USMLE Dataset on Kaggle is a relevant public medical dataset that can be referenced or used for similar applications.
The chatbot relies on pre-processed medical text chunks and a FAISS index for its RAG capabilities. You have two convenient options to obtain these:
You can directly download the medical_faiss_index.bin
and medical_text_chunks.pkl
files from the following Google Drive link. After downloading, create a new directory named medprompt_ai_data
in the root of your project and place these files inside it:
MedPrompt AI Data on Google Drive
If you prefer to generate the data yourself, you can run the model.ipynb
notebook on Google Colab.
- Recommendation: Utilize a T4 GPU runtime in Colab for significantly faster processing.
- This notebook will guide you through:
- Installing necessary libraries.
- Downloading NLTK data (handled automatically by the notebook).
- Mounting your Google Drive to access your medical textbooks (you'll need to provide your own
.txt
medical textbook files in a folder likeMedical_Textbooks
on your Google Drive). - Processing the textbooks, generating embeddings, and building the FAISS index.
- Saving
medical_faiss_index.bin
andmedical_text_chunks.pkl
to your specifiedSAVE_DIR
(e.g.,/content/drive/MyDrive/medprompt_ai_data
).
Ensure these generated files are then accessible to your app.py
(e.g., by placing them in a medprompt_ai_data
folder in your project directory).
You can install all the required Python packages using pip
.
If you have a requirements.txt
file (which lists all project dependencies), simply run:
pip install -r requirements.txt
Alternatively, you can install each core dependency by listing them in a single pip install
command:
pip install flask python-dotenv google-generativeai sentence-transformers faiss-cpu nltk numpy requests scipy
It's highly recommended to install dependencies within a virtual environment. This isolates your project's dependencies, preventing conflicts with other Python projects on your system.
- Create a virtual environment:
python -m venv venv
- Activate the virtual environment:
- On macOS/Linux:
source venv/bin/activate
- On Windows:
.\venv\Scripts\activate
- On macOS/Linux:
- Install the dependencies within the activated environment:
Once installed, you can run your application. To exit the virtual environment, simply type
pip install flask python-dotenv google-generativeai sentence-transformers faiss-cpu nltk numpy requests scipy
deactivate
.
Once you have set up your API keys and the data files, you can launch the Flask application:
python app.py
The application will start, and you can usually access it by opening your web browser and navigating to http://127.0.0.1:5000/
.
Note: For production deployment, it is recommended to use a production-ready WSGI server like Gunicorn instead of Flask's built-in development server.
- Access the Chatbot: Open your web browser and go to the address where the Flask app is running (e.g.,
http://127.0.0.1:5000/
). - Ask a Question: Type your medical question into the input box at the bottom of the chat interface.
- Send Message: Press
Enter
or click the send button (the paper plane icon) to submit your question. - Receive Response: The AI will swiftly process your question, retrieve relevant context, and synthesize a comprehensive answer, which will be streamed to the chat interface.
- Voice Input/Output:
- Click the microphone icon to speak your question directly.
- Click the volume icon to toggle voice output for the AI's responses on or off.
- New Chat: Click the "New Chat" button to start a fresh conversation at any time.
DISCLAIMER: This AI tool is for informational purposes only and is not a substitute for professional medical advice. Always consult a qualified healthcare provider.