File size: 2,109 Bytes
d03f587
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
---
title: Medical Coding API
emoji: πŸ₯
colorFrom: blue
colorTo: green
sdk: docker
pinned: false
license: mit
app_port: 7860
tags:
  - medical
  - healthcare
  - icd-10
  - cpt
  - phi-3
  - fastapi
---

# πŸ₯ Medical Coding API

AI-powered API for extracting **ICD-10** and **CPT codes** from clinical provider notes using Microsoft Phi-3.

## πŸš€ Features

- βœ… Extract ICD-10 diagnosis codes
- βœ… Extract CPT procedure codes
- βœ… Supports notes up to 10,000 characters (~2,500 words)
- βœ… JSON output format
- βœ… GPU-accelerated inference (when available)
- βœ… Automatic text truncation
- βœ… Production-ready with error handling

## πŸ“‘ API Endpoints

### POST `/predict`

Extract medical codes from clinical note.

**Request:**

```json
{
  "note": "Your clinical note here..."
}
```

**Response:**

```json
{
  "result": {
    "icd10_codes": ["I10", "E11.9"],
    "cpt_codes": ["99213"]
  },
  "raw_output": "...",
  "note_length": 250,
  "truncated": false,
  "processing_time": 3.45
}
```

### GET `/health`

Check API health status.

### GET `/docs`

Interactive API documentation (Swagger UI).

## πŸ§ͺ Usage Examples

### cURL

```bash
curl -X POST "https://YOUR-SPACE.hf.space/predict" \
  -H "Content-Type: application/json" \
  -d '{"note": "Patient with HTN, BP 160/95. Prescribed lisinopril."}'
```

### Python

```python
import requests

response = requests.post(
    "https://YOUR-SPACE.hf.space/predict",
    json={"note": "Patient with diabetes, HbA1c 8.2. Started metformin."}
)
print(response.json())
```

### JavaScript

```javascript
fetch("https://YOUR-SPACE.hf.space/predict", {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({ note: "Clinical note here..." }),
})
  .then((res) => res.json())
  .then((data) => console.log(data));
```

## βš™οΈ Technical Details

- **Model:** RayyanAhmed9477/med-coding (Phi-3 based)
- **Framework:** FastAPI + Transformers
- **Deployment:** HuggingFace Spaces (Docker)
- **First Request:** 30-60 seconds (model loading)
- **Subsequent Requests:** 2-10 seconds

## πŸ“ License

MIT License