A sophisticated AI-powered healthcare application that analyzes patient medical data and documents to detect potential drug interactions, side effects, and provides personalized medical insights.
MLHKS (Medicine Error Detection Companion) is an intelligent healthcare assistant that combines patient medical history, current medications, and uploaded medical documents to provide comprehensive analysis of potential drug interactions and side effects. The system uses advanced AI agents to extract drug information, analyze chemical interactions, and generate patient-friendly medical insights.
- Multi-format Document Processing: Supports PDF and DOCX medical document analysis
- Drug Interaction Analysis: Advanced chemical structure analysis using SMILES representations
- AI-Powered Insights: Multi-agent AI system for comprehensive medical analysis
- Patient-Friendly Output: Clear, non-frightening explanations with doctor consultation questions
- Web Interface: Both Streamlit and FastAPI-based interfaces available
- Comprehensive Medical Database: Integration with drug interaction databases
- Data Models: Pydantic-based patient data validation and structure
- Document Processing Engine: PDF/DOCX text extraction and processing
- AI Agent System: Multi-stage analysis using SmoLAgents framework
- Database Layer: SQLite database with drug interaction data
- API Service: FastAPI-based REST endpoints
- Frontend Interfaces: Streamlit web application
- Entity Extraction Agent: Extracts drug names from patient data and documents
- Drug Analysis Agent: Converts drug names to chemical structures (SMILES)
- Interaction Analysis: Queries database for drug pair interactions
- Summary Agent: Synthesizes findings into actionable insights
- Python 3.7 or higher
- pip package manager
- Git
-
Clone the repository:
git clone https://github.com/Raman369AI/mlhks.git cd mlhks -
Create virtual environment:
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install dependencies:
pip install -r requirements.txt
-
Environment Configuration:
cp .env.example .env
Edit
.envand add your API keys:GEMINI_API_KEY=your_gemini_api_key_here -
Initialize Database (if not already present): The application uses a SQLite database (
raman.db) for drug interaction data.
-
Start the API server:
uvicorn patient_help_api:app --reload --host 0.0.0.0 --port 8000
-
Access the API:
- API Documentation: http://localhost:8000/docs
- Main endpoint:
POST /process-patient-data/
-
Run the Streamlit app:
streamlit run app1.py
-
Access the web interface:
- Open http://localhost:8501 in your browser
import requests
# Patient data
payload = {
"age": 45,
"sex": "Male",
"height": 175,
"weight": 85,
"allergies": "Shellfish, Dust",
"preexisting_conditions": "Diabetes, Hypertension",
"medications": "Aspirin, Atorvastatin",
"family_history": "Heart Disease",
"question": "I feel dizzy after taking my medication. What could be wrong?"
}
# Upload medical documents (optional)
files = [
('files', ('medical_report.pdf', open('medical_report.pdf', 'rb'), 'application/pdf'))
]
# Make request
response = requests.post(
"http://localhost:8000/process-patient-data/",
data=payload,
files=files
)
print(response.json())Analyzes patient data and uploaded medical documents to provide medical insights.
Request Parameters:
age(int): Patient agesex(str): Patient sex (Male/Female/Other)height(float): Height in cmweight(float): Weight in kgallergies(str): Known allergiespreexisting_conditions(str): Medical conditionsmedications(str): Current medicationsfamily_history(str): Family medical historyquestion(str): Patient's medical questionfiles(list): Medical documents (PDF/DOCX)
Response:
{
"insights": "Detailed medical analysis and recommendations..."
}| Variable | Description | Required |
|---|---|---|
GEMINI_API_KEY |
Google Gemini API key for AI processing | Yes |
The application uses SQLite for drug interaction data. The database schema includes:
- Drug pairs with SMILES representations
- Side effect classifications
- Interaction severity levels
- Drug Database: Based on DrugBank and TWOSIDES datasets
- Chemical Structures: PubChemPy integration for SMILES conversion
- Side Effects: Comprehensive database with 1300+ side effect categories
- API Keys: Never commit API keys to version control
- Patient Data: Ensure compliance with healthcare privacy regulations
- File Uploads: Temporary files are automatically cleaned up
- Input Validation: Comprehensive input sanitization and validation
Run the test payload example:
jupyter notebook test_payload.ipynbOr test with curl:
curl -X POST "http://localhost:8000/process-patient-data/" \
-F "age=45" \
-F "sex=Male" \
-F "height=175" \
-F "weight=85" \
-F "allergies=Shellfish, Dust" \
-F "preexisting_conditions=Diabetes, Hypertension" \
-F "medications=Aspirin, Atorvastatin" \
-F "family_history=Heart Disease" \
-F "question=I feel dizzy after taking my medication. What could be wrong?"Build and run with Docker:
docker build -t mlhks .
docker run -p 8000:8000 -e GEMINI_API_KEY=your_api_key mlhksmlhks/
โโโ app1.py # Streamlit web interface
โโโ patient_help_api.py # Main FastAPI application
โโโ patient_help.py # Alternative API implementation
โโโ Dockerfile # Docker configuration
โโโ requirements.txt # Python dependencies
โโโ .env.example # Environment variables template
โโโ .gitignore # Git ignore patterns
โโโ README.md # This file
โโโ raman.db # SQLite database
โโโ documents_uploaded/ # Sample medical documents
โโโ test_payload.ipynb # Testing notebook
โโโ new.ipynb # Development notebook
โโโ temp/ # Temporary file storage
- 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
-
Database Connection Error:
- Ensure
raman.dbfile exists and is accessible - Check file permissions
- Ensure
-
API Key Issues:
- Verify your Gemini API key is valid
- Check environment variable configuration
-
File Upload Errors:
- Ensure uploaded files are PDF or DOCX format
- Check file size limits
-
Memory Issues:
- Large document processing may require additional memory
- Consider processing documents in batches
Enable detailed logging by setting:
export LOG_LEVEL=DEBUG- Medical Advice: This tool is for informational purposes only and does not replace professional medical advice
- Accuracy: Always consult healthcare providers for medical concerns
- Liability: Users are responsible for verifying all medical information
This project is licensed under the MIT License - see the LICENSE file for details.
For support and questions:
- Create an issue on GitHub
- Check the documentation
- Review common troubleshooting steps
- DrugBank and TWOSIDES datasets for drug interaction data
- SmoLAgents framework for AI agent orchestration
- Google Gemini for AI-powered analysis
- FastAPI and Streamlit communities for excellent frameworks
Note: This is a research and development project. Always consult qualified healthcare professionals for medical decisions.