Skip to content

Priyanshi-Solanki/Medical-Chatbot

Repository files navigation

HealthBot v2.0 - AI Medical Information Assistant 🏥

An advanced AI-powered medical information assistant optimized for Streamlit Cloud deployment.

🔄 Processing Flow

User Input → Normalize → Symptom Rules → MedQuad/MIMIC-III Search → Gemini 1.5 Flash → Response

✨ Key Features

  • 🧠 Context-Aware Conversations: Thread-based memory system
  • 📚 Multi-Dataset Integration: MedQuad + MIMIC-III + Custom rules
  • ⚡ Gemini 1.5 Flash: Fast AI-powered response generation
  • 🎯 Streamlit Cloud Optimized: Ready for immediate deployment
  • 🔒 Secure API Management: Server-side API key configuration

🚀 Quick Local Testing

1. Setup Project Structure

# Create project directory
mkdir healthbot-v2
cd healthbot-v2

# Create required directories
mkdir .streamlit

2. Create Files

Copy each section from this package into separate files:

  • app.py (main application)
  • requirements.txt (dependencies)
  • symptoms.json (medical data)
  • .streamlit/config.toml (UI config)
  • .gitignore (git ignore rules)
  • README.md (documentation)

3. Local Environment Setup

# Create virtual environment
python -m venv healthbot_env

# Activate virtual environment
# Windows:
healthbot_env\Scripts\activate
# macOS/Linux:
source healthbot_env/bin/activate

# Install dependencies
pip install -r requirements.txt

4. Configure API Key for Local Testing

# Create .streamlit/secrets.toml for local testing
echo 'GEMINI_API_KEY = "your_actual_api_key_here"' > .streamlit/secrets.toml

# Get your API key from: https://makersuite.google.com/app/apikey

5. Test Locally

# Run the application
streamlit run app.py

# Open browser to: http://localhost:8501

6. Verify Local Testing

  • ✅ App loads without errors
  • ✅ Sidebar shows dataset information
  • ✅ Chat interface is responsive
  • ✅ AI responses are generated (with API key)
  • ✅ Medical databases load properly

🌐 Streamlit Cloud Deployment

Step 1: Prepare Repository

# Initialize git repository
git init

# Add files (secrets.toml will be ignored)
git add .

# Commit changes
git commit -m "Initial HealthBot v2.0 deployment"

# Push to GitHub
git remote add origin https://github.com/yourusername/healthbot-v2.git
git branch -M main
git push -u origin main

Step 2: Deploy to Streamlit Cloud

  1. Go to share.streamlit.io
  2. Sign in with your GitHub account
  3. Click "New app"
  4. Select your repository: yourusername/healthbot-v2
  5. Set main file path: app.py
  6. Click "Advanced settings"
  7. Add secrets:
    GEMINI_API_KEY = "your_actual_gemini_api_key_here"
    
  8. Click "Deploy!"

Step 3: Verify Deployment

  • ✅ App deploys successfully
  • ✅ All datasets load properly
  • ✅ AI integration works
  • ✅ Chat functionality operational
  • ✅ No errors in logs

🔧 Configuration Guide

Getting Gemini API Key

  1. Visit Google AI Studio
  2. Sign in with Google account
  3. Click "Create API Key"
  4. Copy the generated key
  5. Add to Streamlit Cloud secrets

Streamlit Cloud Secrets

In your Streamlit Cloud dashboard:

  1. Go to your app settings
  2. Click on "Secrets"
  3. Add:
    GEMINI_API_KEY = "your_actual_api_key_here"

File Structure

healthbot-v2/
├── app.py                    # Main application (Streamlit expects app.py)
├── requirements.txt          # Dependencies
├── symptoms.json            # Medical symptom database
├── .streamlit/
│   └── config.toml         # UI configuration
├── .gitignore              # Git ignore rules
└── README.md              # This file

🔍 Testing Checklist

Local Testing

  • Virtual environment created and activated
  • All dependencies installed without errors
  • API key configured in .streamlit/secrets.toml
  • App runs with streamlit run app.py
  • No errors in terminal/console
  • Medical datasets load successfully
  • Chat interface responds to user input
  • AI generates relevant responses

Streamlit Cloud Testing

  • Repository pushed to GitHub
  • Streamlit Cloud deployment successful
  • API key added to Cloud secrets
  • App accessible via provided URL
  • All features working in production
  • No errors in Cloud logs

📊 Features Overview

Data Processing Pipeline

  1. Input Normalization: Clean and standardize user input
  2. Symptom Rule Matching: Apply pattern matching from medical rules
  3. Database Search: Query MedQuad and MIMIC-III datasets
  4. Context Integration: Include conversation history
  5. AI Enhancement: Process through Gemini 1.5 Flash
  6. Response Generation: Deliver comprehensive, contextual response

Medical Data Sources

  • MedQuad: 47,000+ medical Q&A pairs from trusted sources
  • MIMIC-III: Clinical conversations and professional guidance
  • Custom Database: Specialized symptom-advice mappings
  • Rule Engine: Pattern matching from medical knowledge base

AI Integration

  • Model: Gemini 1.5 Flash for fast, accurate responses
  • Context: Thread-based conversation memory
  • Safety: Built-in medical disclaimers and safety guidelines
  • Fallback: Graceful degradation when AI is unavailable

⚠️ Important Notes

Medical Disclaimer

This application provides general health information only and is not a substitute for professional medical advice, diagnosis, or treatment. Always consult qualified healthcare professionals for medical concerns.

API Key Security

  • Never commit API keys to version control
  • Use Streamlit Cloud secrets for production
  • Use .streamlit/secrets.toml for local development only
  • Add secrets.toml to .gitignore

Performance Considerations

  • Dataset loading is cached for 1 hour
  • Conversation history limited to last 10 messages
  • Database search results limited to top 3 per source
  • Response length optimized for readability

🐛 Troubleshooting

Common Issues

"Gemini API key not found"

  • Solution: Add API key to Streamlit Cloud secrets
  • Local: Check .streamlit/secrets.toml exists and has correct key

"Dataset loading failed"

  • Solution: Check internet connection and Hugging Face access
  • App will work with fallback data if datasets fail

"ModuleNotFoundError"

  • Solution: Ensure all requirements are installed
  • Run: pip install -r requirements.txt

App won't start locally

  • Solution: Check Python version (3.9+ recommended)
  • Verify virtual environment is activated
  • Check for syntax errors in app.py

Support Resources

📈 Version History

v2.0 Features

  • ✅ Streamlit Cloud optimized deployment
  • ✅ Enhanced conversation context management
  • ✅ Improved medical database integration
  • ✅ Gemini 1.5 Flash AI integration
  • ✅ Better error handling and fallbacks
  • ✅ Clean, professional UI design
  • ✅ Comprehensive medical disclaimer system

🏥 HealthBot v2.0 - Advanced Medical Information Assistant
Powered by Gemini 1.5 Flash + Medical Databases + AI

Releases

No releases published

Packages

 
 
 

Contributors

Languages