A Django-based web application that analyzes medical reports and prescriptions to detect drug interactions and provide AI-powered diagnosis suggestions.
- 📄 File Upload Support: Upload medical reports in TXT, PDF, or image formats (PNG, JPG, JPEG)
- 🔍 OCR Processing: Extract text from images using Tesseract OCR
- 💊 Drug Interaction Detection: Identify potential drug interactions from a comprehensive database
- 🩺 AI Diagnosis: Get AI-powered diagnosis suggestions using LangChain and Groq
- 📊 Multi-specialist Analysis: Cardiologist, Psychologist, and Pulmonologist agents provide specialized insights
- 🎨 Modern UI: Clean, responsive interface built with Tailwind CSS
- Python 3.8+
- Tesseract OCR (for Windows: install from here)
- Groq API key (get one from Groq Console)
-
Clone the repository
cd Drug_detect_app/drugchecker -
Create a virtual environment
python -m venv venv venv\Scripts\activate # On Windows
-
Install dependencies
pip install -r requirements.txt
-
Set up environment variables
- Copy
.env.exampleto.env - Add your Groq API key:
GROQ_API_KEY=your-groq-api-key-here
- Copy
-
Run migrations
python manage.py migrate
-
Start the development server
python manage.py runserver
-
Access the application
- Open your browser and navigate to
http://127.0.0.1:8000/
- Open your browser and navigate to
drugchecker/
├── interaction/ # Main Django app
│ ├── templates/ # HTML templates
│ ├── utils/ # Utility modules
│ │ ├── agent.py # LangChain agents
│ │ ├── file_classifier.py
│ │ └── text_extractor.py
│ ├── views.py # View functions
│ ├── urls.py # URL routing
│ ├── tests.py # Unit tests
│ └── drug_analyzer.py # Drug interaction analyzer
├── drugchecker/ # Project settings
├── media/ # Uploaded files
├── db_drug_interactions.csv # Drug interaction database
└── requirements.txt # Python dependencies
-
Upload a Medical File
- Click "Upload Medical File" on the home page
- Select a TXT, PDF, or image file containing medical information
-
Choose Analysis Type
- If a structured report is detected, choose:
- Extract Diagnosis only
- Check Drug Interactions only
- Do Both
- If a structured report is detected, choose:
-
View Results
- See extracted text from the document
- View detected drugs and potential interactions
- Read AI-generated diagnosis suggestions
Run the test suite:
python manage.py test interactionRun specific test files:
python manage.py test interaction.tests
python manage.py test interaction.tests_drug_analyzer- Prefer digital PDFs: The app first extracts text with PyMuPDF. Scanned PDFs/images require OCR and take longer.
- Image size: Large images slow OCR. Resize to ~1600–1800px width before upload for faster results.
- Diagnosis mode: Multi-agent diagnosis is heavier than interaction-only. Use only when needed.
- Windows Tesseract path: On Windows,
pytesseract.pytesseract.tesseract_cmdis set toC:\\Program Files\\Tesseract-OCR\\tesseract.exe. Ensure it exists. - CSV lookups: Drug interaction CSV is loaded once at startup from
db_drug_interactions.csv.
- The UI uses Tailwind CSS with a custom design system defined in
interaction/templates/interaction/base.html. - Theme is controlled with CSS variables under
:rootand.dark. - Theme toggle button persists user choice via
localStorageand applies the.darkclass to<html>.
/or/upload/→ upload and smart analysis (upload_file)/analyze/→ choose action after structured report (choose_action)/diagnosis/→ run diagnosis on uploaded structured text (diagnosis_view)/check-interactions/and/drug-interactions/→ manual drug interaction analysis (analyze_drugs)
- Interaction DB CSV columns should include
Drug 1,Drug 2, andInteraction. - If your CSV uses
Interaction Description, it is auto-renamed toInteractionat load time. - Media uploads are stored under
media/(served in DEBUG mode via Django static serving).
- Tesseract not found (Windows): Install Tesseract and verify the path:
C:\\Program Files\\Tesseract-OCR\\tesseract.exe. - Slow analysis: Use smaller images, prefer text PDFs, or run interaction-only first.
- No interactions found: Ensure drug names match the CSV exactly (case-sensitive in current implementation). Try entering generic names.
- 500 errors after upload: Check server logs; confirm PDF is not password-protected and images are not corrupted.
- Never commit your
.envfile or API keys to version control - The current implementation includes a fallback API key for development only
- In production, always use environment variables for sensitive data
- This application is for educational purposes only and should not replace professional medical advice
- Backend: Django 5.2.4
- AI/ML: LangChain, Groq (Llama 3)
- OCR: Tesseract, PyTesseract
- PDF Processing: PyMuPDF
- Data Processing: Pandas, NumPy
- Frontend: Tailwind CSS
- Image Processing: Pillow
- Fork the repository
- Create a feature branch
- Make your changes
- Run tests to ensure everything works
- Submit a pull request
This project is for educational purposes only.
This application is designed for educational and informational purposes only. It should not be used as a substitute for professional medical advice, diagnosis, or treatment. Always consult with qualified healthcare providers for medical decisions.