An advanced AI-powered system for analyzing complex medical cases using specialized LLM-based agents. This project uses free, open-source APIs (Ollama and Hugging Face) to provide intelligent medical case analysis, symptom evaluation, and diagnostic suggestions.
This system is for educational and informational purposes only. It is NOT a substitute for professional medical advice, diagnosis, or treatment. Always seek the advice of qualified healthcare providers. If you have a medical emergency, call emergency services immediately.
- 🏥 Comprehensive Case Analysis - Multi-step reasoning for complex medical cases
- 🔍 Symptom Extraction - Automatic categorization and analysis of symptoms
- 💊 Differential Diagnosis - AI-generated diagnostic suggestions with confidence levels
- 💬 Interactive Chat - Conversational interface for medical questions
- 📚 PubMed Integration - Access to peer-reviewed medical literature and research citations
- 🌐 Multi-Language Support - Interface and responses in Tamil and English
- 📄 PDF Export - Download analysis reports as professional PDF documents
- 🎤 Voice Input Support - Dictate medical cases using speech-to-text
- 🖼️ Medical Imaging Analysis - Analyze medical images (X-rays, CT scans) for quality and structure
- 🧠 Enhanced RAG System - Vector-based medical knowledge retrieval with semantic search
- 🌐 Web Interface - Modern, responsive web UI
- 🖥️ CLI Interface - Rich command-line interface for power users
- 📚 Knowledge Base - Medical knowledge integration with disease-symptom mappings
- 🔄 Automatic Fallback - Seamless switching between Ollama and Hugging Face APIs
- Python 3.8 or higher
- Ollama (recommended) or Hugging Face API key
-
Clone or download the project
cd /Users/sharan/Downloads/AI-Agent-for-Medical-Diagnostics -
Create a virtual environment
python3 -m venv venv source venv/bin/activate # On macOS/Linux
-
Install dependencies
pip install -r requirements.txt
-
Set up Ollama (Primary LLM - Recommended)
# Install Ollama brew install ollama # macOS # Start Ollama service ollama serve # In a new terminal, pull a model ollama pull llama3.2 # or ollama pull mistral
-
Configure environment variables
cp .env.example .env # Edit .env and add your Hugging Face API key (optional, for fallback)
python app.pyThen open your browser to: http://localhost:5000
# Interactive mode
python cli.py interactive
# Chat mode
python cli.py chat
# Analyze from file
python cli.py analyze-file case.txt
# Check system status
python cli.py status- Navigate to
http://localhost:5000 - Enter a medical case description in the "Case Analysis" section
- Click "Analyze Case" to get comprehensive analysis
- Use the "Interactive Consultation" chat for follow-up questions
# Start interactive session
python cli.py interactive
# Example case input:
Patient: 45-year-old male
Symptoms: Persistent cough for 3 weeks, fever (101°F), night sweats, fatigue
Duration: 3 weeks
Medical History: No significant past medical historyAI-Agent-for-Medical-Diagnostics/
├── agents/
│ ├── medical_agent.py # Main medical AI agent
│ ├── llm_provider.py # LLM abstraction layer
│ └── prompts.py # Specialized medical prompts
├── config/
│ └── settings.py # Configuration management
├── knowledge/
│ ├── medical_kb.py # Medical knowledge base
│ └── sample_data.json # Disease and symptom data
├── static/
│ ├── css/style.css # Modern UI styling
│ └── js/app.js # Frontend JavaScript
├── templates/
│ └── index.html # Web interface
├── utils/
│ ├── validators.py # Input validation
│ └── logger.py # Logging utilities
├── app.py # Flask web application
├── cli.py # Command-line interface
├── requirements.txt # Python dependencies
└── README.md # This file
Edit .env file:
# Ollama (Primary)
OLLAMA_BASE_URL=http://localhost:11434
OLLAMA_MODEL=llama3.2
# Hugging Face (Fallback)
HUGGINGFACE_API_KEY=your_key_here
HUGGINGFACE_MODEL=microsoft/BioGPT
# Flask
FLASK_PORT=5000
FLASK_DEBUG=True- Go to https://huggingface.co/join
- Create a free account
- Navigate to Settings → Access Tokens
- Create a new token
- Add it to your
.envfile
The core AI agent (agents/medical_agent.py) provides:
- Case analysis with multi-step reasoning
- Symptom extraction and categorization
- Differential diagnosis generation
- Treatment suggestions
- Interactive chat capabilities
Abstraction layer (agents/llm_provider.py) supporting:
- Ollama - Local, unlimited, free inference
- Hugging Face - Cloud-based fallback
- Automatic failover between providers
Medical knowledge system (knowledge/medical_kb.py) with:
- Disease-symptom mappings
- Red flag detection
- Symptom categorization
Run the application with sample cases from examples/sample_cases.md:
# Web interface
python app.py
# CLI
python cli.py interactive# Check if Ollama is running
curl http://localhost:11434/api/tags
# Start Ollama
ollama serve
# Pull a model if not already done
ollama pull llama3.2- Verify your API key in
.env - Check rate limits (free tier has limits)
- Ensure model name is correct
# Change port in .env
FLASK_PORT=5001See examples/sample_cases.md for example medical cases to test with.
This is an educational project. Feel free to:
- Report issues
- Suggest improvements
- Add more medical knowledge to the knowledge base
- Improve prompts for better analysis
Gmail- sharangs08@gmail.com
This project is for educational purposes. Please ensure compliance with medical regulations in your jurisdiction.
Remember: This tool is for educational purposes only. Always consult with qualified healthcare professionals for medical advice.
Made with love 💚 from Sharan G S