A smart, AI-powered medical assistant that helps you understand prescriptions, answer health questions, and provide general medical guidance. Built with Flask and Google's Gemini AI.
- 💬 Interactive Chat Interface - Ask medical questions and get informed responses
- 📄 Prescription Analysis - Upload prescription images and get detailed explanations of medications
- 🔍 OCR Technology - Automatically extract text from prescription images
- 💾 Chat History - All conversations are saved and can be reviewed
- 🎨 Modern UI - Clean, responsive design that works on all devices
- 🔒 Privacy Focused - All data stored locally in SQLite database
- Answer Medical Questions - Get information about symptoms, conditions, and treatments
- Explain Prescriptions - Upload prescription images and understand what medications you've been prescribed
- Medication Information - Learn about drug uses, side effects, and precautions
- Health Advice - Receive general wellness tips and guidance
- Symptom Assessment - Understand when to seek professional help
Important: This chatbot provides general information only and is not a substitute for professional medical advice, diagnosis, or treatment. Always consult qualified healthcare providers for medical decisions.
Before you begin, make sure you have:
- Python 3.8 or higher
- A Google API key (for Gemini AI)
- Tesseract OCR installed (for prescription text extraction)
If you don't have Python installed:
Windows:
- Download from python.org
- Run installer and check "Add Python to PATH"
Mac/Linux:
# Mac (using Homebrew)
brew install python3
# Ubuntu/Debian
sudo apt-get install python3 python3-pipTesseract is required for reading text from prescription images.
Windows:
- Download installer from GitHub
- Run the installer (use default installation path)
- Add to PATH:
C:\Program Files\Tesseract-OCR
Mac:
brew install tesseractLinux:
sudo apt-get install tesseract-ocr- Go to Google AI Studio
- Sign in with your Google account
- Click "Create API Key"
- Copy the key (you'll need it soon)
# If you have git
git clone <repository-url>
cd Medical-Chatbot
# Or download and extract the ZIP file, then navigate to the folderOpen terminal/command prompt in the project folder:
# Install required packages
pip install -r requirements.txtIf you encounter issues, try:
pip install --upgrade pip
pip install -r requirements.txt- Copy the example environment file:
# Windows
copy .env.example .env
# Mac/Linux
cp .env.example .env- Open
.envfile in a text editor and add your Google API key:
GOOGLE_API_KEY=your_actual_api_key_here
GENAI_MODEL=gemini-pro
DB_PATH=chat_history.db
PORT=5000
You can set your GOOGLE_API_KEY in a .env file (recommended) or in your PowerShell session.
-
Using the
.envfile (recommended):- Copy
.env.exampleto.env:copy .env.example .env
- Open
.envin a text editor and paste your actual API key:GOOGLE_API_KEY=your_actual_api_key_here
- Copy
-
Setting for the current PowerShell session (temporary):
$env:GOOGLE_API_KEY = 'your_actual_api_key_here'
-
Setting permanently for your user (persists across sessions):
[Environment]::SetEnvironmentVariable('GOOGLE_API_KEY', 'your_actual_api_key_here', 'User')
After setting the key, restart your terminal or IDE so environment variables are picked up.
- With the environment configured, run the app:
python app.pyIf GOOGLE_API_KEY is missing the app will print a clear error and exit. If configured correctly, the server should start and be available at http://localhost:5000.
python app.pyYou should see output like:
* Running on http://0.0.0.0:5000
* Running on http://127.0.0.1:5000
Open your web browser and go to:
http://localhost:5000
Simply type your question in the chat box:
- "What causes headaches?"
- "How to treat a common cold?"
- "What are symptoms of diabetes?"
- Click the file input under "Upload Prescription Image"
- Select a clear photo of your prescription (JPG, PNG, etc.)
- Click "Analyze" button
- Wait for the AI to extract and explain the medications
Tips for Best Results:
- Take photos in good lighting
- Ensure text is clear and readable
- Avoid shadows or glare
- Keep the image straight and in focus
Click the "Clear History" button in the top-right corner to delete all conversations.
Medical-Chatbot/
├── app.py # Main Flask application
├── db.py # Database operations
├── medical_assistant.py # AI response generation
├── prescription_handler.py # OCR and prescription processing
├── llm.py # Legacy compatibility layer
├── requirements.txt # Python dependencies
├── .env # Environment configuration
├── .env.example # Example environment file
├── chat_history.db # SQLite database (created automatically)
├── templates/
│ └── index.html # Frontend interface
└── uploads/ # Uploaded prescription images
pip install -r requirements.txt --force-reinstall- Check that
.envfile exists - Verify API key is correct
- Make sure no extra spaces in
.envfile
# Edit prescription_handler.py and uncomment this line (Windows):
pytesseract.pytesseract.tesseract_cmd = r'C:\Program Files\Tesseract-OCR\tesseract.exe'Change the port in .env:
PORT=8000
- Verify Tesseract is installed:
tesseract --version - Check image file is a supported format
- Ensure image text is clear and readable
- This is normal - AI processing takes a few seconds
- Check your internet connection
- Verify Google API key has sufficient quota
The codebase is modular:
- medical_assistant.py - Modify AI prompts and response logic
- prescription_handler.py - Enhance OCR or parsing algorithms
- templates/index.html - Update UI and styling
- app.py - Add new API endpoints
Debug mode is enabled by default. To disable:
# In app.py, change:
app.run(debug=False, host='0.0.0.0', port=port)- Never commit
.envfile to version control - Keep your Google API key private
- Uploaded files are stored in
uploads/folder - Database file contains all chat history
- Consider implementing user authentication for production use
GET /- Main chat interfacePOST /api/chat- Send text messagePOST /api/upload-prescription- Upload prescription imagePOST /api/clear-history- Clear chat history
- Flask - Web framework
- langchain - LLM integration
- langchain-google-genai - Google Gemini AI
- pytesseract - OCR for image text extraction
- Pillow - Image processing
- python-dotenv - Environment variable management
- Prescription OCR accuracy depends on image quality
- AI responses are general information only
- Requires active internet connection
- Google API has rate limits (check your quota)
Potential improvements:
- User authentication system
- Export chat history to PDF
- Multi-language support
- Voice input/output
- Medication reminder system
- Integration with pharmacy databases
This project is for educational purposes. Always consult healthcare professionals for medical advice.
If you encounter issues:
- Check this README's troubleshooting section
- Verify all prerequisites are installed
- Review error messages in terminal
- Check that API key is valid and has quota
This medical chatbot is an informational tool and should not be used as a substitute for professional medical advice, diagnosis, or treatment. Always seek the advice of your physician or other qualified health provider with any questions you may have regarding a medical condition.
Made with ❤️ for better health awareness