Parse unstructured medication text into structured entities using a Django API and a React UI.
- Django backend:
med_parser/+med_app/ - React frontend:
med_ui/ - SQLite DB:
db.sqlite3
-
Create and activate a virtual environment:
python3 -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install dependencies:
pip install -r requirement.txt
-
Download the spaCy medical model (required for medspaCy):
python -m spacy download en_core_web_sm
-
(Optional) Set up MedGemma with Google AI:
To use the MedGemma model, you need a Google API key:
export GOOGLE_API_KEY="your-api-key-here"
Get your API key from: https://makersuite.google.com/app/apikey
-
Run migrations:
python manage.py migrate
-
Start the dev server:
python manage.py runserver
The API is served at http://127.0.0.1:8000/api/.
GET /api/— health check.POST /api/parse_medical_text— extracts entities using medspaCy (local).POST /api/parse_medical_text_gemma— extracts entities using MedGemma (Google AI).
Request body (both endpoints):
{
"medical_text": "Metformin 500mg twice daily"
}
Response example:
{
"entities": [
["Metformin", "DRUG"],
["500mg", "DOSAGE"],
["twice daily", "FREQUENCY"]
],
"model": "medspacy"
}
From the med_ui folder:
-
Install dependencies:
npm install
-
Configure the API URL (optional):
- Copy
.env.exampleto.envif needed - Default API URL is
http://127.0.0.1:8000 - To change it, edit the
.envfile:REACT_APP_API_URL=http://127.0.0.1:8000
- Copy
-
Run the dev server:
npm start
The UI runs at http://localhost:3000 and connects to the Django API.
- Multiple AI Models: Choose between two parsing engines:
- medspaCy: Fast, local medical NLP processing (no API key needed)
- MedGemma: Google's advanced medical AI model (requires API key)
- Medical Text Input: Enter unstructured medical text in a user-friendly interface
- Entity Extraction: Automatically extracts and categorizes medical entities:
- Drugs/Medications
- Dosages
- Frequencies
- Durations
- Conditions
- Procedures
- Visual Results: Color-coded entity cards for easy identification
- API Health Check: Test connection to the backend API
- Responsive Design: Works on desktop and mobile devices
- CORS is enabled for local development in med_parser/settings.py.
- The Django backend uses medspaCy for medical NLP processing.
- MedGemma uses Google's Gemini API for advanced medical entity extraction.
- The frontend is built with React and uses Axios for API calls.
- All dependencies are listed in requirement.txt (backend) and med_ui/package.json (frontend).
| Feature | medspaCy | MedGemma |
|---|---|---|
| Speed | Very Fast | Moderate (API call) |
| Setup | Local install only | Requires API key |
| Accuracy | Good | Excellent |
| Cost | Free | Free tier available |
| Privacy | Fully local | Cloud-based |
-
Start Backend:
python manage.py runserver
-
Start Frontend (in a new terminal):
cd med_ui npm start -
Access the app: Open
http://localhost:3000in your browser -
Select a model: Choose medspaCy or MedGemma in the UI
-
Test it: Try parsing "Metformin 500mg twice daily for diabetes"