Intelligent Veterinary Diagnostic System
Diagnose diseases in Dogs, Cats & Cattle — then plan the optimal treatment path — using hybrid AI
Overview · Demo · Architecture · Getting Started · API · How It Works · Roadmap
PetPulse AI is a full-stack veterinary diagnostic assistant built around three AI modules that work in concert:
| Module | Algorithm | When it runs |
|---|---|---|
| Diagnosis (full data) | Decision Tree — Gini criterion, max_depth=5 |
All 4 symptoms + ≥4 clinical flags provided |
| Diagnosis (partial data) | Naïve Bayes — Laplace smoothing, log-space | Incomplete input; gracefully skips missing features |
| Treatment planning | A* Search — admissible heuristic, heapq |
Always — after diagnosis, finds minimum-cost treatment path |
The system auto-trains from a CSV on startup, exposes a REST API, and ships with a standalone HTML frontend that runs fully offline with a built-in JavaScript fallback engine.
Open
index.htmlin any browser — no server required. The embedded JS engine handles diagnosis locally. Startapp.pyfor full ML accuracy and the frontend upgrades automatically.
┌─────────────────────────────── PetPulse AI · Patient Input ──────────────────────────────┐
│ │
│ Pet Name Bruno Animal Dog · Golden Retriever · 3 yrs · Male │
│ │
│ Symptom 1 Vomiting Symptom 2 Diarrhea │
│ Symptom 3 Lethargy Symptom 4 Dehydration │
│ │
│ Body Temp 40.2°C ⚠ Heart Rate 118 bpm ⚠ │
│ Flags Vomiting ✓ Diarrhea ✓ Appetite Loss ✓ │
│ │
└───────────────────────────────────────────────────────────────────────────────────────────┘
│
[ Decision Tree ]
│
▼
┌─────────────────────────────── Diagnosis Result ──────────────────────────────────────────┐
│ │
│ PRIMARY Canine Parvovirus Confidence ████████████ 87.3% │
│ #2 Canine Gastroenteritis ██░░░░░░░░░░ 8.2% │
│ #3 Canine Distemper █░░░░░░░░░░░ 3.1% │
│ │
│ URGENCY ⚠ EMERGENCY ENGINE Decision Tree (complete input) │
│ │
│ TREATMENT PATH (A* · cost=8) │
│ 1 Triage & Isolation → 2 IV Fluid Therapy → 3 Antiemetics (Maropitant) │
│ → 4 Broad-Spectrum Antibiotics → 5 Nutritional Support │
│ → 6 Viral Load Monitoring → ★ Recovery & Discharge │
│ │
└───────────────────────────────────────────────────────────────────────────────────────────┘
flowchart TD
A["HTML Frontend\nindex.html"] -->|"POST /api/diagnose"| B["Flask REST API\napp.py"]
A -->|"Backend offline"| Z["Embedded JS Engine\nfallback mode"]
B --> C{"Input\nComplete?"}
C -->|"4 symptoms + 4 flags"| D["Decision Tree\nGini · max_depth=5\nsklearn"]
C -->|"Partial / missing fields"| E["Naive Bayes\nLaplace smoothing\nlog-space arithmetic"]
D --> F["Top-5 Disease Ranking\nwith probabilities"]
E --> F
F --> G["A-Star Treatment Search\nf = g + h\nheapq min-heap"]
G --> H{"Disease-specific\ngraph?"}
H -->|"Yes"| I["5 custom graphs\nParvovirus · BRD\nURI · FIP · TB"]
H -->|"No"| J["Generic fallback\nTriage to Discharge"]
I --> K["JSON Response\nprimary disease · top-5\npath · treatment · prevention"]
J --> K
style D fill:#00b580,color:#000000
style E fill:#0066bb,color:#ffffff
style G fill:#ff7700,color:#000000
style K fill:#004477,color:#ffffff
petpulse-ai/
│
├── app.py # Flask backend — ML pipeline + REST API
├── index.html # Standalone frontend (offline-capable)
├── petpulse_presentation.html # 10-slide HTML presentation deck
├── requirements.txt
├── pet_disease_full_merged.csv # ← place dataset here
└── README.md
- Python 3.11 or higher
pet_disease_full_merged.csvplaced in the project root
# Clone
git clone https://github.com/yourusername/petpulse-ai.git
cd petpulse-ai
# Install dependencies
pip install -r requirements.txt
# Run the backend
python app.pyOn startup you'll see:
PetPulse AI — Loading dataset...
Loaded: 215 rows × 16 columns
Decision Tree trained (max_depth=5, gini criterion)
Naive Bayes tables built (68 disease classes, Laplace smoothing)
══════════════════════════════════════════════════════════
PetPulse AI Backend — http://localhost:5000
GET /api/health
POST /api/diagnose
GET /api/symptoms
GET /api/diseases
══════════════════════════════════════════════════════════
Then open index.html in your browser — diagnosis starts immediately.
Tip
You can open index.html without starting the backend. The embedded JavaScript engine handles the full pipeline locally using a built-in knowledge base and A* implementation.
Note
The backend trains from scratch every startup — no pre-built .pkl files needed. Training takes under 2 seconds.
Base URL: http://localhost:5000/api
curl http://localhost:5000/api/health{
"status": "ok",
"diseases": 68,
"records": 215,
"model": "DecisionTree (CO4) + NaiveBayes (CO3) + A* (CO2)"
}The main inference endpoint. Accepts a patient session object and returns ranked diagnoses with the optimal treatment path.
curl -X POST http://localhost:5000/api/diagnose \
-H "Content-Type: application/json" \
-d '{
"Animal Type": "Dog",
"Breed": "Golden Retriever",
"Age": 3,
"Gender": "Male",
"Body Temperature": 40.2,
"Heart Rate": 118,
"Symptom 1": "Vomiting",
"Symptom 2": "Diarrhea",
"Symptom 3": "Lethargy",
"Symptom 4": "Dehydration",
"Vomiting": "Yes",
"Diarrhea": "Yes",
"Appetite Loss": "Yes",
"Coughing": "No",
"Labored Breathing": "No",
"Lameness": "No",
"Skin Lesions": "No"
}'View full response →
{
"primary_disease": "Canine Parvovirus",
"engine_used": "Decision Tree — max_depth=5, Gini criterion",
"input_complete": true,
"top_diseases": [
{ "disease": "Canine Parvovirus", "probability": 0.873 },
{ "disease": "Canine Gastroenteritis", "probability": 0.082 },
{ "disease": "Canine Distemper", "probability": 0.031 },
{ "disease": "Heartworm Disease", "probability": 0.009 },
{ "disease": "Lyme Disease", "probability": 0.005 }
],
"treatment_path": {
"path": [
{ "step": 1, "action": "Triage & Isolation", "is_goal": false },
{ "step": 2, "action": "IV Fluid Therapy", "is_goal": false },
{ "step": 3, "action": "Antiemetics (Maropitant)", "is_goal": false },
{ "step": 4, "action": "Broad-Spectrum Antibiotics", "is_goal": false },
{ "step": 5, "action": "Nutritional Support", "is_goal": false },
{ "step": 6, "action": "Viral Load Monitoring", "is_goal": false },
{ "step": 7, "action": "Recovery & Discharge", "is_goal": true }
],
"total_cost": 8
},
"treatment_text": "Hospitalization with IV fluid therapy (LRS). Maropitant 1 mg/kg SQ q24h. Broad-spectrum antibiotics (Ampicillin + Gentamicin). Nutritional support via NJ tube if vomiting persists.",
"prevention_text": "MLV CPV-2 vaccine at 6-8, 10-12, and 14-16 weeks. Annual adult boosters. Disinfect environment with 1:30 bleach solution."
}Returns all unique symptom values in the dataset — useful for autocomplete.
curl http://localhost:5000/api/symptomsReturns all 68 disease class names.
curl http://localhost:5000/api/diseasesEvery input passes through five transformations before reaching any model:
Raw Input
│
├─ 1. Missing value imputation
│ categorical → mode fill
│ numerical → median fill
│
├─ 2. Temperature parsing
│ "39.2°C" ──► 39.2 (regex strip)
│
├─ 3. Binary flag encoding
│ "Yes" ──► 1 "No" ──► 0
│
├─ 4. Label encoding
│ Animal Type, Breed, Symptoms ──► integer indices (LabelEncoder)
│
└─ 5. StandardScaler normalization
Age, Heart Rate, Body Temp ──► zero-mean, unit-variance
Trained with sklearn.tree.DecisionTreeClassifier:
DecisionTreeClassifier(
criterion = "gini",
max_depth = 5,
min_samples_leaf = 1,
random_state = 65
)Split: 75% train / 25% test · Accuracy: ~92%
Returns top-5 diseases from predict_proba() — the probability mass at the leaf node reached by the input feature vector.
Custom implementation. Uses log-space arithmetic to prevent floating-point underflow when multiplying many small probabilities:
log P(Disease | X) = log P(Disease) + Σ log P(xᵢ | Disease)
Laplace smoothing ensures zero-frequency features don't kill a valid hypothesis:
P(x | Disease) = (count(x, Disease) + 1) / (|Disease| + |Vocabulary|)
Missing features are simply skipped — the posterior is computed from whatever features are available.
After diagnosis, A* navigates a weighted directed graph of treatment steps:
f(n) = g(n) + h(n)
g(n) ── cost from start to n (treatment steps taken)
h(n) ── admissible heuristic (remaining steps, never overestimates)
f(n) ── priority score in the min-heap
Disease-specific treatment graphs:
| Disease | Start | Goal | Nodes |
|---|---|---|---|
| Canine Parvovirus | Triage & Isolation | Recovery & Discharge | 7 |
| Bovine Respiratory Disease | Isolation & Rest | Recovery & Return to Herd | 7 |
| Upper Respiratory Infection (Cat) | Clinical Assessment | Follow-Up & Discharge | 6 |
| Feline Infectious Peritonitis | Isolation & Supportive Care | Discharge & Long-term Care | 7 |
| Bovine Tuberculosis | Quarantine Animal | Re-Testing & Clearance | 7 |
| (all other diseases) | Emergency Triage | Recovery & Discharge | 6 |
Implemented with Python's heapq and a visited closed set — O(E log V) per query, effectively instant.
🐕 Dogs — 14+ diseases
| Disease | Urgency |
|---|---|
| Canine Parvovirus | 🔴 Emergency |
| Heartworm Disease | 🟠 High |
| Canine Distemper | 🟠 High |
| Lyme Disease | 🟡 Moderate |
| Kennel Cough | 🟡 Moderate |
| Canine Gastroenteritis | 🟡 Moderate |
| Canine Hip Dysplasia | 🟢 Low |
| Ringworm | 🟢 Low |
🐈 Cats — 10+ diseases
| Disease | Urgency |
|---|---|
| Feline Infectious Peritonitis | 🟠 High |
| Feline Leukemia (FeLV) | 🟠 High |
| Feline Pancreatitis | 🟠 High |
| Upper Respiratory Infection | 🟡 Moderate |
| Feline Hyperthyroidism | 🟡 Moderate |
| Ringworm | 🟢 Low |
🐄 Cattle — 10+ diseases
| Disease | Urgency |
|---|---|
| Bovine Tuberculosis | 🔴 Emergency (Notifiable) |
| Foot and Mouth Disease | 🔴 Emergency (Notifiable) |
| Bovine Bloat | 🔴 Emergency |
| Bovine Respiratory Disease | 🟠 High |
| Mastitis | 🟠 High |
flask==3.0.3
flask-cors==4.0.1
pandas==2.2.2
numpy==1.26.4
scikit-learn==1.5.1
- Expand dataset to 1,000+ verified veterinary records
- Random Forest / XGBoost ensemble for higher accuracy
- CNN-based image symptom detection (skin lesions, eye discharge)
- React Native mobile app for field use by rural vets
- IoT wearable sensor integration for continuous vitals monitoring
- PostgreSQL persistence for patient history tracking
- Multilingual interface (Bengali, Hindi)
- Docker containerization for one-command deployment
Warning
PetPulse AI is an academic research project. All outputs are for educational purposes only and must not replace professional veterinary diagnosis or treatment. Always consult a licensed veterinarian for any animal health decisions.
Distributed under the MIT License. See LICENSE for details.
Built with 🐾 for CSE 3811 — Artificial Intelligence
United International University