A production-ready AI-powered medical assistant built with LangChain and Google Gemini 2.0. Demonstrates best practices for building intelligent healthcare applications with natural language processing, document analysis, and research capabilities.
Click the preview to watch the full demonstration
Click the link above to see the Medical AI Assistant in action.
- AI Medical Consultation - Natural language medical Q&A with context-aware responses
- Medical Record Analysis - Automated analysis of lab results, prescriptions, and clinical documents
- OCR Text Extraction - Extract text from handwritten or printed medical documents
- Medical Research Search - Query trusted medical databases (PubMed, WHO, CDC) with AI-powered summarization
- Bilingual Support - Complete English and French language support
- Modern Architecture - FastAPI, LangChain, Google Gemini 2.0 (free tier available)
| Technology | Purpose |
|---|---|
| FastAPI | High-performance async backend framework |
| LangChain | AI orchestration and chain operations |
| Google Gemini 2.0 | Multimodal AI model (text + vision) |
| Tavily AI | AI-powered medical research search |
| Pydantic | Data validation and settings management |
| Python 3.11+ | Core programming language |
backend/
├── app/
│ ├── main.py # FastAPI application
│ ├── config.py # Settings & environment
│ ├── routes/
│ │ ├── health.py # Health check endpoints
│ │ ├── analysis.py # Medical analysis endpoints
│ │ └── research.py # Research endpoints
│ ├── services/
│ │ ├── gemini_service.py # Gemini Vision operations
│ │ └── tavily_service.py # Medical research
│ ├── chains/
│ │ ├── chat_chain.py # LangChain chat flows
│ │ └── analysis_chain.py # LangChain analysis flows
│ └── models/
│ └── schemas.py # Pydantic data models
├── requirements.txt
├── .env.example
└── README.md
- Python 3.11 or higher
- pip (Python package manager)
- API Keys (both free):
git clone https://github.com/yourusername/medical-ai-assistant.git
cd medical-ai-assistant/backendpython -m venv venv
# Activate (Windows)
venv\Scripts\activate
# Activate (Mac/Linux)
source venv/bin/activatepip install --upgrade pip
pip install -r requirements.txtCreate a .env file in the backend/ directory:
GOOGLE_API_KEY=your_gemini_api_key_here
TAVILY_API_KEY=your_tavily_api_key_here
HOST=0.0.0.0
PORT=8000
CORS_ORIGINS=http://localhost:3000,http://127.0.0.1:3000
GEMINI_MODEL=gemini-2.0-flash-exp
TEMPERATURE=0.7
MAX_TOKENS=2048Important: Add .env to .gitignore to keep your API keys secure.
uvicorn app.main:app --reloadThe API will be available at http://localhost:8000
Once running, access the interactive documentation:
- Swagger UI: http://localhost:8000/docs
- ReDoc: http://localhost:8000/redoc
GET /api/health
Returns server status and timestamp.
POST /api/chat
{
"message": "What are the symptoms of diabetes?",
"language": "en"
}
Get AI-powered medical information in English or French.
POST /api/analyze-text
{
"text": "Patient presents with elevated blood pressure...",
"context": "45-year-old male",
"language": "en"
}
Analyze medical text and receive structured insights.
POST /api/analyze-image
- file: medical_record.jpg
- language: en
- extract_text_only: false
Extract text from medical images and analyze them.
POST /api/extract-text
- file: prescription.jpg
Extract text from medical documents (OCR only).
POST /api/research
{
"query": "latest treatments for hypertension",
"max_results": 5,
"language": "en"
}
Search trusted medical databases with AI-generated summaries.
- Navigate to http://localhost:8000/docs
- Click on any endpoint to expand it
- Click "Try it out"
- Fill in the parameters
- Click "Execute"
- View the response below
See the full guide for detailed testing instructions.
All endpoints return structured JSON with timestamps and proper error handling.
Example chat response:
{
"response": "Early signs of diabetes include frequent urination...",
"language": "en",
"timestamp": "2025-09-30T14:25:30.456789"
}Example analysis response:
{
"summary": "Blood test shows elevated glucose levels...",
"key_findings": [
"Fasting glucose: 126 mg/dL (elevated)",
"Blood pressure: 150/95 mmHg (stage 1 hypertension)"
],
"recommendations": [
"Monitor blood sugar levels daily",
"Reduce sodium intake"
],
"next_steps": [
"Schedule appointment with endocrinologist",
"Start dietary modifications"
],
"disclaimer": "This analysis is for informational purposes only...",
"language": "en",
"timestamp": "2025-09-30T14:30:15.789012"
}chain = prompt | llm | parserClean, composable AI workflows with built-in async support and error handling.
Type-safe configuration with automatic validation and IDE autocomplete support.
Forces AI models to return valid JSON matching your data models.
Processes both text and images in a single model for document analysis.
- Environment variables for sensitive data
- No persistent data storage
- CORS protection enabled
- Input validation with Pydantic
- Medical disclaimer on all responses
"Module not found" errors:
pip install -r requirements.txt"Invalid API key" errors:
- Verify your
.envfile exists - Check API keys are valid
- Ensure no extra spaces in keys
Slow responses:
- Vision/research endpoints take 5-15 seconds (normal)
- Check internet connection
- Monitor API rate limits
pytestblack app/
ruff app/mypy app/docker build -t medical-ai-assistant .
docker run -p 8000:8000 medical-ai-assistant- Deploy to Railway, Render, or Google Cloud Run
- Set environment variables in platform settings
- Use production ASGI server (gunicorn + uvicorn)
- FastAPI for high-performance async APIs with automatic documentation
- LangChain LCEL for composable AI workflows
- Pydantic for type-safe data validation and settings
- Gemini Vision for multimodal document processing
- Structured outputs using PydanticOutputParser
- Production patterns for error handling and validation
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
MIT License - see LICENSE file for details
- Built with LangChain
- Powered by Google Gemini 2.0
- Search by Tavily AI
- Framework by FastAPI
- Open an issue for bugs or feature requests
- Check the full documentation for detailed guides
- Join discussions in the Issues tab
This application is for educational and demonstration purposes only. It is not a substitute for professional medical advice, diagnosis, or treatment. Always seek the advice of qualified health providers with questions about medical conditions.
Building Production-Ready AI Applications with Modern Python Stack