File size: 3,914 Bytes
fff3c77
7149c09
 
 
 
fff3c77
 
7149c09
fff3c77
 
7149c09
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
---
title: Milk Spoilage Classifier - Multi-Variant API
emoji: πŸ₯›
colorFrom: indigo
colorTo: purple
sdk: docker
pinned: false
license: mit
---

# Milk Spoilage Classification API - Multi-Variant

AI-powered milk spoilage classification with **10 specialized model variants** optimized for different data availability scenarios.

## πŸš€ Features

- **10 Model Variants** with test accuracies from 62.8% to 95.8%
- **Automatic Feature Validation** - API validates required features for each variant
- **RESTful API** with comprehensive OpenAPI documentation
- **Custom GPT Ready** - Designed for seamless ChatGPT integration

## πŸ“Š Available Model Variants

| Rank | Variant | Test Accuracy | Features Required |
|------|---------|---------------|-------------------|
| πŸ₯‡ | baseline | **95.8%** | All 6 features |
| πŸ₯ˆ | scenario_1_days14_21 | **94.2%** | Days 14 & 21 (SPC+TGN) |
| πŸ₯‰ | scenario_3_day21 | **93.7%** | Day 21 only (SPC+TGN) |
| 4 | scenario_4_day14 | 87.4% | Day 14 only (SPC+TGN) |
| 5 | scenario_2_days7_14 | 87.3% | Days 7 & 14 (SPC+TGN) |
| 6 | scenario_6_spc_all | 78.3% | SPC only (All Days) |
| 7 | scenario_8_spc_7_14 | 73.3% | SPC only (Days 7 & 14) |
| 8 | scenario_9_tgn_7_14 | 73.1% | TGN only (Days 7 & 14) |
| 9 | scenario_7_tgn_all | 69.9% | TGN only (All Days) |
| 10 | scenario_5_day7 | 62.8% | Day 7 only (SPC+TGN) |

## πŸ”§ API Endpoints

### `GET /variants`
List all available model variants with metadata

### `POST /predict`
Make a prediction using the specified model variant

**Example Request:**
```json
{
  "spc_d7": 2.1,
  "spc_d14": 4.7,
  "spc_d21": 6.4,
  "tgn_d7": 1.0,
  "tgn_d14": 3.7,
  "tgn_d21": 5.3,
  "model_variant": "baseline"
}
```

**Example Response:**
```json
{
  "prediction": "PPC",
  "probabilities": {
    "PPC": 0.97,
    "no spoilage": 0.02,
    "spore spoilage": 0.01
  },
  "confidence": 0.97,
  "variant_used": {
    "variant_id": "baseline",
    "name": "Baseline (All Features)",
    "test_accuracy": 0.9576,
    "features": ["SPC_D7", "SPC_D14", "SPC_D21", "TGN_D7", "TGN_D14", "TGN_D21"]
  }
}
```

## πŸ“– Spoilage Classes

| Class | Description |
|-------|-------------|
| **PPC** | Post-Pasteurization Contamination - Bacteria introduced after pasteurization |
| **no spoilage** | No significant spoilage detected |
| **spore spoilage** | Heat-resistant spore-forming bacteria survived pasteurization |

## πŸ”— Interactive Documentation

Visit `/docs` for interactive Swagger UI documentation where you can test the API directly.

## πŸ’» Usage Example

```bash
curl -X POST https://chenhaoq87-milkspoilageclassifier-api-variants.hf.space/predict \
  -H "Content-Type: application/json" \
  -d '{
    "spc_d21": 6.4,
    "tgn_d21": 5.3,
    "model_variant": "scenario_3_day21"
  }'
```

## πŸ€– Custom GPT Integration

This API is designed for Custom GPT integration. The GPT will automatically select the best variant based on available data.

See the [Custom GPT Setup Guide](https://huggingface.co/chenhaoq87/MilkSpoilageClassifier/blob/main/docs/CUSTOM_GPT_SETUP_MULTIVARIANT.md) for complete integration instructions.

## πŸ“ Input Format

All microbial count values should be in **log CFU/mL (base 10)**:
- **SPC** (Standard Plate Count): Total bacterial count
- **TGN** (Total Gram-Negative): Gram-negative bacteria count
- Measured at **Day 7, 14, and 21**

## πŸ” Variant Selection Guide

- **Have all measurements?** β†’ Use `baseline` (best accuracy)
- **Only Day 21 data?** β†’ Use `scenario_3_day21` (nearly as good!)
- **Only Day 14 data?** β†’ Use `scenario_4_day14`
- **Only SPC measurements?** β†’ Use `scenario_6_spc_all`
- **Only TGN measurements?** β†’ Use `scenario_7_tgn_all`

## πŸ“š Research

Based on predictive modeling for milk spoilage classification using microbial growth patterns.

---

**Model Repository:** [MilkSpoilageClassifier](https://huggingface.co/chenhaoq87/MilkSpoilageClassifier)